2 *******************************************************************************
3 * Copyright (C) 2011-2012, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 *******************************************************************************
12 * \brief C++ API: TimeZoneFormat
15 #include "unicode/utypes.h"
17 #if !UCONFIG_NO_FORMATTING
18 #ifndef U_HIDE_INTERNAL_API
20 #include "unicode/format.h"
21 #include "unicode/timezone.h"
22 #include "unicode/tznames.h"
26 * Constants for time zone display format style used by format/parse APIs
28 * @internal ICU 49 technology preview
30 typedef enum UTimeZoneFormatStyle
{
32 * Generic location format, such as "United States Time (New York)", "Italy Time"
33 * @internal ICU 49 technology preview
35 UTZFMT_STYLE_GENERIC_LOCATION
,
37 * Generic long non-location format, such as "Eastern Time".
38 * @internal ICU 49 technology preview
40 UTZFMT_STYLE_GENERIC_LONG
,
42 * Generic short non-location format, such as "ET".
43 * @internal ICU 49 technology preview
45 UTZFMT_STYLE_GENERIC_SHORT
,
47 * Specific long format, such as "Eastern Standard Time".
48 * @internal ICU 49 technology preview
50 UTZFMT_STYLE_SPECIFIC_LONG
,
52 * Specific short format, such as "EST", "PDT".
53 * @internal ICU 49 technology preview
55 UTZFMT_STYLE_SPECIFIC_SHORT
,
57 * RFC822 format, such as "-0500"
58 * @internal ICU 49 technology preview
62 * Localized GMT offset format, such as "GMT-05:00", "UTC+0100"
63 * @internal ICU 49 technology preview
65 UTZFMT_STYLE_LOCALIZED_GMT
,
67 * ISO 8601 format (extended), such as "-05:00", "Z"(UTC)
68 * @internal ICU 49 technology preview
71 } UTimeZoneFormatStyle
;
74 * Constants for GMT offset pattern types.
75 * @internal ICU 49 technology preview
77 typedef enum UTimeZoneFormatGMTOffsetPatternType
{
79 * Positive offset with hour and minute fields
80 * @internal ICU 49 technology preview
82 UTZFMT_PAT_POSITIVE_HM
,
84 * Positive offset with hour, minute and second fields
85 * @internal ICU 49 technology preview
87 UTZFMT_PAT_POSITIVE_HMS
,
89 * Negative offset with hour and minute fields
90 * @internal ICU 49 technology preview
92 UTZFMT_PAT_NEGATIVE_HM
,
94 * Negative offset with hour, minute and second fields
95 * @internal ICU 49 technology preview
97 UTZFMT_PAT_NEGATIVE_HMS
98 } UTimeZoneFormatGMTOffsetPatternType
;
101 * Constants for time types used by TimeZoneFormat APIs for
102 * receiving time type (standard time, daylight time or unknown).
103 * @internal ICU 49 technology preview
105 typedef enum UTimeZoneFormatTimeType
{
108 * @internal ICU 49 technology preview
110 UTZFMT_TIME_TYPE_UNKNOWN
,
113 * @internal ICU 49 technology preview
115 UTZFMT_TIME_TYPE_STANDARD
,
117 * Daylight saving time
118 * @internal ICU 49 technology preview
120 UTZFMT_TIME_TYPE_DAYLIGHT
121 } UTimeZoneFormatTimeType
;
124 * Constants for parse option flags, used for specifying optional parse behavior.
125 * @internal ICU 49 technology preview
127 typedef enum UTimeZoneFormatParseOption
{
130 * @internal ICU 49 technology preview
132 UTZFMT_PARSE_OPTION_NONE
= 0x00,
134 * When a time zone display name is not found within a set of display names
135 * used for the specified style, look for the name from display names used
137 * @internal ICU 49 technology preview
139 UTZFMT_PARSE_OPTION_ALL_STYLES
= 0x01
140 } UTimeZoneFormatParseOption
;
148 class TimeZoneGenericNames
;
152 * <code>TimeZoneFormat</code> supports time zone display name formatting and parsing.
153 * An instance of TimeZoneFormat works as a subformatter of {@link SimpleDateFormat},
154 * but you can also directly get a new instance of <code>TimeZoneFormat</code> and
155 * formatting/parsing time zone display names.
157 * ICU implements the time zone display names defined by <a href="http://www.unicode.org/reports/tr35/">UTS#35
158 * Unicode Locale Data Markup Language (LDML)</a>. {@link TimeZoneNames} represents the
159 * time zone display name data model and this class implements the algorithm for actual
160 * formatting and parsing.
162 * @see SimpleDateFormat
164 * @internal ICU 49 technology preview
166 class U_I18N_API TimeZoneFormat
: public Format
{
170 * @internal ICU 49 technology preview
172 TimeZoneFormat(const TimeZoneFormat
& other
);
176 * @internal ICU 49 technology preview
178 virtual ~TimeZoneFormat();
181 * Assignment operator.
182 * @internal ICU 49 technology preview
184 TimeZoneFormat
& operator=(const TimeZoneFormat
& other
);
187 * Return true if the given Format objects are semantically equal.
188 * Objects of different subclasses are considered unequal.
189 * @param other The object to be compared with.
190 * @return Return TRUE if the given Format objects are semantically equal.
191 * Objects of different subclasses are considered unequal.
192 * @internal ICU 49 technology preview
194 virtual UBool
operator==(const Format
& other
) const;
197 * Clone this object polymorphically. The caller is responsible
198 * for deleting the result when done.
199 * @return A copy of the object
200 * @internal ICU 49 technology preview
202 virtual Format
* clone() const;
205 * Creates an instance of <code>TimeZoneFormat</code> for the given locale.
206 * @param locale The locale.
207 * @param status Recevies the status.
208 * @return An instance of <code>TimeZoneFormat</code> for the given locale,
209 * owned by the caller.
210 * @internal ICU 49 technology preview
212 static TimeZoneFormat
* U_EXPORT2
createInstance(const Locale
& locale
, UErrorCode
& status
);
215 * Returns the time zone display name data used by this instance.
216 * @return The time zone display name data.
217 * @internal ICU 49 technology preview
219 const TimeZoneNames
* getTimeZoneNames() const;
222 * Sets the time zone display name data to this format instnace.
223 * The caller should not delete the TimeZoenNames object after it is adopted
225 * @param tznames TimeZoneNames object to be adopted.
226 * @internal ICU 49 technology preview
228 void adoptTimeZoneNames(TimeZoneNames
*tznames
);
231 * Sets the time zone display name data to this format instnace.
232 * @param tznames TimeZoneNames object to be set.
233 * @internal ICU 49 technology preview
235 void setTimeZoneNames(const TimeZoneNames
&tznames
);
238 * Returns the localized GMT format pattern.
239 * @param pattern Receives the localized GMT format pattern.
240 * @return A reference to the result pattern.
241 * @see #setGMTPattern
242 * @internal ICU 49 technology preview
244 UnicodeString
& getGMTPattern(UnicodeString
& pattern
) const;
247 * Sets the localized GMT format pattern. The pattern must contain
248 * a single argument {0}, for example "GMT {0}".
249 * @param pattern The localized GMT format pattern to be used by this object.
250 * @param status Recieves the status.
251 * @see #getGMTPattern
252 * @internal ICU 49 technology preview
254 void setGMTPattern(const UnicodeString
& pattern
, UErrorCode
& status
);
257 * Returns the offset pattern used for localized GMT format.
258 * @param type The offset pattern type enum.
259 * @param pattern Receives the offset pattern.
260 * @return A reference to the result pattern.
261 * @see #setGMTOffsetPattern
262 * @internal ICU 49 technology preview
264 UnicodeString
& getGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type
, UnicodeString
& pattern
) const;
267 * Sets the offset pattern for the given offset type.
268 * @param type The offset pattern type enum.
269 * @param pattern The offset pattern used for localized GMT format for the type.
270 * @param status Receives the status.
271 * @see #getGMTOffsetPattern
272 * @internal ICU 49 technology preview
274 void setGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type
, const UnicodeString
& pattern
, UErrorCode
& status
);
277 * Returns the decimal digit characters used for localized GMT format in a single string
278 * containing from 0 to 9 in the ascending order.
279 * @param digits Receives the decimal digits used for localized GMT format.
280 * @see #setGMTOffsetDigits
282 UnicodeString
& getGMTOffsetDigits(UnicodeString
& digits
) const;
285 * Sets the decimal digit characters used for localized GMT format.
286 * @param digits The decimal digits used for localized GMT format.
287 * @param status Receives the status.
288 * @see #getGMTOffsetDigits
290 void setGMTOffsetDigits(const UnicodeString
& digits
, UErrorCode
& status
);
293 * Returns the localized GMT format string for GMT(UTC) itself (GMT offset is 0).
294 * @param gmtZeroFormat Receives the localized GMT string string for GMT(UTC) itself.
295 * @return A reference to the result GMT string.
296 * @see #setGMTZeroFormat
298 UnicodeString
& getGMTZeroFormat(UnicodeString
& gmtZeroFormat
) const;
301 * Sets the localized GMT format string for GMT(UTC) itself (GMT offset is 0).
302 * @param gmtZeroFormat The localized GMT format string for GMT(UTC).
303 * @param status Receives the status.
304 * @see #getGMTZeroFormat
306 void setGMTZeroFormat(const UnicodeString
& gmtZeroFormat
, UErrorCode
& status
);
309 * Returns the bitwise flags of UTimeZoneFormatParseOption representing the default parse
310 * options used by this object.
311 * @return the default parse options.
313 * @internal ICU 49 technology preview
315 int32_t getDefaultParseOptions(void) const;
318 * Sets the default parse options.
319 * <p><b>Note</b>: By default, an instance of <code>TimeZoneFormat</code>
320 * created by {@link #createInstance} has no parse options set (UTZFMT_PARSE_OPTION_NONE).
321 * To specify multipe options, use bitwise flags of UTimeZoneFormatParseOption.
322 * @see #UTimeZoneFormatParseOption
323 * @internal ICU 49 technology preview
325 void setDefaultParseOptions(int32_t flags
);
328 * Returns the RFC822 style time zone string for the given offset.
329 * For example, "-0800".
330 * @param offset The offset from GMT(UTC) in milliseconds.
331 * @param result Recevies the RFC822 style GMT(UTC) offset format.
332 * @return A reference to the result.
333 * @see #parseOffsetRFC822
334 * @internal ICU 49 technology preview
336 UnicodeString
& formatOffsetRFC822(int32_t offset
, UnicodeString
& result
, UErrorCode
& status
) const;
339 * Returns the ISO 8601 style time zone string for the given offset.
340 * For example, "-08:00" and "Z".
341 * @param offset The offset from GMT(UTC) in milliseconds.
342 * @param result Recevies the ISO 8601 style GMT(UTC) offset format.
343 * @return A reference to the result.
344 * @see #parseOffsetISO8601
345 * @internal ICU 49 technology preview
347 UnicodeString
& formatOffsetISO8601(int32_t offset
, UnicodeString
& result
, UErrorCode
& status
) const;
350 * Returns the localized GMT(UTC) offset format for the given offset.
351 * The localized GMT offset is defined by;
353 * <li>GMT format pattern (e.g. "GMT {0}" - see {@link #getGMTPattern})
354 * <li>Offset time pattern (e.g. "+HH:mm" - see {@link #getGMTOffsetPattern})
355 * <li>Offset digits (e.g. "0123456789" - see {@link #getGMTOffsetDigits})
356 * <li>GMT zero format (e.g. "GMT" - see {@link #getGMTZeroFormat})
358 * @param offset the offset from GMT(UTC) in milliseconds.
359 * @param result Receives the localized GMT format string.
360 * @return A reference to the result.
361 * @see #parseOffsetLocalizedGMT
362 * @internal ICU 49 technology preview
364 UnicodeString
& formatOffsetLocalizedGMT(int32_t offset
, UnicodeString
& result
, UErrorCode
& status
) const;
367 * Returns the display name of the time zone at the given date for the style.
368 * @param style The style (e.g. <code>UTZFMT_STYLE_GENERIC_LONG</code>, <code>UTZFMT_STYLE_LOCALIZED_GMT</code>...)
369 * @param tz The time zone.
370 * @param date The date.
371 * @param name Receives the display name.
372 * @param timeType the output argument for receiving the time type (standard/daylight/unknown)
373 * used for the display name, or NULL if the information is not necessary.
374 * @return A reference to the result
375 * @see #UTimeZoneFormatStyle
376 * @see #UTimeZoneFormatTimeType
377 * @internal ICU 49 technology preview
379 virtual UnicodeString
& format(UTimeZoneFormatStyle style
, const TimeZone
& tz
, UDate date
,
380 UnicodeString
& name
, UTimeZoneFormatTimeType
* timeType
= NULL
) const;
383 * Returns offset from GMT(UTC) in milliseconds for the given RFC822
384 * style time zone string. When the given string is not an RFC822 time zone
385 * string, this method sets the current position as the error index
386 * to <code>ParsePosition pos</code> and returns 0.
387 * @param text The text contains RFC822 style time zone string (e.g. "-0800")
389 * @param pos The ParsePosition object.
390 * @return The offset from GMT(UTC) in milliseconds for the given RFC822 style
392 * @see #formatOffsetRFC822
393 * @internal ICU 49 technology preview
395 int32_t parseOffsetRFC822(const UnicodeString
& text
, ParsePosition
& pos
) const;
398 * Returns offset from GMT(UTC) in milliseconds for the given ISO 8601
399 * style time zone string. When the given string is not an ISO 8601 time zone
400 * string, this method sets the current position as the error index
401 * to <code>ParsePosition pos</code> and returns 0.
402 * @param text The text contains RFC822 style time zone string (e.g. "-08:00", "Z")
404 * @param pos The ParsePosition object.
405 * @return The offset from GMT(UTC) in milliseconds for the given ISO 8601 style
407 * @see #formatOffsetISO8601
408 * @internal ICU 49 technology preview
410 int32_t parseOffsetISO8601(const UnicodeString
& text
, ParsePosition
& pos
) const;
413 * Returns offset from GMT(UTC) in milliseconds for the given localized GMT
414 * offset format string. When the given string cannot be parsed, this method
415 * sets the current position as the error index to <code>ParsePosition pos</code>
417 * @param text The text contains a localized GMT offset string at the position.
418 * @param pos The ParsePosition object.
419 * @return The offset from GMT(UTC) in milliseconds for the given localized GMT
420 * offset format string.
421 * @see #formatOffsetLocalizedGMT
422 * @internal ICU 49 technology preview
424 int32_t parseOffsetLocalizedGMT(const UnicodeString
& text
, ParsePosition
& pos
) const;
427 * Returns a <code>TimeZone</code> by parsing the time zone string according to
428 * the given parse position, the specified format style and parse options.
430 * @param text The text contains a time zone string at the position.
431 * @param style The format style
432 * @param pos The position.
433 * @param parseOptions The parse options repesented by bitwise flags of UTimeZoneFormatParseOption.
434 * @param timeType The output argument for receiving the time type (standard/daylight/unknown),
435 * or NULL if the information is not necessary.
436 * @return A <code>TimeZone</code>, or null if the input could not be parsed.
437 * @see UTimeZoneFormatStyle
438 * @see UTimeZoneFormatParseOption
439 * @see UTimeZoneFormatTimeType
440 * @internal ICU 49 technology preview
442 virtual TimeZone
* parse(UTimeZoneFormatStyle style
, const UnicodeString
& text
, ParsePosition
& pos
,
443 int32_t parseOptions
, UTimeZoneFormatTimeType
* timeType
= NULL
) const;
446 * Returns a <code>TimeZone</code> by parsing the time zone string according to
447 * the given parse position, the specified format style and the default parse options.
449 * @param text The text contains a time zone string at the position.
450 * @param style The format style
451 * @param pos The position.
452 * @param timeType The output argument for receiving the time type (standard/daylight/unknown),
453 * or NULL if the information is not necessary.
454 * @return A <code>TimeZone</code>, or null if the input could not be parsed.
455 * @see UTimeZoneFormatStyle
456 * @see UTimeZoneFormatParseOption
457 * @see UTimeZoneFormatTimeType
458 * @internal ICU 49 technology preview
460 TimeZone
* parse(UTimeZoneFormatStyle style
, const UnicodeString
& text
, ParsePosition
& pos
,
461 UTimeZoneFormatTimeType
* timeType
= NULL
) const;
463 /* ----------------------------------------------
465 * ---------------------------------------------- */
468 * Format an object to produce a time zone display string using localized GMT offset format.
469 * This method handles Formattable objects with a <code>TimeZone</code>. If a the Formattable
470 * object type is not a <code>TimeZone</code>, then it returns a failing UErrorCode.
471 * @param obj The object to format. Must be a <code>TimeZone</code>.
472 * @param appendTo Output parameter to receive result. Result is appended to existing contents.
473 * @param pos On input: an alignment field, if desired. On output: the offsets of the alignment field.
474 * @param status Output param filled with success/failure status.
475 * @return Reference to 'appendTo' parameter.
476 * @internal ICU 49 technology preview
478 virtual UnicodeString
& format(const Formattable
& obj
, UnicodeString
& appendTo
,
479 FieldPosition
& pos
, UErrorCode
& status
) const;
482 * Parse a string to produce an object. This methods handles parsing of
483 * time zone display strings into Formattable objects with <code>TimeZone</code>.
484 * @param source The string to be parsed into an object.
485 * @param result Formattable to be set to the parse result. If parse fails, return contents are undefined.
486 * @param parse_pos The position to start parsing at. Upon return this param is set to the position after the
487 * last character successfully parsed. If the source is not parsed successfully, this param
488 * will remain unchanged.
489 * @return A newly created Formattable* object, or NULL on failure. The caller owns this and should
490 * delete it when done.
491 * @internal ICU 49 technology preview
493 virtual void parseObject(const UnicodeString
& source
, Formattable
& result
, ParsePosition
& parse_pos
) const;
496 * ICU "poor man's RTTI", returns a UClassID for this class.
497 * @internal ICU 49 technology preview
499 static UClassID U_EXPORT2
getStaticClassID(void);
502 * ICU "poor man's RTTI", returns a UClassID for the actual class.
503 * @internal ICU 49 technology preview
505 virtual UClassID
getDynamicClassID() const;
509 * Constructs a TimeZoneFormat object for the specified locale.
510 * @param locale the locale
511 * @param status receives the status.
512 * @internal ICU 49 technology preview
514 TimeZoneFormat(const Locale
& locale
, UErrorCode
& status
);
520 /* Locale of this object */
523 /* Stores the region (could be implicit default) */
524 char fTargetRegion
[ULOC_COUNTRY_CAPACITY
];
526 /* TimeZoneNames object used by this formatter */
527 TimeZoneNames
* fTimeZoneNames
;
529 /* TimeZoneGenericNames object used by this formatter - lazily instantiated */
530 TimeZoneGenericNames
* fTimeZoneGenericNames
;
532 /* Localized GMT format pattern - e.g. "GMT{0}" */
533 UnicodeString fGMTPattern
;
535 /* Array of offset patterns used by Localized GMT format - e.g. "+HH:mm" */
536 UnicodeString fGMTOffsetPatterns
[UTZFMT_PAT_NEGATIVE_HMS
+ 1];
538 /* Localized decimal digits used by Localized GMT format */
539 UChar32 fGMTOffsetDigits
[10];
541 /* Localized GMT zero format - e.g. "GMT" */
542 UnicodeString fGMTZeroFormat
;
544 /* Bit flags representing parse options */
545 int32_t fDefParseOptionFlags
;
547 /* Constant parts of GMT format pattern, populated from localized GMT format pattern*/
548 UnicodeString fGMTPatternPrefix
; /* Substring before {0} */
549 UnicodeString fGMTPatternSuffix
; /* Substring after {0} */
551 /* Compiled offset patterns generated from fGMTOffsetPatterns[] */
552 UVector
* fGMTOffsetPatternItems
[UTZFMT_PAT_NEGATIVE_HMS
+ 1];
555 * Returns the time zone's specific format string.
556 * @param tz the time zone
557 * @param stdType the name type used for standard time
558 * @param dstType the name type used for daylight time
559 * @param date the date
560 * @param name receives the time zone's specific format name string
561 * @param timeType when null, actual time type is set
562 * @return a reference to name.
564 UnicodeString
& formatSpecific(const TimeZone
& tz
, UTimeZoneNameType stdType
, UTimeZoneNameType dstType
,
565 UDate date
, UnicodeString
& name
, UTimeZoneFormatTimeType
*timeType
) const;
568 * Returns the time zone's generic format string.
569 * @param tz the time zone
570 * @param genType the generic name type
571 * @param date the date
572 * @param name receives the time zone's generic format name string
573 * @return a reference to name.
575 UnicodeString
& formatGeneric(const TimeZone
& tz
, int32_t genType
, UDate date
, UnicodeString
& name
) const;
578 * Lazily create a TimeZoneGenericNames instance
579 * @param status receives the status
580 * @return the cached TimeZoneGenericNames.
582 const TimeZoneGenericNames
* getTimeZoneGenericNames(UErrorCode
& status
) const;
585 * Private enum specifying a combination of offset fields
594 * Parses the localized GMT pattern string and initialize
595 * localized gmt pattern fields.
596 * @param gmtPattern the localized GMT pattern string such as "GMT {0}"
597 * @param status U_ILLEGAL_ARGUMENT_ERROR is set when the specified pattern does not
598 * contain an argument "{0}".
600 void initGMTPattern(const UnicodeString
& gmtPattern
, UErrorCode
& status
);
603 * Parse the GMT offset pattern into runtime optimized format.
604 * @param pattern the offset pattern string
605 * @param required the required set of fields, such as FIELDS_HM
606 * @param status U_ILLEGAL_ARGUMENT is set when the specified pattern does not contain
607 * pattern letters for the required fields.
608 * @return A list of GMTOffsetField objects, or NULL on error.
610 static UVector
* parseOffsetPattern(const UnicodeString
& pattern
, OffsetFields required
, UErrorCode
& status
);
613 * Appends second field to the offset pattern with hour/minute
614 * Note: This code will be obsoleted once we add hour-minute-second pattern data in CLDR.
615 * @param offsetHM the offset pattern including hour and minute fields
616 * @param result the output offset pattern including hour, minute and second fields
617 * @return a reference to result
619 static UnicodeString
& expandOffsetPattern(const UnicodeString
& offsetHM
, UnicodeString
& result
);
622 * Break input string into UChar32[]. Each array element represents
623 * a code point. This method is used for parsing localized digit
624 * characters and support characters in Unicode supplemental planes.
625 * @param str the string
626 * @param codeArray receives the result
627 * @param capacity the capacity of codeArray
628 * @return TRUE when the specified code array is fully filled with code points
629 * (no under/overflow).
631 static UBool
toCodePoints(const UnicodeString
& str
, UChar32
* codeArray
, int32_t capacity
);
634 * Returns offset from GMT(UTC) in milliseconds for the given ISO 8601 style
635 * (extended format) time zone string. When the given string is not an ISO 8601 time
636 * zone string, this method sets the current position as the error index
637 * to <code>ParsePosition pos</code> and returns 0.
638 * @param text the text contains ISO 8601 style time zone string (e.g. "-08:00", "Z")
640 * @param pos the position, non-negative error index will be set on failure.
641 * @param extendedOnly TRUE if parsing the text as ISO 8601 extended offset format (e.g. "-08:00"),
642 * or FALSE to evaluate the text as basic format.
643 * @param hasDigitOffset receiving if the parsed zone string contains offset digits.
644 * @return the offset from GMT(UTC) in milliseconds for the given ISO 8601 style
647 int32_t parseOffsetISO8601(const UnicodeString
& text
, ParsePosition
& pos
, UBool extendedOnly
,
648 UBool
* hasDigitOffset
= NULL
) const;
651 * Appends localized digits to the buffer.
652 * This code assumes that the input number is 0 - 59
653 * @param buf the target buffer
654 * @param n the integer number
655 * @param minDigits the minimum digits width
657 void appendOffsetDigits(UnicodeString
& buf
, int32_t n
, uint8_t minDigits
) const;
660 * Returns offset from GMT(UTC) in milliseconds for the given localized GMT
661 * offset format string. When the given string cannot be parsed, this method
662 * sets the current position as the error index to <code>ParsePosition pos</code>
664 * @param text the text contains a localized GMT offset string at the position.
665 * @param pos the position, non-negative error index will be set on failure.
666 * @param hasDigitOffset receiving if the parsed zone string contains offset digits.
667 * @return the offset from GMT(UTC) in milliseconds for the given localized GMT
668 * offset format string.
670 int32_t parseOffsetLocalizedGMT(const UnicodeString
& text
, ParsePosition
& pos
,
671 UBool
* hasDigitOffset
) const;
674 * Parses localized GMT offset fields into offset.
675 * @param text the input text
676 * @param start the start index
677 * @param minimumHourWidth true if the parser allows hour field width to be 1
678 * @param parsedLen the parsed length, or 0 on failure.
679 * @return the parsed offset in milliseconds.
681 int32_t parseOffsetFields(const UnicodeString
& text
, int32_t start
, UBool minimumHourWidth
,
682 int32_t& parsedLen
) const;
685 * Parses abutting localized GMT offset fields (such as 0800) into offset.
686 * @param text the input text
687 * @param start the start index
688 * @param parsedLen the parsed length, or 0 on failure
689 * @return the parsed offset in milliseconds.
691 int32_t parseAbuttingOffsetFields(const UnicodeString
& text
, int32_t start
, int32_t& parsedLen
) const;
694 * Parses the input text using the default format patterns (e.g. "UTC{0}").
695 * @param text the input text
696 * @param start the start index
697 * @param parsedLen the parsed length, or 0 on failure
698 * @return the parsed offset in milliseconds.
700 int32_t parseOffsetDefaultLocalizedGMT(const UnicodeString
& text
, int start
, int32_t& parsedLen
) const;
703 * Parses the input GMT offset fields with the default offset pattern.
704 * @param text the input text
705 * @param start the start index
706 * @param separator the separator character, e.g. ':'
707 * @param parsedLen the parsed length, or 0 on failure.
708 * @return the parsed offset in milliseconds.
710 int32_t parseDefaultOffsetFields(const UnicodeString
& text
, int32_t start
, UChar separator
,
711 int32_t& parsedLen
) const;
714 * Reads an offset field value. This method will stop parsing when
715 * 1) number of digits reaches <code>maxDigits</code>
716 * 2) just before already parsed number exceeds <code>maxVal</code>
718 * @param text the text
719 * @param start the start offset
720 * @param minDigits the minimum number of required digits
721 * @param maxDigits the maximum number of digits
722 * @param minVal the minimum value
723 * @param maxVal the maximum value
724 * @param parsedLen the actual parsed length.
725 * @return the integer value parsed
727 int32_t parseOffsetFieldWithLocalizedDigits(const UnicodeString
& text
, int32_t start
,
728 uint8_t minDigits
, uint8_t maxDigits
, uint16_t minVal
, uint16_t maxVal
, int32_t& parsedLen
) const;
731 * Reads a single decimal digit, either localized digits used by this object
732 * or any Unicode numeric character.
733 * @param text the text
734 * @param start the start index
735 * @param len the actual length read from the text
736 * the start index is not a decimal number.
737 * @return the integer value of the parsed digit, or -1 on failure.
739 int32_t parseSingleLocalizedDigit(const UnicodeString
& text
, int32_t start
, int32_t& len
) const;
742 * Formats offset using ASCII digits. The input offset range must be
743 * within +/-24 hours (exclusive).
744 * @param offset The offset
745 * @param sep The field separator character or 0 if not required
746 * @param minFields The minimum fields
747 * @param maxFields The maximum fields
748 * @return The offset string
750 static UnicodeString
& formatOffsetWithAsciiDigits(int32_t offset
, UChar sep
,
751 OffsetFields minFields
, OffsetFields maxFields
, UnicodeString
& result
);
754 * Parses offset represented by contiguous ASCII digits.
756 * Note: This method expects the input position is already at the start of
757 * ASCII digits and does not parse sign (+/-).
758 * @param text The text contains a sequence of ASCII digits
759 * @param pos The parse position
760 * @param minFields The minimum Fields to be parsed
761 * @param maxFields The maximum Fields to be parsed
762 * @param fixedHourWidth true if hour field must be width of 2
763 * @return Parsed offset, 0 or positive number.
765 static int32_t parseAbuttingAsciiOffsetFields(const UnicodeString
& text
, ParsePosition
& pos
,
766 OffsetFields minFields
, OffsetFields maxFields
, UBool fixedHourWidth
);
769 * Parses offset represented by ASCII digits and separators.
771 * Note: This method expects the input position is already at the start of
772 * ASCII digits and does not parse sign (+/-).
773 * @param text The text
774 * @param pos The parse position
775 * @param sep The separator character
776 * @param minFields The minimum Fields to be parsed
777 * @param maxFields The maximum Fields to be parsed
778 * @param fixedHourWidth true if hour field must be width of 2
779 * @return Parsed offset, 0 or positive number.
781 static int32_t parseAsciiOffsetFields(const UnicodeString
& text
, ParsePosition
& pos
, UChar sep
,
782 OffsetFields minFields
, OffsetFields maxFields
, UBool fixedHourWidth
);
785 * Unquotes the message format style pattern.
786 * @param pattern the pattern
787 * @param result receive the unquoted pattern.
788 * @return A reference to result.
790 static UnicodeString
& unquote(const UnicodeString
& pattern
, UnicodeString
& result
);
793 * Initialize localized GMT format offset hour/min/sec patterns.
794 * This method parses patterns into optimized run-time format.
795 * @param status receives the status.
797 void initGMTOffsetPatterns(UErrorCode
& status
);
800 * Creates an instance of TimeZone for the given offset
801 * @param offset the offset
802 * @return A TimeZone with the given offset
804 TimeZone
* createTimeZoneForOffset(int32_t offset
) const;
807 * Returns the time type for the given name type
808 * @param nameType the name type
809 * @return the time type (unknown/standard/daylight)
811 static UTimeZoneFormatTimeType
getTimeType(UTimeZoneNameType nameType
);
814 * Returns the time zone ID of a match at the specified index within
815 * the MatchInfoCollection.
816 * @param matches the collection of matches
817 * @param idx the index withing matches
818 * @param tzID receives the resolved time zone ID
819 * @return a reference to tzID.
821 UnicodeString
& getTimeZoneID(const TimeZoneNames::MatchInfoCollection
* matches
, int32_t idx
, UnicodeString
& tzID
) const;
826 #endif /* U_HIDE_INTERNAL_API */