2 *******************************************************************************
3 * Copyright (C) 2011-2013, 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
19 #include "unicode/format.h"
20 #include "unicode/timezone.h"
21 #include "unicode/tznames.h"
25 * Constants for time zone display format style used by format/parse APIs
29 typedef enum UTimeZoneFormatStyle {
31 * Generic location format, such as "United States Time (New York)", "Italy Time"
34 UTZFMT_STYLE_GENERIC_LOCATION,
36 * Generic long non-location format, such as "Eastern Time".
39 UTZFMT_STYLE_GENERIC_LONG,
41 * Generic short non-location format, such as "ET".
44 UTZFMT_STYLE_GENERIC_SHORT,
46 * Specific long format, such as "Eastern Standard Time".
49 UTZFMT_STYLE_SPECIFIC_LONG,
51 * Specific short format, such as "EST", "PDT".
54 UTZFMT_STYLE_SPECIFIC_SHORT,
56 * Localized GMT offset format, such as "GMT-05:00", "UTC+0100"
59 UTZFMT_STYLE_LOCALIZED_GMT,
60 #ifndef U_HIDE_DRAFT_API
62 * Short localized GMT offset format, such as "GMT-5", "UTC+1:30"
63 * This style is equivalent to the LDML date format pattern "O".
66 UTZFMT_STYLE_LOCALIZED_GMT_SHORT,
68 * Short ISO 8601 local time difference (basic format) or the UTC indicator.
69 * For example, "-05", "+0530", and "Z"(UTC).
70 * This style is equivalent to the LDML date format pattern "X".
73 UTZFMT_STYLE_ISO_BASIC_SHORT,
75 * Short ISO 8601 locale time difference (basic format).
76 * For example, "-05" and "+0530".
77 * This style is equivalent to the LDML date format pattern "x".
80 UTZFMT_STYLE_ISO_BASIC_LOCAL_SHORT,
82 * Fixed width ISO 8601 local time difference (basic format) or the UTC indicator.
83 * For example, "-0500", "+0530", and "Z"(UTC).
84 * This style is equivalent to the LDML date format pattern "XX".
87 UTZFMT_STYLE_ISO_BASIC_FIXED,
89 * Fixed width ISO 8601 local time difference (basic format).
90 * For example, "-0500" and "+0530".
91 * This style is equivalent to the LDML date format pattern "xx".
94 UTZFMT_STYLE_ISO_BASIC_LOCAL_FIXED,
96 * ISO 8601 local time difference (basic format) with optional seconds field, or the UTC indicator.
97 * For example, "-0500", "+052538", and "Z"(UTC).
98 * This style is equivalent to the LDML date format pattern "XXXX".
101 UTZFMT_STYLE_ISO_BASIC_FULL,
103 * ISO 8601 local time difference (basic format) with optional seconds field.
104 * For example, "-0500" and "+052538".
105 * This style is equivalent to the LDML date format pattern "xxxx".
108 UTZFMT_STYLE_ISO_BASIC_LOCAL_FULL,
110 * Fixed width ISO 8601 local time difference (extended format) or the UTC indicator.
111 * For example, "-05:00", "+05:30", and "Z"(UTC).
112 * This style is equivalent to the LDML date format pattern "XXX".
115 UTZFMT_STYLE_ISO_EXTENDED_FIXED,
117 * Fixed width ISO 8601 local time difference (extended format).
118 * For example, "-05:00" and "+05:30".
119 * This style is equivalent to the LDML date format pattern "xxx" and "ZZZZZ".
122 UTZFMT_STYLE_ISO_EXTENDED_LOCAL_FIXED,
124 * ISO 8601 local time difference (extended format) with optional seconds field, or the UTC indicator.
125 * For example, "-05:00", "+05:25:38", and "Z"(UTC).
126 * This style is equivalent to the LDML date format pattern "XXXXX".
129 UTZFMT_STYLE_ISO_EXTENDED_FULL,
131 * ISO 8601 local time difference (extended format) with optional seconds field.
132 * For example, "-05:00" and "+05:25:38".
133 * This style is equivalent to the LDML date format pattern "xxxxx".
136 UTZFMT_STYLE_ISO_EXTENDED_LOCAL_FULL,
138 * Time Zone ID, such as "America/Los_Angeles".
141 UTZFMT_STYLE_ZONE_ID,
143 * Short Time Zone ID (BCP 47 Unicode location extension, time zone type value), such as "uslax".
146 UTZFMT_STYLE_ZONE_ID_SHORT,
148 * Exemplar location, such as "Los Angeles" and "Paris".
151 UTZFMT_STYLE_EXEMPLAR_LOCATION
152 #endif /* U_HIDE_DRAFT_API */
153 } UTimeZoneFormatStyle;
156 * Constants for GMT offset pattern types.
159 typedef enum UTimeZoneFormatGMTOffsetPatternType {
161 * Positive offset with hours and minutes fields
164 UTZFMT_PAT_POSITIVE_HM,
166 * Positive offset with hours, minutes and seconds fields
169 UTZFMT_PAT_POSITIVE_HMS,
171 * Negative offset with hours and minutes fields
174 UTZFMT_PAT_NEGATIVE_HM,
176 * Negative offset with hours, minutes and seconds fields
179 UTZFMT_PAT_NEGATIVE_HMS,
180 #ifndef U_HIDE_DRAFT_API
182 * Positive offset with hours field
185 UTZFMT_PAT_POSITIVE_H,
187 * Negative offset with hours field
190 UTZFMT_PAT_NEGATIVE_H,
191 #endif /* U_HIDE_DRAFT_API */
194 * Number of UTimeZoneFormatGMTOffsetPatternType types.
198 } UTimeZoneFormatGMTOffsetPatternType;
201 * Constants for time types used by TimeZoneFormat APIs for
202 * receiving time type (standard time, daylight time or unknown).
205 typedef enum UTimeZoneFormatTimeType {
210 UTZFMT_TIME_TYPE_UNKNOWN,
215 UTZFMT_TIME_TYPE_STANDARD,
217 * Daylight saving time
220 UTZFMT_TIME_TYPE_DAYLIGHT
221 } UTimeZoneFormatTimeType;
224 * Constants for parse option flags, used for specifying optional parse behavior.
227 typedef enum UTimeZoneFormatParseOption {
232 UTZFMT_PARSE_OPTION_NONE = 0x00,
234 * When a time zone display name is not found within a set of display names
235 * used for the specified style, look for the name from display names used
239 UTZFMT_PARSE_OPTION_ALL_STYLES = 0x01
240 } UTimeZoneFormatParseOption;
246 class TimeZoneGenericNames;
250 * <code>TimeZoneFormat</code> supports time zone display name formatting and parsing.
251 * An instance of TimeZoneFormat works as a subformatter of {@link SimpleDateFormat},
252 * but you can also directly get a new instance of <code>TimeZoneFormat</code> and
253 * formatting/parsing time zone display names.
255 * ICU implements the time zone display names defined by <a href="http://www.unicode.org/reports/tr35/">UTS#35
256 * Unicode Locale Data Markup Language (LDML)</a>. {@link TimeZoneNames} represents the
257 * time zone display name data model and this class implements the algorithm for actual
258 * formatting and parsing.
260 * @see SimpleDateFormat
264 class U_I18N_API TimeZoneFormat : public Format {
270 TimeZoneFormat(const TimeZoneFormat& other);
276 virtual ~TimeZoneFormat();
279 * Assignment operator.
282 TimeZoneFormat& operator=(const TimeZoneFormat& other);
285 * Return true if the given Format objects are semantically equal.
286 * Objects of different subclasses are considered unequal.
287 * @param other The object to be compared with.
288 * @return Return TRUE if the given Format objects are semantically equal.
289 * Objects of different subclasses are considered unequal.
292 virtual UBool operator==(const Format& other) const;
295 * Clone this object polymorphically. The caller is responsible
296 * for deleting the result when done.
297 * @return A copy of the object
300 virtual Format* clone() const;
303 * Creates an instance of <code>TimeZoneFormat</code> for the given locale.
304 * @param locale The locale.
305 * @param status Recevies the status.
306 * @return An instance of <code>TimeZoneFormat</code> for the given locale,
307 * owned by the caller.
310 static TimeZoneFormat* U_EXPORT2 createInstance(const Locale& locale, UErrorCode& status);
313 * Returns the time zone display name data used by this instance.
314 * @return The time zone display name data.
317 const TimeZoneNames* getTimeZoneNames() const;
320 * Sets the time zone display name data to this format instnace.
321 * The caller should not delete the TimeZoenNames object after it is adopted
323 * @param tznames TimeZoneNames object to be adopted.
326 void adoptTimeZoneNames(TimeZoneNames *tznames);
329 * Sets the time zone display name data to this format instnace.
330 * @param tznames TimeZoneNames object to be set.
333 void setTimeZoneNames(const TimeZoneNames &tznames);
336 * Returns the localized GMT format pattern.
337 * @param pattern Receives the localized GMT format pattern.
338 * @return A reference to the result pattern.
339 * @see #setGMTPattern
342 UnicodeString& getGMTPattern(UnicodeString& pattern) const;
345 * Sets the localized GMT format pattern. The pattern must contain
346 * a single argument {0}, for example "GMT {0}".
347 * @param pattern The localized GMT format pattern to be used by this object.
348 * @param status Recieves the status.
349 * @see #getGMTPattern
352 void setGMTPattern(const UnicodeString& pattern, UErrorCode& status);
355 * Returns the offset pattern used for localized GMT format.
356 * @param type The offset pattern type enum.
357 * @param pattern Receives the offset pattern.
358 * @return A reference to the result pattern.
359 * @see #setGMTOffsetPattern
362 UnicodeString& getGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, UnicodeString& pattern) const;
365 * Sets the offset pattern for the given offset type.
366 * @param type The offset pattern type enum.
367 * @param pattern The offset pattern used for localized GMT format for the type.
368 * @param status Receives the status.
369 * @see #getGMTOffsetPattern
372 void setGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, const UnicodeString& pattern, UErrorCode& status);
375 * Returns the decimal digit characters used for localized GMT format.
376 * The return string contains exactly 10 code points (may include Unicode
377 * supplementary character) representing digit 0 to digit 9 in the ascending
379 * @param digits Receives the decimal digits used for localized GMT format.
380 * @see #setGMTOffsetDigits
383 UnicodeString& getGMTOffsetDigits(UnicodeString& digits) const;
386 * Sets the decimal digit characters used for localized GMT format.
387 * The input <code>digits</code> must contain exactly 10 code points
388 * (Unicode supplementary characters are also allowed) representing
389 * digit 0 to digit 9 in the ascending order. When the input <code>digits</code>
390 * does not satisfy the condition, <code>U_ILLEGAL_ARGUMENT_ERROR</code>
391 * will be set to the return status.
392 * @param digits The decimal digits used for localized GMT format.
393 * @param status Receives the status.
394 * @see #getGMTOffsetDigits
397 void setGMTOffsetDigits(const UnicodeString& digits, UErrorCode& status);
400 * Returns the localized GMT format string for GMT(UTC) itself (GMT offset is 0).
401 * @param gmtZeroFormat Receives the localized GMT string string for GMT(UTC) itself.
402 * @return A reference to the result GMT string.
403 * @see #setGMTZeroFormat
406 UnicodeString& getGMTZeroFormat(UnicodeString& gmtZeroFormat) const;
409 * Sets the localized GMT format string for GMT(UTC) itself (GMT offset is 0).
410 * @param gmtZeroFormat The localized GMT format string for GMT(UTC).
411 * @param status Receives the status.
412 * @see #getGMTZeroFormat
415 void setGMTZeroFormat(const UnicodeString& gmtZeroFormat, UErrorCode& status);
418 * Returns the bitwise flags of UTimeZoneFormatParseOption representing the default parse
419 * options used by this object.
420 * @return the default parse options.
424 uint32_t getDefaultParseOptions(void) const;
427 * Sets the default parse options.
428 * <p><b>Note</b>: By default, an instance of <code>TimeZoneFormat</code>
429 * created by {@link #createInstance} has no parse options set (UTZFMT_PARSE_OPTION_NONE).
430 * To specify multipe options, use bitwise flags of UTimeZoneFormatParseOption.
431 * @see #UTimeZoneFormatParseOption
434 void setDefaultParseOptions(uint32_t flags);
436 #ifndef U_HIDE_DRAFT_API
438 * Returns the ISO 8601 basic time zone string for the given offset.
439 * For example, "-08", "-0830" and "Z"
441 * @param offset the offset from GMT(UTC) in milliseconds.
442 * @param useUtcIndicator true if ISO 8601 UTC indicator "Z" is used when the offset is 0.
443 * @param isShort true if shortest form is used.
444 * @param ignoreSeconds true if non-zero offset seconds is appended.
445 * @param result Receives the ISO format string.
446 * @param status Receives the status
447 * @return the ISO 8601 basic format.
448 * @see #formatOffsetISO8601Extended
449 * @see #parseOffsetISO8601
452 UnicodeString& formatOffsetISO8601Basic(int32_t offset, UBool useUtcIndicator, UBool isShort, UBool ignoreSeconds,
453 UnicodeString& result, UErrorCode& status) const;
456 * Returns the ISO 8601 extended time zone string for the given offset.
457 * For example, "-08:00", "-08:30" and "Z"
459 * @param offset the offset from GMT(UTC) in milliseconds.
460 * @param useUtcIndicator true if ISO 8601 UTC indicator "Z" is used when the offset is 0.
461 * @param isShort true if shortest form is used.
462 * @param ignoreSeconds true if non-zero offset seconds is appended.
463 * @param result Receives the ISO format string.
464 * @param status Receives the status
465 * @return the ISO 8601 basic format.
466 * @see #formatOffsetISO8601Extended
467 * @see #parseOffsetISO8601
470 UnicodeString& formatOffsetISO8601Extended(int32_t offset, UBool useUtcIndicator, UBool isShort, UBool ignoreSeconds,
471 UnicodeString& result, UErrorCode& status) const;
472 #endif /* U_HIDE_DRAFT_API */
475 * Returns the localized GMT(UTC) offset format for the given offset.
476 * The localized GMT offset is defined by;
478 * <li>GMT format pattern (e.g. "GMT {0}" - see {@link #getGMTPattern})
479 * <li>Offset time pattern (e.g. "+HH:mm" - see {@link #getGMTOffsetPattern})
480 * <li>Offset digits (e.g. "0123456789" - see {@link #getGMTOffsetDigits})
481 * <li>GMT zero format (e.g. "GMT" - see {@link #getGMTZeroFormat})
483 * This format always uses 2 digit hours and minutes. When the given offset has non-zero
484 * seconds, 2 digit seconds field will be appended. For example,
485 * GMT+05:00 and GMT+05:28:06.
486 * @param offset the offset from GMT(UTC) in milliseconds.
487 * @param status Receives the status
488 * @param result Receives the localized GMT format string.
489 * @return A reference to the result.
490 * @see #parseOffsetLocalizedGMT
493 UnicodeString& formatOffsetLocalizedGMT(int32_t offset, UnicodeString& result, UErrorCode& status) const;
495 #ifndef U_HIDE_DRAFT_API
497 * Returns the short localized GMT(UTC) offset format for the given offset.
498 * The short localized GMT offset is defined by;
500 * <li>GMT format pattern (e.g. "GMT {0}" - see {@link #getGMTPattern})
501 * <li>Offset time pattern (e.g. "+HH:mm" - see {@link #getGMTOffsetPattern})
502 * <li>Offset digits (e.g. "0123456789" - see {@link #getGMTOffsetDigits})
503 * <li>GMT zero format (e.g. "GMT" - see {@link #getGMTZeroFormat})
505 * This format uses the shortest representation of offset. The hours field does not
506 * have leading zero and lower fields with zero will be truncated. For example,
508 * @param offset the offset from GMT(UTC) in milliseconds.
509 * @param status Receives the status
510 * @param result Receives the short localized GMT format string.
511 * @return A reference to the result.
512 * @see #parseOffsetShortLocalizedGMT
515 UnicodeString& formatOffsetShortLocalizedGMT(int32_t offset, UnicodeString& result, UErrorCode& status) const;
516 #endif /* U_HIDE_DRAFT_API */
518 using Format::format;
521 * Returns the display name of the time zone at the given date for the style.
522 * @param style The style (e.g. <code>UTZFMT_STYLE_GENERIC_LONG</code>, <code>UTZFMT_STYLE_LOCALIZED_GMT</code>...)
523 * @param tz The time zone.
524 * @param date The date.
525 * @param name Receives the display name.
526 * @param timeType the output argument for receiving the time type (standard/daylight/unknown)
527 * used for the display name, or NULL if the information is not necessary.
528 * @return A reference to the result
529 * @see #UTimeZoneFormatStyle
530 * @see #UTimeZoneFormatTimeType
533 virtual UnicodeString& format(UTimeZoneFormatStyle style, const TimeZone& tz, UDate date,
534 UnicodeString& name, UTimeZoneFormatTimeType* timeType = NULL) const;
537 * Returns offset from GMT(UTC) in milliseconds for the given ISO 8601
538 * style time zone string. When the given string is not an ISO 8601 time zone
539 * string, this method sets the current position as the error index
540 * to <code>ParsePosition pos</code> and returns 0.
541 * @param text The text contains ISO8601 style time zone string (e.g. "-08:00", "Z")
543 * @param pos The ParsePosition object.
544 * @return The offset from GMT(UTC) in milliseconds for the given ISO 8601 style
546 * @see #formatOffsetISO8601Basic
547 * @see #formatOffsetISO8601Extended
550 int32_t parseOffsetISO8601(const UnicodeString& text, ParsePosition& pos) const;
553 * Returns offset from GMT(UTC) in milliseconds for the given localized GMT
554 * offset format string. When the given string cannot be parsed, this method
555 * sets the current position as the error index to <code>ParsePosition pos</code>
557 * @param text The text contains a localized GMT offset string at the position.
558 * @param pos The ParsePosition object.
559 * @return The offset from GMT(UTC) in milliseconds for the given localized GMT
560 * offset format string.
561 * @see #formatOffsetLocalizedGMT
564 int32_t parseOffsetLocalizedGMT(const UnicodeString& text, ParsePosition& pos) const;
566 #ifndef U_HIDE_DRAFT_API
568 * Returns offset from GMT(UTC) in milliseconds for the given short localized GMT
569 * offset format string. When the given string cannot be parsed, this method
570 * sets the current position as the error index to <code>ParsePosition pos</code>
572 * @param text The text contains a short localized GMT offset string at the position.
573 * @param pos The ParsePosition object.
574 * @return The offset from GMT(UTC) in milliseconds for the given short localized GMT
575 * offset format string.
576 * @see #formatOffsetShortLocalizedGMT
579 int32_t parseOffsetShortLocalizedGMT(const UnicodeString& text, ParsePosition& pos) const;
580 #endif /* U_HIDE_DRAFT_API */
583 * Returns a <code>TimeZone</code> by parsing the time zone string according to
584 * the given parse position, the specified format style and parse options.
586 * @param text The text contains a time zone string at the position.
587 * @param style The format style
588 * @param pos The position.
589 * @param parseOptions The parse options repesented by bitwise flags of UTimeZoneFormatParseOption.
590 * @param timeType The output argument for receiving the time type (standard/daylight/unknown),
591 * or NULL if the information is not necessary.
592 * @return A <code>TimeZone</code>, or null if the input could not be parsed.
593 * @see UTimeZoneFormatStyle
594 * @see UTimeZoneFormatParseOption
595 * @see UTimeZoneFormatTimeType
598 virtual TimeZone* parse(UTimeZoneFormatStyle style, const UnicodeString& text, ParsePosition& pos,
599 int32_t parseOptions, UTimeZoneFormatTimeType* timeType = NULL) const;
602 * Returns a <code>TimeZone</code> by parsing the time zone string according to
603 * the given parse position, the specified format style and the default parse options.
605 * @param text The text contains a time zone string at the position.
606 * @param style The format style
607 * @param pos The position.
608 * @param timeType The output argument for receiving the time type (standard/daylight/unknown),
609 * or NULL if the information is not necessary.
610 * @return A <code>TimeZone</code>, or null if the input could not be parsed.
611 * @see UTimeZoneFormatStyle
612 * @see UTimeZoneFormatParseOption
613 * @see UTimeZoneFormatTimeType
616 TimeZone* parse(UTimeZoneFormatStyle style, const UnicodeString& text, ParsePosition& pos,
617 UTimeZoneFormatTimeType* timeType = NULL) const;
619 /* ----------------------------------------------
621 * ---------------------------------------------- */
624 * Format an object to produce a time zone display string using localized GMT offset format.
625 * This method handles Formattable objects with a <code>TimeZone</code>. If a the Formattable
626 * object type is not a <code>TimeZone</code>, then it returns a failing UErrorCode.
627 * @param obj The object to format. Must be a <code>TimeZone</code>.
628 * @param appendTo Output parameter to receive result. Result is appended to existing contents.
629 * @param pos On input: an alignment field, if desired. On output: the offsets of the alignment field.
630 * @param status Output param filled with success/failure status.
631 * @return Reference to 'appendTo' parameter.
634 virtual UnicodeString& format(const Formattable& obj, UnicodeString& appendTo,
635 FieldPosition& pos, UErrorCode& status) const;
638 * Parse a string to produce an object. This methods handles parsing of
639 * time zone display strings into Formattable objects with <code>TimeZone</code>.
640 * @param source The string to be parsed into an object.
641 * @param result Formattable to be set to the parse result. If parse fails, return contents are undefined.
642 * @param parse_pos The position to start parsing at. Upon return this param is set to the position after the
643 * last character successfully parsed. If the source is not parsed successfully, this param
644 * will remain unchanged.
645 * @return A newly created Formattable* object, or NULL on failure. The caller owns this and should
646 * delete it when done.
649 virtual void parseObject(const UnicodeString& source, Formattable& result, ParsePosition& parse_pos) const;
652 * ICU "poor man's RTTI", returns a UClassID for this class.
655 static UClassID U_EXPORT2 getStaticClassID(void);
658 * ICU "poor man's RTTI", returns a UClassID for the actual class.
661 virtual UClassID getDynamicClassID() const;
665 * Constructs a TimeZoneFormat object for the specified locale.
666 * @param locale the locale
667 * @param status receives the status.
670 TimeZoneFormat(const Locale& locale, UErrorCode& status);
673 /* Locale of this object */
676 /* Stores the region (could be implicit default) */
677 char fTargetRegion[ULOC_COUNTRY_CAPACITY];
679 /* TimeZoneNames object used by this formatter */
680 TimeZoneNames* fTimeZoneNames;
682 /* TimeZoneGenericNames object used by this formatter - lazily instantiated */
683 TimeZoneGenericNames* fTimeZoneGenericNames;
685 /* Localized GMT format pattern - e.g. "GMT{0}" */
686 UnicodeString fGMTPattern;
688 /* Array of offset patterns used by Localized GMT format - e.g. "+HH:mm" */
689 UnicodeString fGMTOffsetPatterns[UTZFMT_PAT_COUNT];
691 /* Localized decimal digits used by Localized GMT format */
692 UChar32 fGMTOffsetDigits[10];
694 /* Localized GMT zero format - e.g. "GMT" */
695 UnicodeString fGMTZeroFormat;
697 /* Bit flags representing parse options */
698 uint32_t fDefParseOptionFlags;
700 /* Constant parts of GMT format pattern, populated from localized GMT format pattern*/
701 UnicodeString fGMTPatternPrefix; /* Substring before {0} */
702 UnicodeString fGMTPatternSuffix; /* Substring after {0} */
704 /* Compiled offset patterns generated from fGMTOffsetPatterns[] */
705 UVector* fGMTOffsetPatternItems[UTZFMT_PAT_COUNT];
707 UBool fAbuttingOffsetHoursAndMinutes;
710 * Returns the time zone's specific format string.
711 * @param tz the time zone
712 * @param stdType the name type used for standard time
713 * @param dstType the name type used for daylight time
714 * @param date the date
715 * @param name receives the time zone's specific format name string
716 * @param timeType when null, actual time type is set
717 * @return a reference to name.
719 UnicodeString& formatSpecific(const TimeZone& tz, UTimeZoneNameType stdType, UTimeZoneNameType dstType,
720 UDate date, UnicodeString& name, UTimeZoneFormatTimeType *timeType) const;
723 * Returns the time zone's generic format string.
724 * @param tz the time zone
725 * @param genType the generic name type
726 * @param date the date
727 * @param name receives the time zone's generic format name string
728 * @return a reference to name.
730 UnicodeString& formatGeneric(const TimeZone& tz, int32_t genType, UDate date, UnicodeString& name) const;
733 * Lazily create a TimeZoneGenericNames instance
734 * @param status receives the status
735 * @return the cached TimeZoneGenericNames.
737 const TimeZoneGenericNames* getTimeZoneGenericNames(UErrorCode& status) const;
740 * Private method returning the time zone's exemplar location string.
741 * This method will never return empty.
742 * @param tz the time zone
743 * @param name receives the time zone's exemplar location name
744 * @return a reference to name.
746 UnicodeString& formatExemplarLocation(const TimeZone& tz, UnicodeString& name) const;
749 * Private enum specifying a combination of offset fields
758 * Parses the localized GMT pattern string and initialize
759 * localized gmt pattern fields.
760 * @param gmtPattern the localized GMT pattern string such as "GMT {0}"
761 * @param status U_ILLEGAL_ARGUMENT_ERROR is set when the specified pattern does not
762 * contain an argument "{0}".
764 void initGMTPattern(const UnicodeString& gmtPattern, UErrorCode& status);
767 * Parse the GMT offset pattern into runtime optimized format.
768 * @param pattern the offset pattern string
769 * @param required the required set of fields, such as FIELDS_HM
770 * @param status U_ILLEGAL_ARGUMENT is set when the specified pattern does not contain
771 * pattern letters for the required fields.
772 * @return A list of GMTOffsetField objects, or NULL on error.
774 static UVector* parseOffsetPattern(const UnicodeString& pattern, OffsetFields required, UErrorCode& status);
777 * Appends seconds field to the offset pattern with hour/minute
778 * Note: This code will be obsoleted once we add hour-minute-second pattern data in CLDR.
779 * @param offsetHM the offset pattern including hours and minutes fields
780 * @param result the output offset pattern including hour, minute and seconds fields
781 * @param status receives the status
782 * @return a reference to result
784 static UnicodeString& expandOffsetPattern(const UnicodeString& offsetHM, UnicodeString& result, UErrorCode& status);
787 * Truncates minutes field to the offset pattern with hour/minute
788 * Note: This code will be obsoleted once we add hour pattern data in CLDR.
789 * @param offsetHM the offset pattern including hours and minutes fields
790 * @param result the output offset pattern including only hours field
791 * @param status receives the status
792 * @return a reference to result
794 static UnicodeString& truncateOffsetPattern(const UnicodeString& offsetHM, UnicodeString& result, UErrorCode& status);
797 * Break input string into UChar32[]. Each array element represents
798 * a code point. This method is used for parsing localized digit
799 * characters and support characters in Unicode supplemental planes.
800 * @param str the string
801 * @param codeArray receives the result
802 * @param capacity the capacity of codeArray
803 * @return TRUE when the specified code array is fully filled with code points
804 * (no under/overflow).
806 static UBool toCodePoints(const UnicodeString& str, UChar32* codeArray, int32_t capacity);
809 * Private method supprting all of ISO8601 formats
810 * @param offset the offset from GMT(UTC) in milliseconds.
811 * @param useUtcIndicator true if ISO 8601 UTC indicator "Z" is used when the offset is 0.
812 * @param isShort true if shortest form is used.
813 * @param ignoreSeconds true if non-zero offset seconds is appended.
814 * @param result Receives the result
815 * @param status Receives the status
816 * @return the ISO 8601 basic format.
818 UnicodeString& formatOffsetISO8601(int32_t offset, UBool isBasic, UBool useUtcIndicator,
819 UBool isShort, UBool ignoreSeconds, UnicodeString& result, UErrorCode& status) const;
822 * Private method used for localized GMT formatting.
823 * @param offset the zone's UTC offset
824 * @param isShort true if the short localized GMT format is desired.
825 * @param result receives the localized GMT format string
826 * @param status receives the status
828 UnicodeString& formatOffsetLocalizedGMT(int32_t offset, UBool isShort, UnicodeString& result, UErrorCode& status) const;
831 * Returns offset from GMT(UTC) in milliseconds for the given ISO 8601 style
832 * (extended format) time zone string. When the given string is not an ISO 8601 time
833 * zone string, this method sets the current position as the error index
834 * to <code>ParsePosition pos</code> and returns 0.
835 * @param text the text contains ISO 8601 style time zone string (e.g. "-08:00", "Z")
837 * @param pos the position, non-negative error index will be set on failure.
838 * @param extendedOnly TRUE if parsing the text as ISO 8601 extended offset format (e.g. "-08:00"),
839 * or FALSE to evaluate the text as basic format.
840 * @param hasDigitOffset receiving if the parsed zone string contains offset digits.
841 * @return the offset from GMT(UTC) in milliseconds for the given ISO 8601 style
844 int32_t parseOffsetISO8601(const UnicodeString& text, ParsePosition& pos, UBool extendedOnly,
845 UBool* hasDigitOffset = NULL) const;
848 * Appends localized digits to the buffer.
849 * This code assumes that the input number is 0 - 59
850 * @param buf the target buffer
851 * @param n the integer number
852 * @param minDigits the minimum digits width
854 void appendOffsetDigits(UnicodeString& buf, int32_t n, uint8_t minDigits) const;
857 * Returns offset from GMT(UTC) in milliseconds for the given localized GMT
858 * offset format string. When the given string cannot be parsed, this method
859 * sets the current position as the error index to <code>ParsePosition pos</code>
861 * @param text the text contains a localized GMT offset string at the position.
862 * @param pos the position, non-negative error index will be set on failure.
863 * @param isShort true if this parser to try the short format first
864 * @param hasDigitOffset receiving if the parsed zone string contains offset digits.
865 * @return the offset from GMT(UTC) in milliseconds for the given localized GMT
866 * offset format string.
868 int32_t parseOffsetLocalizedGMT(const UnicodeString& text, ParsePosition& pos,
869 UBool isShort, UBool* hasDigitOffset) const;
872 * Parse localized GMT format generated by the patter used by this formatter, except
874 * @param text the input text
875 * @param start the start index
876 * @param isShort true if the short localized format is parsed.
877 * @param parsedLen receives the parsed length
878 * @return the parsed offset in milliseconds
880 int32_t parseOffsetLocalizedGMTPattern(const UnicodeString& text, int32_t start,
881 UBool isShort, int32_t& parsedLen) const;
884 * Parses localized GMT offset fields into offset.
885 * @param text the input text
886 * @param start the start index
887 * @param isShort true if this is a short format - currently not used
888 * @param parsedLen the parsed length, or 0 on failure.
889 * @return the parsed offset in milliseconds.
891 int32_t parseOffsetFields(const UnicodeString& text, int32_t start, UBool isShort, int32_t& parsedLen) const;
894 * Parse localized GMT offset fields with the given pattern.
895 * @param text the input text
896 * @param start the start index
897 * @param pattenItems the pattern (already itemized)
898 * @param forceSingleHourDigit true if hours field is parsed as a single digit
899 * @param hour receives the hour offset field
900 * @param min receives the minute offset field
901 * @param sec receives the second offset field
902 * @return the parsed length
904 int32_t parseOffsetFieldsWithPattern(const UnicodeString& text, int32_t start,
905 UVector* patternItems, UBool forceSingleHourDigit, int32_t& hour, int32_t& min, int32_t& sec) const;
908 * Parses abutting localized GMT offset fields (such as 0800) into offset.
909 * @param text the input text
910 * @param start the start index
911 * @param parsedLen the parsed length, or 0 on failure
912 * @return the parsed offset in milliseconds.
914 int32_t parseAbuttingOffsetFields(const UnicodeString& text, int32_t start, int32_t& parsedLen) const;
917 * Parses the input text using the default format patterns (e.g. "UTC{0}").
918 * @param text the input text
919 * @param start the start index
920 * @param parsedLen the parsed length, or 0 on failure
921 * @return the parsed offset in milliseconds.
923 int32_t parseOffsetDefaultLocalizedGMT(const UnicodeString& text, int start, int32_t& parsedLen) const;
926 * Parses the input GMT offset fields with the default offset pattern.
927 * @param text the input text
928 * @param start the start index
929 * @param separator the separator character, e.g. ':'
930 * @param parsedLen the parsed length, or 0 on failure.
931 * @return the parsed offset in milliseconds.
933 int32_t parseDefaultOffsetFields(const UnicodeString& text, int32_t start, UChar separator,
934 int32_t& parsedLen) const;
937 * Reads an offset field value. This method will stop parsing when
938 * 1) number of digits reaches <code>maxDigits</code>
939 * 2) just before already parsed number exceeds <code>maxVal</code>
941 * @param text the text
942 * @param start the start offset
943 * @param minDigits the minimum number of required digits
944 * @param maxDigits the maximum number of digits
945 * @param minVal the minimum value
946 * @param maxVal the maximum value
947 * @param parsedLen the actual parsed length.
948 * @return the integer value parsed
950 int32_t parseOffsetFieldWithLocalizedDigits(const UnicodeString& text, int32_t start,
951 uint8_t minDigits, uint8_t maxDigits, uint16_t minVal, uint16_t maxVal, int32_t& parsedLen) const;
954 * Reads a single decimal digit, either localized digits used by this object
955 * or any Unicode numeric character.
956 * @param text the text
957 * @param start the start index
958 * @param len the actual length read from the text
959 * the start index is not a decimal number.
960 * @return the integer value of the parsed digit, or -1 on failure.
962 int32_t parseSingleLocalizedDigit(const UnicodeString& text, int32_t start, int32_t& len) const;
965 * Formats offset using ASCII digits. The input offset range must be
966 * within +/-24 hours (exclusive).
967 * @param offset The offset
968 * @param sep The field separator character or 0 if not required
969 * @param minFields The minimum fields
970 * @param maxFields The maximum fields
971 * @return The offset string
973 static UnicodeString& formatOffsetWithAsciiDigits(int32_t offset, UChar sep,
974 OffsetFields minFields, OffsetFields maxFields, UnicodeString& result);
977 * Parses offset represented by contiguous ASCII digits.
979 * Note: This method expects the input position is already at the start of
980 * ASCII digits and does not parse sign (+/-).
981 * @param text The text contains a sequence of ASCII digits
982 * @param pos The parse position
983 * @param minFields The minimum Fields to be parsed
984 * @param maxFields The maximum Fields to be parsed
985 * @param fixedHourWidth true if hours field must be width of 2
986 * @return Parsed offset, 0 or positive number.
988 static int32_t parseAbuttingAsciiOffsetFields(const UnicodeString& text, ParsePosition& pos,
989 OffsetFields minFields, OffsetFields maxFields, UBool fixedHourWidth);
992 * Parses offset represented by ASCII digits and separators.
994 * Note: This method expects the input position is already at the start of
995 * ASCII digits and does not parse sign (+/-).
996 * @param text The text
997 * @param pos The parse position
998 * @param sep The separator character
999 * @param minFields The minimum Fields to be parsed
1000 * @param maxFields The maximum Fields to be parsed
1001 * @return Parsed offset, 0 or positive number.
1003 static int32_t parseAsciiOffsetFields(const UnicodeString& text, ParsePosition& pos, UChar sep,
1004 OffsetFields minFields, OffsetFields maxFields);
1007 * Unquotes the message format style pattern.
1008 * @param pattern the pattern
1009 * @param result receive the unquoted pattern.
1010 * @return A reference to result.
1012 static UnicodeString& unquote(const UnicodeString& pattern, UnicodeString& result);
1015 * Initialize localized GMT format offset hour/min/sec patterns.
1016 * This method parses patterns into optimized run-time format.
1017 * @param status receives the status.
1019 void initGMTOffsetPatterns(UErrorCode& status);
1022 * Check if there are any GMT format offset patterns without
1023 * any separators between hours field and minutes field and update
1024 * fAbuttingOffsetHoursAndMinutes field. This method must be called
1025 * after all patterns are parsed into pattern items.
1027 void checkAbuttingHoursAndMinutes();
1030 * Creates an instance of TimeZone for the given offset
1031 * @param offset the offset
1032 * @return A TimeZone with the given offset
1034 TimeZone* createTimeZoneForOffset(int32_t offset) const;
1037 * Returns the time type for the given name type
1038 * @param nameType the name type
1039 * @return the time type (unknown/standard/daylight)
1041 static UTimeZoneFormatTimeType getTimeType(UTimeZoneNameType nameType);
1044 * Returns the time zone ID of a match at the specified index within
1045 * the MatchInfoCollection.
1046 * @param matches the collection of matches
1047 * @param idx the index withing matches
1048 * @param tzID receives the resolved time zone ID
1049 * @return a reference to tzID.
1051 UnicodeString& getTimeZoneID(const TimeZoneNames::MatchInfoCollection* matches, int32_t idx, UnicodeString& tzID) const;
1056 * @param text the text contains a time zone ID string at the position.
1057 * @param pos the position
1058 * @param tzID receives the zone ID
1059 * @return a reference to tzID
1061 UnicodeString& parseZoneID(const UnicodeString& text, ParsePosition& pos, UnicodeString& tzID) const;
1064 * Parse a short zone ID.
1065 * @param text the text contains a short time zone ID string at the position.
1066 * @param pos the position
1067 * @param tzID receives the short zone ID
1068 * @return a reference to tzID
1070 UnicodeString& parseShortZoneID(const UnicodeString& text, ParsePosition& pos, UnicodeString& tzID) const;
1073 * Parse an exemplar location string.
1074 * @param text the text contains an exemplar location string at the position.
1075 * @param pos the position.
1076 * @param tzID receives the time zone ID
1077 * @return a reference to tzID
1079 UnicodeString& parseExemplarLocation(const UnicodeString& text, ParsePosition& pos, UnicodeString& tzID) const;
1084 #endif /* !UCONFIG_NO_FORMATTING */