1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
5 * Copyright (C) 2011-2015, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 *******************************************************************************
14 * \brief C++ API: TimeZoneFormat
17 #include "unicode/utypes.h"
19 #if U_SHOW_CPLUSPLUS_API
21 #if !UCONFIG_NO_FORMATTING
23 #include "unicode/format.h"
24 #include "unicode/timezone.h"
25 #include "unicode/tznames.h"
29 * Constants for time zone display format style used by format/parse APIs
33 typedef enum UTimeZoneFormatStyle
{
35 * Generic location format, such as "United States Time (New York)", "Italy Time"
38 UTZFMT_STYLE_GENERIC_LOCATION
,
40 * Generic long non-location format, such as "Eastern Time".
43 UTZFMT_STYLE_GENERIC_LONG
,
45 * Generic short non-location format, such as "ET".
48 UTZFMT_STYLE_GENERIC_SHORT
,
50 * Specific long format, such as "Eastern Standard Time".
53 UTZFMT_STYLE_SPECIFIC_LONG
,
55 * Specific short format, such as "EST", "PDT".
58 UTZFMT_STYLE_SPECIFIC_SHORT
,
60 * Localized GMT offset format, such as "GMT-05:00", "UTC+0100"
63 UTZFMT_STYLE_LOCALIZED_GMT
,
65 * Short localized GMT offset format, such as "GMT-5", "UTC+1:30"
66 * This style is equivalent to the LDML date format pattern "O".
69 UTZFMT_STYLE_LOCALIZED_GMT_SHORT
,
71 * Short ISO 8601 local time difference (basic format) or the UTC indicator.
72 * For example, "-05", "+0530", and "Z"(UTC).
73 * This style is equivalent to the LDML date format pattern "X".
76 UTZFMT_STYLE_ISO_BASIC_SHORT
,
78 * Short ISO 8601 locale time difference (basic format).
79 * For example, "-05" and "+0530".
80 * This style is equivalent to the LDML date format pattern "x".
83 UTZFMT_STYLE_ISO_BASIC_LOCAL_SHORT
,
85 * Fixed width ISO 8601 local time difference (basic format) or the UTC indicator.
86 * For example, "-0500", "+0530", and "Z"(UTC).
87 * This style is equivalent to the LDML date format pattern "XX".
90 UTZFMT_STYLE_ISO_BASIC_FIXED
,
92 * Fixed width ISO 8601 local time difference (basic format).
93 * For example, "-0500" and "+0530".
94 * This style is equivalent to the LDML date format pattern "xx".
97 UTZFMT_STYLE_ISO_BASIC_LOCAL_FIXED
,
99 * ISO 8601 local time difference (basic format) with optional seconds field, or the UTC indicator.
100 * For example, "-0500", "+052538", and "Z"(UTC).
101 * This style is equivalent to the LDML date format pattern "XXXX".
104 UTZFMT_STYLE_ISO_BASIC_FULL
,
106 * ISO 8601 local time difference (basic format) with optional seconds field.
107 * For example, "-0500" and "+052538".
108 * This style is equivalent to the LDML date format pattern "xxxx".
111 UTZFMT_STYLE_ISO_BASIC_LOCAL_FULL
,
113 * Fixed width ISO 8601 local time difference (extended format) or the UTC indicator.
114 * For example, "-05:00", "+05:30", and "Z"(UTC).
115 * This style is equivalent to the LDML date format pattern "XXX".
118 UTZFMT_STYLE_ISO_EXTENDED_FIXED
,
120 * Fixed width ISO 8601 local time difference (extended format).
121 * For example, "-05:00" and "+05:30".
122 * This style is equivalent to the LDML date format pattern "xxx" and "ZZZZZ".
125 UTZFMT_STYLE_ISO_EXTENDED_LOCAL_FIXED
,
127 * ISO 8601 local time difference (extended format) with optional seconds field, or the UTC indicator.
128 * For example, "-05:00", "+05:25:38", and "Z"(UTC).
129 * This style is equivalent to the LDML date format pattern "XXXXX".
132 UTZFMT_STYLE_ISO_EXTENDED_FULL
,
134 * ISO 8601 local time difference (extended format) with optional seconds field.
135 * For example, "-05:00" and "+05:25:38".
136 * This style is equivalent to the LDML date format pattern "xxxxx".
139 UTZFMT_STYLE_ISO_EXTENDED_LOCAL_FULL
,
141 * Time Zone ID, such as "America/Los_Angeles".
144 UTZFMT_STYLE_ZONE_ID
,
146 * Short Time Zone ID (BCP 47 Unicode location extension, time zone type value), such as "uslax".
149 UTZFMT_STYLE_ZONE_ID_SHORT
,
151 * Exemplar location, such as "Los Angeles" and "Paris".
154 UTZFMT_STYLE_EXEMPLAR_LOCATION
155 } UTimeZoneFormatStyle
;
158 * Constants for GMT offset pattern types.
161 typedef enum UTimeZoneFormatGMTOffsetPatternType
{
163 * Positive offset with hours and minutes fields
166 UTZFMT_PAT_POSITIVE_HM
,
168 * Positive offset with hours, minutes and seconds fields
171 UTZFMT_PAT_POSITIVE_HMS
,
173 * Negative offset with hours and minutes fields
176 UTZFMT_PAT_NEGATIVE_HM
,
178 * Negative offset with hours, minutes and seconds fields
181 UTZFMT_PAT_NEGATIVE_HMS
,
183 * Positive offset with hours field
186 UTZFMT_PAT_POSITIVE_H
,
188 * Negative offset with hours field
191 UTZFMT_PAT_NEGATIVE_H
,
193 /* The following cannot be #ifndef U_HIDE_INTERNAL_API, needed for other .h declarations */
195 * Number of UTimeZoneFormatGMTOffsetPatternType types.
199 } UTimeZoneFormatGMTOffsetPatternType
;
202 * Constants for time types used by TimeZoneFormat APIs for
203 * receiving time type (standard time, daylight time or unknown).
206 typedef enum UTimeZoneFormatTimeType
{
211 UTZFMT_TIME_TYPE_UNKNOWN
,
216 UTZFMT_TIME_TYPE_STANDARD
,
218 * Daylight saving time
221 UTZFMT_TIME_TYPE_DAYLIGHT
222 } UTimeZoneFormatTimeType
;
225 * Constants for parse option flags, used for specifying optional parse behavior.
228 typedef enum UTimeZoneFormatParseOption
{
233 UTZFMT_PARSE_OPTION_NONE
= 0x00,
235 * When a time zone display name is not found within a set of display names
236 * used for the specified style, look for the name from display names used
240 UTZFMT_PARSE_OPTION_ALL_STYLES
= 0x01,
242 * When parsing a time zone display name in \link UTZFMT_STYLE_SPECIFIC_SHORT \endlink,
243 * look for the IANA tz database compatible zone abbreviations in addition
244 * to the localized names coming from the icu::TimeZoneNames currently
245 * used by the icu::TimeZoneFormat.
248 UTZFMT_PARSE_OPTION_TZ_DATABASE_ABBREVIATIONS
= 0x02
249 } UTimeZoneFormatParseOption
;
255 class TimeZoneGenericNames
;
256 class TZDBTimeZoneNames
;
260 * <code>TimeZoneFormat</code> supports time zone display name formatting and parsing.
261 * An instance of TimeZoneFormat works as a subformatter of {@link SimpleDateFormat},
262 * but you can also directly get a new instance of <code>TimeZoneFormat</code> and
263 * formatting/parsing time zone display names.
265 * ICU implements the time zone display names defined by <a href="http://www.unicode.org/reports/tr35/">UTS#35
266 * Unicode Locale Data Markup Language (LDML)</a>. {@link TimeZoneNames} represents the
267 * time zone display name data model and this class implements the algorithm for actual
268 * formatting and parsing.
270 * @see SimpleDateFormat
274 class U_I18N_API TimeZoneFormat
: public Format
{
280 TimeZoneFormat(const TimeZoneFormat
& other
);
286 virtual ~TimeZoneFormat();
289 * Assignment operator.
292 TimeZoneFormat
& operator=(const TimeZoneFormat
& other
);
295 * Return true if the given Format objects are semantically equal.
296 * Objects of different subclasses are considered unequal.
297 * @param other The object to be compared with.
298 * @return Return TRUE if the given Format objects are semantically equal.
299 * Objects of different subclasses are considered unequal.
302 virtual UBool
operator==(const Format
& other
) const;
305 * Clone this object polymorphically. The caller is responsible
306 * for deleting the result when done.
307 * @return A copy of the object
310 virtual TimeZoneFormat
* clone() const;
313 * Creates an instance of <code>TimeZoneFormat</code> for the given locale.
314 * @param locale The locale.
315 * @param status Receives the status.
316 * @return An instance of <code>TimeZoneFormat</code> for the given locale,
317 * owned by the caller.
320 static TimeZoneFormat
* U_EXPORT2
createInstance(const Locale
& locale
, UErrorCode
& status
);
323 * Returns the time zone display name data used by this instance.
324 * @return The time zone display name data.
327 const TimeZoneNames
* getTimeZoneNames() const;
330 * Sets the time zone display name data to this format instnace.
331 * The caller should not delete the TimeZoenNames object after it is adopted
333 * @param tznames TimeZoneNames object to be adopted.
336 void adoptTimeZoneNames(TimeZoneNames
*tznames
);
339 * Sets the time zone display name data to this format instnace.
340 * @param tznames TimeZoneNames object to be set.
343 void setTimeZoneNames(const TimeZoneNames
&tznames
);
346 * Returns the localized GMT format pattern.
347 * @param pattern Receives the localized GMT format pattern.
348 * @return A reference to the result pattern.
349 * @see #setGMTPattern
352 UnicodeString
& getGMTPattern(UnicodeString
& pattern
) const;
355 * Sets the localized GMT format pattern. The pattern must contain
356 * a single argument {0}, for example "GMT {0}".
357 * @param pattern The localized GMT format pattern to be used by this object.
358 * @param status Recieves the status.
359 * @see #getGMTPattern
362 void setGMTPattern(const UnicodeString
& pattern
, UErrorCode
& status
);
365 * Returns the offset pattern used for localized GMT format.
366 * @param type The offset pattern type enum.
367 * @param pattern Receives the offset pattern.
368 * @return A reference to the result pattern.
369 * @see #setGMTOffsetPattern
372 UnicodeString
& getGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type
, UnicodeString
& pattern
) const;
375 * Sets the offset pattern for the given offset type.
376 * @param type The offset pattern type enum.
377 * @param pattern The offset pattern used for localized GMT format for the type.
378 * @param status Receives the status.
379 * @see #getGMTOffsetPattern
382 void setGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type
, const UnicodeString
& pattern
, UErrorCode
& status
);
385 * Returns the decimal digit characters used for localized GMT format.
386 * The return string contains exactly 10 code points (may include Unicode
387 * supplementary character) representing digit 0 to digit 9 in the ascending
389 * @param digits Receives the decimal digits used for localized GMT format.
390 * @see #setGMTOffsetDigits
393 UnicodeString
& getGMTOffsetDigits(UnicodeString
& digits
) const;
396 * Sets the decimal digit characters used for localized GMT format.
397 * The input <code>digits</code> must contain exactly 10 code points
398 * (Unicode supplementary characters are also allowed) representing
399 * digit 0 to digit 9 in the ascending order. When the input <code>digits</code>
400 * does not satisfy the condition, <code>U_ILLEGAL_ARGUMENT_ERROR</code>
401 * will be set to the return status.
402 * @param digits The decimal digits used for localized GMT format.
403 * @param status Receives the status.
404 * @see #getGMTOffsetDigits
407 void setGMTOffsetDigits(const UnicodeString
& digits
, UErrorCode
& status
);
410 * Returns the localized GMT format string for GMT(UTC) itself (GMT offset is 0).
411 * @param gmtZeroFormat Receives the localized GMT string string for GMT(UTC) itself.
412 * @return A reference to the result GMT string.
413 * @see #setGMTZeroFormat
416 UnicodeString
& getGMTZeroFormat(UnicodeString
& gmtZeroFormat
) const;
419 * Sets the localized GMT format string for GMT(UTC) itself (GMT offset is 0).
420 * @param gmtZeroFormat The localized GMT format string for GMT(UTC).
421 * @param status Receives the status.
422 * @see #getGMTZeroFormat
425 void setGMTZeroFormat(const UnicodeString
& gmtZeroFormat
, UErrorCode
& status
);
428 * Returns the bitwise flags of UTimeZoneFormatParseOption representing the default parse
429 * options used by this object.
430 * @return the default parse options.
434 uint32_t getDefaultParseOptions(void) const;
437 * Sets the default parse options.
438 * <p><b>Note</b>: By default, an instance of <code>TimeZoneFormat</code>
439 * created by {@link #createInstance} has no parse options set (UTZFMT_PARSE_OPTION_NONE).
440 * To specify multipe options, use bitwise flags of UTimeZoneFormatParseOption.
441 * @see #UTimeZoneFormatParseOption
444 void setDefaultParseOptions(uint32_t flags
);
447 * Returns the ISO 8601 basic time zone string for the given offset.
448 * For example, "-08", "-0830" and "Z"
450 * @param offset the offset from GMT(UTC) in milliseconds.
451 * @param useUtcIndicator true if ISO 8601 UTC indicator "Z" is used when the offset is 0.
452 * @param isShort true if shortest form is used.
453 * @param ignoreSeconds true if non-zero offset seconds is appended.
454 * @param result Receives the ISO format string.
455 * @param status Receives the status
456 * @return the ISO 8601 basic format.
457 * @see #formatOffsetISO8601Extended
458 * @see #parseOffsetISO8601
461 UnicodeString
& formatOffsetISO8601Basic(int32_t offset
, UBool useUtcIndicator
, UBool isShort
, UBool ignoreSeconds
,
462 UnicodeString
& result
, UErrorCode
& status
) const;
465 * Returns the ISO 8601 extended time zone string for the given offset.
466 * For example, "-08:00", "-08:30" and "Z"
468 * @param offset the offset from GMT(UTC) in milliseconds.
469 * @param useUtcIndicator true if ISO 8601 UTC indicator "Z" is used when the offset is 0.
470 * @param isShort true if shortest form is used.
471 * @param ignoreSeconds true if non-zero offset seconds is appended.
472 * @param result Receives the ISO format string.
473 * @param status Receives the status
474 * @return the ISO 8601 basic format.
475 * @see #formatOffsetISO8601Extended
476 * @see #parseOffsetISO8601
479 UnicodeString
& formatOffsetISO8601Extended(int32_t offset
, UBool useUtcIndicator
, UBool isShort
, UBool ignoreSeconds
,
480 UnicodeString
& result
, UErrorCode
& status
) const;
483 * Returns the localized GMT(UTC) offset format for the given offset.
484 * The localized GMT offset is defined by;
486 * <li>GMT format pattern (e.g. "GMT {0}" - see {@link #getGMTPattern})
487 * <li>Offset time pattern (e.g. "+HH:mm" - see {@link #getGMTOffsetPattern})
488 * <li>Offset digits (e.g. "0123456789" - see {@link #getGMTOffsetDigits})
489 * <li>GMT zero format (e.g. "GMT" - see {@link #getGMTZeroFormat})
491 * This format always uses 2 digit hours and minutes. When the given offset has non-zero
492 * seconds, 2 digit seconds field will be appended. For example,
493 * GMT+05:00 and GMT+05:28:06.
494 * @param offset the offset from GMT(UTC) in milliseconds.
495 * @param status Receives the status
496 * @param result Receives the localized GMT format string.
497 * @return A reference to the result.
498 * @see #parseOffsetLocalizedGMT
501 UnicodeString
& formatOffsetLocalizedGMT(int32_t offset
, UnicodeString
& result
, UErrorCode
& status
) const;
504 * Returns the short localized GMT(UTC) offset format for the given offset.
505 * The short localized GMT offset is defined by;
507 * <li>GMT format pattern (e.g. "GMT {0}" - see {@link #getGMTPattern})
508 * <li>Offset time pattern (e.g. "+HH:mm" - see {@link #getGMTOffsetPattern})
509 * <li>Offset digits (e.g. "0123456789" - see {@link #getGMTOffsetDigits})
510 * <li>GMT zero format (e.g. "GMT" - see {@link #getGMTZeroFormat})
512 * This format uses the shortest representation of offset. The hours field does not
513 * have leading zero and lower fields with zero will be truncated. For example,
515 * @param offset the offset from GMT(UTC) in milliseconds.
516 * @param status Receives the status
517 * @param result Receives the short localized GMT format string.
518 * @return A reference to the result.
519 * @see #parseOffsetShortLocalizedGMT
522 UnicodeString
& formatOffsetShortLocalizedGMT(int32_t offset
, UnicodeString
& result
, UErrorCode
& status
) const;
524 using Format::format
;
527 * Returns the display name of the time zone at the given date for the style.
528 * @param style The style (e.g. <code>UTZFMT_STYLE_GENERIC_LONG</code>, <code>UTZFMT_STYLE_LOCALIZED_GMT</code>...)
529 * @param tz The time zone.
530 * @param date The date.
531 * @param name Receives the display name.
532 * @param timeType the output argument for receiving the time type (standard/daylight/unknown)
533 * used for the display name, or NULL if the information is not necessary.
534 * @return A reference to the result
535 * @see #UTimeZoneFormatStyle
536 * @see #UTimeZoneFormatTimeType
539 virtual UnicodeString
& format(UTimeZoneFormatStyle style
, const TimeZone
& tz
, UDate date
,
540 UnicodeString
& name
, UTimeZoneFormatTimeType
* timeType
= NULL
) const;
543 * Returns offset from GMT(UTC) in milliseconds for the given ISO 8601
544 * style time zone string. When the given string is not an ISO 8601 time zone
545 * string, this method sets the current position as the error index
546 * to <code>ParsePosition pos</code> and returns 0.
547 * @param text The text contains ISO8601 style time zone string (e.g. "-08:00", "Z")
549 * @param pos The ParsePosition object.
550 * @return The offset from GMT(UTC) in milliseconds for the given ISO 8601 style
552 * @see #formatOffsetISO8601Basic
553 * @see #formatOffsetISO8601Extended
556 int32_t parseOffsetISO8601(const UnicodeString
& text
, ParsePosition
& pos
) const;
559 * Returns offset from GMT(UTC) in milliseconds for the given localized GMT
560 * offset format string. When the given string cannot be parsed, this method
561 * sets the current position as the error index to <code>ParsePosition pos</code>
563 * @param text The text contains a localized GMT offset string at the position.
564 * @param pos The ParsePosition object.
565 * @return The offset from GMT(UTC) in milliseconds for the given localized GMT
566 * offset format string.
567 * @see #formatOffsetLocalizedGMT
570 int32_t parseOffsetLocalizedGMT(const UnicodeString
& text
, ParsePosition
& pos
) const;
573 * Returns offset from GMT(UTC) in milliseconds for the given short localized GMT
574 * offset format string. When the given string cannot be parsed, this method
575 * sets the current position as the error index to <code>ParsePosition pos</code>
577 * @param text The text contains a short localized GMT offset string at the position.
578 * @param pos The ParsePosition object.
579 * @return The offset from GMT(UTC) in milliseconds for the given short localized GMT
580 * offset format string.
581 * @see #formatOffsetShortLocalizedGMT
584 int32_t parseOffsetShortLocalizedGMT(const UnicodeString
& text
, ParsePosition
& pos
) const;
587 * Returns a <code>TimeZone</code> by parsing the time zone string according to
588 * the given parse position, the specified format style and parse options.
590 * @param text The text contains a time zone string at the position.
591 * @param style The format style
592 * @param pos The position.
593 * @param parseOptions The parse options repesented by bitwise flags of UTimeZoneFormatParseOption.
594 * @param timeType The output argument for receiving the time type (standard/daylight/unknown),
595 * or NULL if the information is not necessary.
596 * @return A <code>TimeZone</code>, or null if the input could not be parsed.
597 * @see UTimeZoneFormatStyle
598 * @see UTimeZoneFormatParseOption
599 * @see UTimeZoneFormatTimeType
602 virtual TimeZone
* parse(UTimeZoneFormatStyle style
, const UnicodeString
& text
, ParsePosition
& pos
,
603 int32_t parseOptions
, UTimeZoneFormatTimeType
* timeType
= NULL
) const;
606 * Returns a <code>TimeZone</code> by parsing the time zone string according to
607 * the given parse position, the specified format style and the default parse options.
609 * @param text The text contains a time zone string at the position.
610 * @param style The format style
611 * @param pos The position.
612 * @param timeType The output argument for receiving the time type (standard/daylight/unknown),
613 * or NULL if the information is not necessary.
614 * @return A <code>TimeZone</code>, or null if the input could not be parsed.
615 * @see UTimeZoneFormatStyle
616 * @see UTimeZoneFormatParseOption
617 * @see UTimeZoneFormatTimeType
620 TimeZone
* parse(UTimeZoneFormatStyle style
, const UnicodeString
& text
, ParsePosition
& pos
,
621 UTimeZoneFormatTimeType
* timeType
= NULL
) const;
623 /* ----------------------------------------------
625 * ---------------------------------------------- */
628 * Format an object to produce a time zone display string using localized GMT offset format.
629 * This method handles Formattable objects with a <code>TimeZone</code>. If a the Formattable
630 * object type is not a <code>TimeZone</code>, then it returns a failing UErrorCode.
631 * @param obj The object to format. Must be a <code>TimeZone</code>.
632 * @param appendTo Output parameter to receive result. Result is appended to existing contents.
633 * @param pos On input: an alignment field, if desired. On output: the offsets of the alignment field.
634 * @param status Output param filled with success/failure status.
635 * @return Reference to 'appendTo' parameter.
638 virtual UnicodeString
& format(const Formattable
& obj
, UnicodeString
& appendTo
,
639 FieldPosition
& pos
, UErrorCode
& status
) const;
642 * Parse a string to produce an object. This methods handles parsing of
643 * time zone display strings into Formattable objects with <code>TimeZone</code>.
644 * @param source The string to be parsed into an object.
645 * @param result Formattable to be set to the parse result. If parse fails, return contents are undefined.
646 * @param parse_pos The position to start parsing at. Upon return this param is set to the position after the
647 * last character successfully parsed. If the source is not parsed successfully, this param
648 * will remain unchanged.
649 * @return A newly created Formattable* object, or NULL on failure. The caller owns this and should
650 * delete it when done.
653 virtual void parseObject(const UnicodeString
& source
, Formattable
& result
, ParsePosition
& parse_pos
) const;
656 * ICU "poor man's RTTI", returns a UClassID for this class.
659 static UClassID U_EXPORT2
getStaticClassID(void);
662 * ICU "poor man's RTTI", returns a UClassID for the actual class.
665 virtual UClassID
getDynamicClassID() const;
669 * Constructs a TimeZoneFormat object for the specified locale.
670 * @param locale the locale
671 * @param status receives the status.
674 TimeZoneFormat(const Locale
& locale
, UErrorCode
& status
);
677 /* Locale of this object */
680 /* Stores the region (could be implicit default) */
681 char fTargetRegion
[ULOC_COUNTRY_CAPACITY
];
683 /* TimeZoneNames object used by this formatter */
684 TimeZoneNames
* fTimeZoneNames
;
686 /* TimeZoneGenericNames object used by this formatter - lazily instantiated */
687 TimeZoneGenericNames
* fTimeZoneGenericNames
;
689 /* Localized GMT format pattern - e.g. "GMT{0}" */
690 UnicodeString fGMTPattern
;
692 /* Array of offset patterns used by Localized GMT format - e.g. "+HH:mm" */
693 UnicodeString fGMTOffsetPatterns
[UTZFMT_PAT_COUNT
];
695 /* Localized decimal digits used by Localized GMT format */
696 UChar32 fGMTOffsetDigits
[10];
698 /* Localized GMT zero format - e.g. "GMT" */
699 UnicodeString fGMTZeroFormat
;
701 /* Bit flags representing parse options */
702 uint32_t fDefParseOptionFlags
;
704 /* Constant parts of GMT format pattern, populated from localized GMT format pattern*/
705 UnicodeString fGMTPatternPrefix
; /* Substring before {0} */
706 UnicodeString fGMTPatternSuffix
; /* Substring after {0} */
708 /* Compiled offset patterns generated from fGMTOffsetPatterns[] */
709 UVector
* fGMTOffsetPatternItems
[UTZFMT_PAT_COUNT
];
711 UBool fAbuttingOffsetHoursAndMinutes
;
713 /* TZDBTimeZoneNames object used for parsing */
714 TZDBTimeZoneNames
* fTZDBTimeZoneNames
;
717 * Returns the time zone's specific format string.
718 * @param tz the time zone
719 * @param stdType the name type used for standard time
720 * @param dstType the name type used for daylight time
721 * @param date the date
722 * @param name receives the time zone's specific format name string
723 * @param timeType when null, actual time type is set
724 * @return a reference to name.
726 UnicodeString
& formatSpecific(const TimeZone
& tz
, UTimeZoneNameType stdType
, UTimeZoneNameType dstType
,
727 UDate date
, UnicodeString
& name
, UTimeZoneFormatTimeType
*timeType
) const;
730 * Returns the time zone's generic format string.
731 * @param tz the time zone
732 * @param genType the generic name type
733 * @param date the date
734 * @param name receives the time zone's generic format name string
735 * @return a reference to name.
737 UnicodeString
& formatGeneric(const TimeZone
& tz
, int32_t genType
, UDate date
, UnicodeString
& name
) const;
740 * Lazily create a TimeZoneGenericNames instance
741 * @param status receives the status
742 * @return the cached TimeZoneGenericNames.
744 const TimeZoneGenericNames
* getTimeZoneGenericNames(UErrorCode
& status
) const;
747 * Lazily create a TZDBTimeZoneNames instance
748 * @param status receives the status
749 * @return the cached TZDBTimeZoneNames.
751 const TZDBTimeZoneNames
* getTZDBTimeZoneNames(UErrorCode
& status
) const;
754 * Private method returning the time zone's exemplar location string.
755 * This method will never return empty.
756 * @param tz the time zone
757 * @param name receives the time zone's exemplar location name
758 * @return a reference to name.
760 UnicodeString
& formatExemplarLocation(const TimeZone
& tz
, UnicodeString
& name
) const;
763 * Private enum specifying a combination of offset fields
772 * Parses the localized GMT pattern string and initialize
773 * localized gmt pattern fields.
774 * @param gmtPattern the localized GMT pattern string such as "GMT {0}"
775 * @param status U_ILLEGAL_ARGUMENT_ERROR is set when the specified pattern does not
776 * contain an argument "{0}".
778 void initGMTPattern(const UnicodeString
& gmtPattern
, UErrorCode
& status
);
781 * Parse the GMT offset pattern into runtime optimized format.
782 * @param pattern the offset pattern string
783 * @param required the required set of fields, such as FIELDS_HM
784 * @param status U_ILLEGAL_ARGUMENT is set when the specified pattern does not contain
785 * pattern letters for the required fields.
786 * @return A list of GMTOffsetField objects, or NULL on error.
788 static UVector
* parseOffsetPattern(const UnicodeString
& pattern
, OffsetFields required
, UErrorCode
& status
);
791 * Appends seconds field to the offset pattern with hour/minute
792 * Note: This code will be obsoleted once we add hour-minute-second pattern data in CLDR.
793 * @param offsetHM the offset pattern including hours and minutes fields
794 * @param result the output offset pattern including hour, minute and seconds fields
795 * @param status receives the status
796 * @return a reference to result
798 static UnicodeString
& expandOffsetPattern(const UnicodeString
& offsetHM
, UnicodeString
& result
, UErrorCode
& status
);
801 * Truncates minutes field to the offset pattern with hour/minute
802 * Note: This code will be obsoleted once we add hour pattern data in CLDR.
803 * @param offsetHM the offset pattern including hours and minutes fields
804 * @param result the output offset pattern including only hours field
805 * @param status receives the status
806 * @return a reference to result
808 static UnicodeString
& truncateOffsetPattern(const UnicodeString
& offsetHM
, UnicodeString
& result
, UErrorCode
& status
);
811 * Break input string into UChar32[]. Each array element represents
812 * a code point. This method is used for parsing localized digit
813 * characters and support characters in Unicode supplemental planes.
814 * @param str the string
815 * @param codeArray receives the result
816 * @param capacity the capacity of codeArray
817 * @return TRUE when the specified code array is fully filled with code points
818 * (no under/overflow).
820 static UBool
toCodePoints(const UnicodeString
& str
, UChar32
* codeArray
, int32_t capacity
);
823 * Private method supprting all of ISO8601 formats
824 * @param offset the offset from GMT(UTC) in milliseconds.
825 * @param useUtcIndicator true if ISO 8601 UTC indicator "Z" is used when the offset is 0.
826 * @param isShort true if shortest form is used.
827 * @param ignoreSeconds true if non-zero offset seconds is appended.
828 * @param result Receives the result
829 * @param status Receives the status
830 * @return the ISO 8601 basic format.
832 UnicodeString
& formatOffsetISO8601(int32_t offset
, UBool isBasic
, UBool useUtcIndicator
,
833 UBool isShort
, UBool ignoreSeconds
, UnicodeString
& result
, UErrorCode
& status
) const;
836 * Private method used for localized GMT formatting.
837 * @param offset the zone's UTC offset
838 * @param isShort true if the short localized GMT format is desired.
839 * @param result receives the localized GMT format string
840 * @param status receives the status
842 UnicodeString
& formatOffsetLocalizedGMT(int32_t offset
, UBool isShort
, UnicodeString
& result
, UErrorCode
& status
) const;
845 * Returns offset from GMT(UTC) in milliseconds for the given ISO 8601 style
846 * (extended format) time zone string. When the given string is not an ISO 8601 time
847 * zone string, this method sets the current position as the error index
848 * to <code>ParsePosition pos</code> and returns 0.
849 * @param text the text contains ISO 8601 style time zone string (e.g. "-08:00", "Z")
851 * @param pos the position, non-negative error index will be set on failure.
852 * @param extendedOnly TRUE if parsing the text as ISO 8601 extended offset format (e.g. "-08:00"),
853 * or FALSE to evaluate the text as basic format.
854 * @param hasDigitOffset receiving if the parsed zone string contains offset digits.
855 * @return the offset from GMT(UTC) in milliseconds for the given ISO 8601 style
858 int32_t parseOffsetISO8601(const UnicodeString
& text
, ParsePosition
& pos
, UBool extendedOnly
,
859 UBool
* hasDigitOffset
= NULL
) const;
862 * Appends localized digits to the buffer.
863 * This code assumes that the input number is 0 - 59
864 * @param buf the target buffer
865 * @param n the integer number
866 * @param minDigits the minimum digits width
868 void appendOffsetDigits(UnicodeString
& buf
, int32_t n
, uint8_t minDigits
) const;
871 * Returns offset from GMT(UTC) in milliseconds for the given localized GMT
872 * offset format string. When the given string cannot be parsed, this method
873 * sets the current position as the error index to <code>ParsePosition pos</code>
875 * @param text the text contains a localized GMT offset string at the position.
876 * @param pos the position, non-negative error index will be set on failure.
877 * @param isShort true if this parser to try the short format first
878 * @param hasDigitOffset receiving if the parsed zone string contains offset digits.
879 * @return the offset from GMT(UTC) in milliseconds for the given localized GMT
880 * offset format string.
882 int32_t parseOffsetLocalizedGMT(const UnicodeString
& text
, ParsePosition
& pos
,
883 UBool isShort
, UBool
* hasDigitOffset
) const;
886 * Parse localized GMT format generated by the patter used by this formatter, except
888 * @param text the input text
889 * @param start the start index
890 * @param isShort true if the short localized format is parsed.
891 * @param parsedLen receives the parsed length
892 * @return the parsed offset in milliseconds
894 int32_t parseOffsetLocalizedGMTPattern(const UnicodeString
& text
, int32_t start
,
895 UBool isShort
, int32_t& parsedLen
) const;
898 * Parses localized GMT offset fields into offset.
899 * @param text the input text
900 * @param start the start index
901 * @param isShort true if this is a short format - currently not used
902 * @param parsedLen the parsed length, or 0 on failure.
903 * @return the parsed offset in milliseconds.
905 int32_t parseOffsetFields(const UnicodeString
& text
, int32_t start
, UBool isShort
, int32_t& parsedLen
) const;
908 * Parse localized GMT offset fields with the given pattern.
909 * @param text the input text
910 * @param start the start index
911 * @param pattenItems the pattern (already itemized)
912 * @param forceSingleHourDigit true if hours field is parsed as a single digit
913 * @param hour receives the hour offset field
914 * @param min receives the minute offset field
915 * @param sec receives the second offset field
916 * @return the parsed length
918 int32_t parseOffsetFieldsWithPattern(const UnicodeString
& text
, int32_t start
,
919 UVector
* patternItems
, UBool forceSingleHourDigit
, int32_t& hour
, int32_t& min
, int32_t& sec
) const;
922 * Parses abutting localized GMT offset fields (such as 0800) into offset.
923 * @param text the input text
924 * @param start the start index
925 * @param parsedLen the parsed length, or 0 on failure
926 * @return the parsed offset in milliseconds.
928 int32_t parseAbuttingOffsetFields(const UnicodeString
& text
, int32_t start
, int32_t& parsedLen
) const;
931 * Parses the input text using the default format patterns (e.g. "UTC{0}").
932 * @param text the input text
933 * @param start the start index
934 * @param parsedLen the parsed length, or 0 on failure
935 * @return the parsed offset in milliseconds.
937 int32_t parseOffsetDefaultLocalizedGMT(const UnicodeString
& text
, int start
, int32_t& parsedLen
) const;
940 * Parses the input GMT offset fields with the default offset pattern.
941 * @param text the input text
942 * @param start the start index
943 * @param separator the separator character, e.g. ':'
944 * @param parsedLen the parsed length, or 0 on failure.
945 * @return the parsed offset in milliseconds.
947 int32_t parseDefaultOffsetFields(const UnicodeString
& text
, int32_t start
, char16_t separator
,
948 int32_t& parsedLen
) const;
951 * Reads an offset field value. This method will stop parsing when
952 * 1) number of digits reaches <code>maxDigits</code>
953 * 2) just before already parsed number exceeds <code>maxVal</code>
955 * @param text the text
956 * @param start the start offset
957 * @param minDigits the minimum number of required digits
958 * @param maxDigits the maximum number of digits
959 * @param minVal the minimum value
960 * @param maxVal the maximum value
961 * @param parsedLen the actual parsed length.
962 * @return the integer value parsed
964 int32_t parseOffsetFieldWithLocalizedDigits(const UnicodeString
& text
, int32_t start
,
965 uint8_t minDigits
, uint8_t maxDigits
, uint16_t minVal
, uint16_t maxVal
, int32_t& parsedLen
) const;
968 * Reads a single decimal digit, either localized digits used by this object
969 * or any Unicode numeric character.
970 * @param text the text
971 * @param start the start index
972 * @param len the actual length read from the text
973 * the start index is not a decimal number.
974 * @return the integer value of the parsed digit, or -1 on failure.
976 int32_t parseSingleLocalizedDigit(const UnicodeString
& text
, int32_t start
, int32_t& len
) const;
979 * Formats offset using ASCII digits. The input offset range must be
980 * within +/-24 hours (exclusive).
981 * @param offset The offset
982 * @param sep The field separator character or 0 if not required
983 * @param minFields The minimum fields
984 * @param maxFields The maximum fields
985 * @return The offset string
987 static UnicodeString
& formatOffsetWithAsciiDigits(int32_t offset
, char16_t sep
,
988 OffsetFields minFields
, OffsetFields maxFields
, UnicodeString
& result
);
991 * Parses offset represented by contiguous ASCII digits.
993 * Note: This method expects the input position is already at the start of
994 * ASCII digits and does not parse sign (+/-).
995 * @param text The text contains a sequence of ASCII digits
996 * @param pos The parse position
997 * @param minFields The minimum Fields to be parsed
998 * @param maxFields The maximum Fields to be parsed
999 * @param fixedHourWidth true if hours field must be width of 2
1000 * @return Parsed offset, 0 or positive number.
1002 static int32_t parseAbuttingAsciiOffsetFields(const UnicodeString
& text
, ParsePosition
& pos
,
1003 OffsetFields minFields
, OffsetFields maxFields
, UBool fixedHourWidth
);
1006 * Parses offset represented by ASCII digits and separators.
1008 * Note: This method expects the input position is already at the start of
1009 * ASCII digits and does not parse sign (+/-).
1010 * @param text The text
1011 * @param pos The parse position
1012 * @param sep The separator character
1013 * @param minFields The minimum Fields to be parsed
1014 * @param maxFields The maximum Fields to be parsed
1015 * @return Parsed offset, 0 or positive number.
1017 static int32_t parseAsciiOffsetFields(const UnicodeString
& text
, ParsePosition
& pos
, char16_t sep
,
1018 OffsetFields minFields
, OffsetFields maxFields
);
1021 * Unquotes the message format style pattern.
1022 * @param pattern the pattern
1023 * @param result receive the unquoted pattern.
1024 * @return A reference to result.
1026 static UnicodeString
& unquote(const UnicodeString
& pattern
, UnicodeString
& result
);
1029 * Initialize localized GMT format offset hour/min/sec patterns.
1030 * This method parses patterns into optimized run-time format.
1031 * @param status receives the status.
1033 void initGMTOffsetPatterns(UErrorCode
& status
);
1036 * Check if there are any GMT format offset patterns without
1037 * any separators between hours field and minutes field and update
1038 * fAbuttingOffsetHoursAndMinutes field. This method must be called
1039 * after all patterns are parsed into pattern items.
1041 void checkAbuttingHoursAndMinutes();
1044 * Creates an instance of TimeZone for the given offset
1045 * @param offset the offset
1046 * @return A TimeZone with the given offset
1048 TimeZone
* createTimeZoneForOffset(int32_t offset
) const;
1051 * Returns the time type for the given name type
1052 * @param nameType the name type
1053 * @return the time type (unknown/standard/daylight)
1055 static UTimeZoneFormatTimeType
getTimeType(UTimeZoneNameType nameType
);
1058 * Returns the time zone ID of a match at the specified index within
1059 * the MatchInfoCollection.
1060 * @param matches the collection of matches
1061 * @param idx the index withing matches
1062 * @param tzID receives the resolved time zone ID
1063 * @return a reference to tzID.
1065 UnicodeString
& getTimeZoneID(const TimeZoneNames::MatchInfoCollection
* matches
, int32_t idx
, UnicodeString
& tzID
) const;
1070 * @param text the text contains a time zone ID string at the position.
1071 * @param pos the position
1072 * @param tzID receives the zone ID
1073 * @return a reference to tzID
1075 UnicodeString
& parseZoneID(const UnicodeString
& text
, ParsePosition
& pos
, UnicodeString
& tzID
) const;
1078 * Parse a short zone ID.
1079 * @param text the text contains a short time zone ID string at the position.
1080 * @param pos the position
1081 * @param tzID receives the short zone ID
1082 * @return a reference to tzID
1084 UnicodeString
& parseShortZoneID(const UnicodeString
& text
, ParsePosition
& pos
, UnicodeString
& tzID
) const;
1087 * Parse an exemplar location string.
1088 * @param text the text contains an exemplar location string at the position.
1089 * @param pos the position.
1090 * @param tzID receives the time zone ID
1091 * @return a reference to tzID
1093 UnicodeString
& parseExemplarLocation(const UnicodeString
& text
, ParsePosition
& pos
, UnicodeString
& tzID
) const;
1098 #endif /* !UCONFIG_NO_FORMATTING */
1100 #endif /* U_SHOW_CPLUSPLUS_API */