TimeZoneFormat
supports time zone display name formatting and parsing.
+ * An instance of TimeZoneFormat works as a subformatter of {@link SimpleDateFormat},
+ * but you can also directly get a new instance of TimeZoneFormat
and
+ * formatting/parsing time zone display names.
+ *
+ * ICU implements the time zone display names defined by UTS#35
+ * Unicode Locale Data Markup Language (LDML). {@link TimeZoneNames} represents the
+ * time zone display name data model and this class implements the algorithm for actual
+ * formatting and parsing.
+ *
+ * @see SimpleDateFormat
+ * @see TimeZoneNames
+ * @internal ICU 49 technology preview
+ */
+class U_I18N_API TimeZoneFormat : public Format {
+public:
+ /**
+ * Copy constructor.
+ * @internal ICU 49 technology preview
+ */
+ TimeZoneFormat(const TimeZoneFormat& other);
+
+ /**
+ * Destructor.
+ * @internal ICU 49 technology preview
+ */
+ virtual ~TimeZoneFormat();
+
+ /**
+ * Assignment operator.
+ * @internal ICU 49 technology preview
+ */
+ TimeZoneFormat& operator=(const TimeZoneFormat& other);
+
+ /**
+ * Return true if the given Format objects are semantically equal.
+ * Objects of different subclasses are considered unequal.
+ * @param other The object to be compared with.
+ * @return Return TRUE if the given Format objects are semantically equal.
+ * Objects of different subclasses are considered unequal.
+ * @internal ICU 49 technology preview
+ */
+ virtual UBool operator==(const Format& other) const;
+
+ /**
+ * Clone this object polymorphically. The caller is responsible
+ * for deleting the result when done.
+ * @return A copy of the object
+ * @internal ICU 49 technology preview
+ */
+ virtual Format* clone() const;
+
+ /**
+ * Creates an instance of TimeZoneFormat
for the given locale.
+ * @param locale The locale.
+ * @param status Recevies the status.
+ * @return An instance of TimeZoneFormat
for the given locale,
+ * owned by the caller.
+ * @internal ICU 49 technology preview
+ */
+ static TimeZoneFormat* U_EXPORT2 createInstance(const Locale& locale, UErrorCode& status);
+
+ /**
+ * Returns the time zone display name data used by this instance.
+ * @return The time zone display name data.
+ * @internal ICU 49 technology preview
+ */
+ const TimeZoneNames* getTimeZoneNames() const;
+
+ /**
+ * Sets the time zone display name data to this format instnace.
+ * The caller should not delete the TimeZoenNames object after it is adopted
+ * by this call.
+ * @param tznames TimeZoneNames object to be adopted.
+ * @internal ICU 49 technology preview
+ */
+ void adoptTimeZoneNames(TimeZoneNames *tznames);
+
+ /**
+ * Sets the time zone display name data to this format instnace.
+ * @param tznames TimeZoneNames object to be set.
+ * @internal ICU 49 technology preview
+ */
+ void setTimeZoneNames(const TimeZoneNames &tznames);
+
+ /**
+ * Returns the localized GMT format pattern.
+ * @param pattern Receives the localized GMT format pattern.
+ * @return A reference to the result pattern.
+ * @see #setGMTPattern
+ * @internal ICU 49 technology preview
+ */
+ UnicodeString& getGMTPattern(UnicodeString& pattern) const;
+
+ /**
+ * Sets the localized GMT format pattern. The pattern must contain
+ * a single argument {0}, for example "GMT {0}".
+ * @param pattern The localized GMT format pattern to be used by this object.
+ * @param status Recieves the status.
+ * @see #getGMTPattern
+ * @internal ICU 49 technology preview
+ */
+ void setGMTPattern(const UnicodeString& pattern, UErrorCode& status);
+
+ /**
+ * Returns the offset pattern used for localized GMT format.
+ * @param type The offset pattern type enum.
+ * @param pattern Receives the offset pattern.
+ * @return A reference to the result pattern.
+ * @see #setGMTOffsetPattern
+ * @internal ICU 49 technology preview
+ */
+ UnicodeString& getGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, UnicodeString& pattern) const;
+
+ /**
+ * Sets the offset pattern for the given offset type.
+ * @param type The offset pattern type enum.
+ * @param pattern The offset pattern used for localized GMT format for the type.
+ * @param status Receives the status.
+ * @see #getGMTOffsetPattern
+ * @internal ICU 49 technology preview
+ */
+ void setGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, const UnicodeString& pattern, UErrorCode& status);
+
+ /**
+ * Returns the decimal digit characters used for localized GMT format in a single string
+ * containing from 0 to 9 in the ascending order.
+ * @param digits Receives the decimal digits used for localized GMT format.
+ * @see #setGMTOffsetDigits
+ */
+ UnicodeString& getGMTOffsetDigits(UnicodeString& digits) const;
+
+ /**
+ * Sets the decimal digit characters used for localized GMT format.
+ * @param digits The decimal digits used for localized GMT format.
+ * @param status Receives the status.
+ * @see #getGMTOffsetDigits
+ */
+ void setGMTOffsetDigits(const UnicodeString& digits, UErrorCode& status);
+
+ /**
+ * Returns the localized GMT format string for GMT(UTC) itself (GMT offset is 0).
+ * @param gmtZeroFormat Receives the localized GMT string string for GMT(UTC) itself.
+ * @return A reference to the result GMT string.
+ * @see #setGMTZeroFormat
+ */
+ UnicodeString& getGMTZeroFormat(UnicodeString& gmtZeroFormat) const;
+
+ /**
+ * Sets the localized GMT format string for GMT(UTC) itself (GMT offset is 0).
+ * @param gmtZeroFormat The localized GMT format string for GMT(UTC).
+ * @param status Receives the status.
+ * @see #getGMTZeroFormat
+ */
+ void setGMTZeroFormat(const UnicodeString& gmtZeroFormat, UErrorCode& status);
+
+ /**
+ * Returns the bitwise flags of UTimeZoneFormatParseOption representing the default parse
+ * options used by this object.
+ * @return the default parse options.
+ * @see ParseOption
+ * @internal ICU 49 technology preview
+ */
+ int32_t getDefaultParseOptions(void) const;
+
+ /**
+ * Sets the default parse options.
+ *
Note: By default, an instance of TimeZoneFormat
+ * created by {@link #createInstance} has no parse options set (UTZFMT_PARSE_OPTION_NONE).
+ * To specify multipe options, use bitwise flags of UTimeZoneFormatParseOption.
+ * @see #UTimeZoneFormatParseOption
+ * @internal ICU 49 technology preview
+ */
+ void setDefaultParseOptions(int32_t flags);
+
+ /**
+ * Returns the RFC822 style time zone string for the given offset.
+ * For example, "-0800".
+ * @param offset The offset from GMT(UTC) in milliseconds.
+ * @param result Recevies the RFC822 style GMT(UTC) offset format.
+ * @return A reference to the result.
+ * @see #parseOffsetRFC822
+ * @internal ICU 49 technology preview
+ */
+ UnicodeString& formatOffsetRFC822(int32_t offset, UnicodeString& result, UErrorCode& status) const;
+
+ /**
+ * Returns the ISO 8601 style time zone string for the given offset.
+ * For example, "-08:00" and "Z".
+ * @param offset The offset from GMT(UTC) in milliseconds.
+ * @param result Recevies the ISO 8601 style GMT(UTC) offset format.
+ * @return A reference to the result.
+ * @see #parseOffsetISO8601
+ * @internal ICU 49 technology preview
+ */
+ UnicodeString& formatOffsetISO8601(int32_t offset, UnicodeString& result, UErrorCode& status) const;
+
+ /**
+ * Returns the localized GMT(UTC) offset format for the given offset.
+ * The localized GMT offset is defined by;
+ *
UTZFMT_STYLE_GENERIC_LONG
, UTZFMT_STYLE_LOCALIZED_GMT
...)
+ * @param tz The time zone.
+ * @param date The date.
+ * @param name Receives the display name.
+ * @param timeType the output argument for receiving the time type (standard/daylight/unknown)
+ * used for the display name, or NULL if the information is not necessary.
+ * @return A reference to the result
+ * @see #UTimeZoneFormatStyle
+ * @see #UTimeZoneFormatTimeType
+ * @internal ICU 49 technology preview
+ */
+ virtual UnicodeString& format(UTimeZoneFormatStyle style, const TimeZone& tz, UDate date,
+ UnicodeString& name, UTimeZoneFormatTimeType* timeType = NULL) const;
+
+ /**
+ * Returns offset from GMT(UTC) in milliseconds for the given RFC822
+ * style time zone string. When the given string is not an RFC822 time zone
+ * string, this method sets the current position as the error index
+ * to ParsePosition pos
and returns 0.
+ * @param text The text contains RFC822 style time zone string (e.g. "-0800")
+ * at the position.
+ * @param pos The ParsePosition object.
+ * @return The offset from GMT(UTC) in milliseconds for the given RFC822 style
+ * time zone string.
+ * @see #formatOffsetRFC822
+ * @internal ICU 49 technology preview
+ */
+ int32_t parseOffsetRFC822(const UnicodeString& text, ParsePosition& pos) const;
+
+ /**
+ * Returns offset from GMT(UTC) in milliseconds for the given ISO 8601
+ * style time zone string. When the given string is not an ISO 8601 time zone
+ * string, this method sets the current position as the error index
+ * to ParsePosition pos
and returns 0.
+ * @param text The text contains RFC822 style time zone string (e.g. "-08:00", "Z")
+ * at the position.
+ * @param pos The ParsePosition object.
+ * @return The offset from GMT(UTC) in milliseconds for the given ISO 8601 style
+ * time zone string.
+ * @see #formatOffsetISO8601
+ * @internal ICU 49 technology preview
+ */
+ int32_t parseOffsetISO8601(const UnicodeString& text, ParsePosition& pos) const;
+
+ /**
+ * Returns offset from GMT(UTC) in milliseconds for the given localized GMT
+ * offset format string. When the given string cannot be parsed, this method
+ * sets the current position as the error index to ParsePosition pos
+ * and returns 0.
+ * @param text The text contains a localized GMT offset string at the position.
+ * @param pos The ParsePosition object.
+ * @return The offset from GMT(UTC) in milliseconds for the given localized GMT
+ * offset format string.
+ * @see #formatOffsetLocalizedGMT
+ * @internal ICU 49 technology preview
+ */
+ int32_t parseOffsetLocalizedGMT(const UnicodeString& text, ParsePosition& pos) const;
+
+ /**
+ * Returns a TimeZone
by parsing the time zone string according to
+ * the given parse position, the specified format style and parse options.
+ *
+ * @param text The text contains a time zone string at the position.
+ * @param style The format style
+ * @param pos The position.
+ * @param parseOptions The parse options repesented by bitwise flags of UTimeZoneFormatParseOption.
+ * @param timeType The output argument for receiving the time type (standard/daylight/unknown),
+ * or NULL if the information is not necessary.
+ * @return A TimeZone
, or null if the input could not be parsed.
+ * @see UTimeZoneFormatStyle
+ * @see UTimeZoneFormatParseOption
+ * @see UTimeZoneFormatTimeType
+ * @internal ICU 49 technology preview
+ */
+ virtual TimeZone* parse(UTimeZoneFormatStyle style, const UnicodeString& text, ParsePosition& pos,
+ int32_t parseOptions, UTimeZoneFormatTimeType* timeType = NULL) const;
+
+ /**
+ * Returns a TimeZone
by parsing the time zone string according to
+ * the given parse position, the specified format style and the default parse options.
+ *
+ * @param text The text contains a time zone string at the position.
+ * @param style The format style
+ * @param pos The position.
+ * @param timeType The output argument for receiving the time type (standard/daylight/unknown),
+ * or NULL if the information is not necessary.
+ * @return A TimeZone
, or null if the input could not be parsed.
+ * @see UTimeZoneFormatStyle
+ * @see UTimeZoneFormatParseOption
+ * @see UTimeZoneFormatTimeType
+ * @internal ICU 49 technology preview
+ */
+ TimeZone* parse(UTimeZoneFormatStyle style, const UnicodeString& text, ParsePosition& pos,
+ UTimeZoneFormatTimeType* timeType = NULL) const;
+
+ /* ----------------------------------------------
+ * Format APIs
+ * ---------------------------------------------- */
+
+ /**
+ * Format an object to produce a time zone display string using localized GMT offset format.
+ * This method handles Formattable objects with a TimeZone
. If a the Formattable
+ * object type is not a TimeZone
, then it returns a failing UErrorCode.
+ * @param obj The object to format. Must be a TimeZone
.
+ * @param appendTo Output parameter to receive result. Result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired. On output: the offsets of the alignment field.
+ * @param status Output param filled with success/failure status.
+ * @return Reference to 'appendTo' parameter.
+ * @internal ICU 49 technology preview
+ */
+ virtual UnicodeString& format(const Formattable& obj, UnicodeString& appendTo,
+ FieldPosition& pos, UErrorCode& status) const;
+
+ /**
+ * Parse a string to produce an object. This methods handles parsing of
+ * time zone display strings into Formattable objects with TimeZone
.
+ * @param source The string to be parsed into an object.
+ * @param result Formattable to be set to the parse result. If parse fails, return contents are undefined.
+ * @param parse_pos The position to start parsing at. Upon return this param is set to the position after the
+ * last character successfully parsed. If the source is not parsed successfully, this param
+ * will remain unchanged.
+ * @return A newly created Formattable* object, or NULL on failure. The caller owns this and should
+ * delete it when done.
+ * @internal ICU 49 technology preview
+ */
+ virtual void parseObject(const UnicodeString& source, Formattable& result, ParsePosition& parse_pos) const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ * @internal ICU 49 technology preview
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ * @internal ICU 49 technology preview
+ */
+ virtual UClassID getDynamicClassID() const;
+
+protected:
+ /**
+ * Constructs a TimeZoneFormat object for the specified locale.
+ * @param locale the locale
+ * @param status receives the status.
+ * @internal ICU 49 technology preview
+ */
+ TimeZoneFormat(const Locale& locale, UErrorCode& status);
+
+private:
+ /* mutex */
+ UMTX fLock;
+
+ /* Locale of this object */
+ Locale fLocale;
+
+ /* Stores the region (could be implicit default) */
+ char fTargetRegion[ULOC_COUNTRY_CAPACITY];
+
+ /* TimeZoneNames object used by this formatter */
+ TimeZoneNames* fTimeZoneNames;
+
+ /* TimeZoneGenericNames object used by this formatter - lazily instantiated */
+ TimeZoneGenericNames* fTimeZoneGenericNames;
+
+ /* Localized GMT format pattern - e.g. "GMT{0}" */
+ UnicodeString fGMTPattern;
+
+ /* Array of offset patterns used by Localized GMT format - e.g. "+HH:mm" */
+ UnicodeString fGMTOffsetPatterns[UTZFMT_PAT_NEGATIVE_HMS + 1];
+
+ /* Localized decimal digits used by Localized GMT format */
+ UChar32 fGMTOffsetDigits[10];
+
+ /* Localized GMT zero format - e.g. "GMT" */
+ UnicodeString fGMTZeroFormat;
+
+ /* Bit flags representing parse options */
+ int32_t fDefParseOptionFlags;
+
+ /* Constant parts of GMT format pattern, populated from localized GMT format pattern*/
+ UnicodeString fGMTPatternPrefix; /* Substring before {0} */
+ UnicodeString fGMTPatternSuffix; /* Substring after {0} */
+
+ /* Compiled offset patterns generated from fGMTOffsetPatterns[] */
+ UVector* fGMTOffsetPatternItems[UTZFMT_PAT_NEGATIVE_HMS + 1];
+
+ /**
+ * Returns the time zone's specific format string.
+ * @param tz the time zone
+ * @param stdType the name type used for standard time
+ * @param dstType the name type used for daylight time
+ * @param date the date
+ * @param name receives the time zone's specific format name string
+ * @param timeType when null, actual time type is set
+ * @return a reference to name.
+ */
+ UnicodeString& formatSpecific(const TimeZone& tz, UTimeZoneNameType stdType, UTimeZoneNameType dstType,
+ UDate date, UnicodeString& name, UTimeZoneFormatTimeType *timeType) const;
+
+ /**
+ * Returns the time zone's generic format string.
+ * @param tz the time zone
+ * @param genType the generic name type
+ * @param date the date
+ * @param name receives the time zone's generic format name string
+ * @return a reference to name.
+ */
+ UnicodeString& formatGeneric(const TimeZone& tz, int32_t genType, UDate date, UnicodeString& name) const;
+
+ /**
+ * Lazily create a TimeZoneGenericNames instance
+ * @param status receives the status
+ * @return the cached TimeZoneGenericNames.
+ */
+ const TimeZoneGenericNames* getTimeZoneGenericNames(UErrorCode& status) const;
+
+ /**
+ * Private enum specifying a combination of offset fields
+ */
+ enum OffsetFields {
+ FIELDS_H,
+ FIELDS_HM,
+ FIELDS_HMS
+ };
+
+ /**
+ * Parses the localized GMT pattern string and initialize
+ * localized gmt pattern fields.
+ * @param gmtPattern the localized GMT pattern string such as "GMT {0}"
+ * @param status U_ILLEGAL_ARGUMENT_ERROR is set when the specified pattern does not
+ * contain an argument "{0}".
+ */
+ void initGMTPattern(const UnicodeString& gmtPattern, UErrorCode& status);
+
+ /**
+ * Parse the GMT offset pattern into runtime optimized format.
+ * @param pattern the offset pattern string
+ * @param required the required set of fields, such as FIELDS_HM
+ * @param status U_ILLEGAL_ARGUMENT is set when the specified pattern does not contain
+ * pattern letters for the required fields.
+ * @return A list of GMTOffsetField objects, or NULL on error.
+ */
+ static UVector* parseOffsetPattern(const UnicodeString& pattern, OffsetFields required, UErrorCode& status);
+
+ /**
+ * Appends second field to the offset pattern with hour/minute
+ * Note: This code will be obsoleted once we add hour-minute-second pattern data in CLDR.
+ * @param offsetHM the offset pattern including hour and minute fields
+ * @param result the output offset pattern including hour, minute and second fields
+ * @return a reference to result
+ */
+ static UnicodeString& expandOffsetPattern(const UnicodeString& offsetHM, UnicodeString& result);
+
+ /**
+ * Break input string into UChar32[]. Each array element represents
+ * a code point. This method is used for parsing localized digit
+ * characters and support characters in Unicode supplemental planes.
+ * @param str the string
+ * @param codeArray receives the result
+ * @param capacity the capacity of codeArray
+ * @return TRUE when the specified code array is fully filled with code points
+ * (no under/overflow).
+ */
+ static UBool toCodePoints(const UnicodeString& str, UChar32* codeArray, int32_t capacity);
+
+ /**
+ * Returns offset from GMT(UTC) in milliseconds for the given ISO 8601 style
+ * (extended format) time zone string. When the given string is not an ISO 8601 time
+ * zone string, this method sets the current position as the error index
+ * to ParsePosition pos
and returns 0.
+ * @param text the text contains ISO 8601 style time zone string (e.g. "-08:00", "Z")
+ * at the position.
+ * @param pos the position, non-negative error index will be set on failure.
+ * @param extendedOnly TRUE if parsing the text as ISO 8601 extended offset format (e.g. "-08:00"),
+ * or FALSE to evaluate the text as basic format.
+ * @param hasDigitOffset receiving if the parsed zone string contains offset digits.
+ * @return the offset from GMT(UTC) in milliseconds for the given ISO 8601 style
+ * time zone string.
+ */
+ int32_t parseOffsetISO8601(const UnicodeString& text, ParsePosition& pos, UBool extendedOnly,
+ UBool* hasDigitOffset = NULL) const;
+
+ /**
+ * Appends localized digits to the buffer.
+ * This code assumes that the input number is 0 - 59
+ * @param buf the target buffer
+ * @param n the integer number
+ * @param minDigits the minimum digits width
+ */
+ void appendOffsetDigits(UnicodeString& buf, int32_t n, uint8_t minDigits) const;
+
+ /**
+ * Returns offset from GMT(UTC) in milliseconds for the given localized GMT
+ * offset format string. When the given string cannot be parsed, this method
+ * sets the current position as the error index to ParsePosition pos
+ * and returns 0.
+ * @param text the text contains a localized GMT offset string at the position.
+ * @param pos the position, non-negative error index will be set on failure.
+ * @param hasDigitOffset receiving if the parsed zone string contains offset digits.
+ * @return the offset from GMT(UTC) in milliseconds for the given localized GMT
+ * offset format string.
+ */
+ int32_t parseOffsetLocalizedGMT(const UnicodeString& text, ParsePosition& pos,
+ UBool* hasDigitOffset) const;
+
+ /**
+ * Parses localized GMT offset fields into offset.
+ * @param text the input text
+ * @param start the start index
+ * @param minimumHourWidth true if the parser allows hour field width to be 1
+ * @param parsedLen the parsed length, or 0 on failure.
+ * @return the parsed offset in milliseconds.
+ */
+ int32_t parseOffsetFields(const UnicodeString& text, int32_t start, UBool minimumHourWidth,
+ int32_t& parsedLen) const;
+
+ /**
+ * Parses abutting localized GMT offset fields (such as 0800) into offset.
+ * @param text the input text
+ * @param start the start index
+ * @param parsedLen the parsed length, or 0 on failure
+ * @return the parsed offset in milliseconds.
+ */
+ int32_t parseAbuttingOffsetFields(const UnicodeString& text, int32_t start, int32_t& parsedLen) const;
+
+ /**
+ * Parses the input text using the default format patterns (e.g. "UTC{0}").
+ * @param text the input text
+ * @param start the start index
+ * @param parsedLen the parsed length, or 0 on failure
+ * @return the parsed offset in milliseconds.
+ */
+ int32_t parseOffsetDefaultLocalizedGMT(const UnicodeString& text, int start, int32_t& parsedLen) const;
+
+ /**
+ * Parses the input GMT offset fields with the default offset pattern.
+ * @param text the input text
+ * @param start the start index
+ * @param separator the separator character, e.g. ':'
+ * @param parsedLen the parsed length, or 0 on failure.
+ * @return the parsed offset in milliseconds.
+ */
+ int32_t parseDefaultOffsetFields(const UnicodeString& text, int32_t start, UChar separator,
+ int32_t& parsedLen) const;
+
+ /**
+ * Reads an offset field value. This method will stop parsing when
+ * 1) number of digits reaches maxDigits
+ * 2) just before already parsed number exceeds maxVal
+ *
+ * @param text the text
+ * @param start the start offset
+ * @param minDigits the minimum number of required digits
+ * @param maxDigits the maximum number of digits
+ * @param minVal the minimum value
+ * @param maxVal the maximum value
+ * @param parsedLen the actual parsed length.
+ * @return the integer value parsed
+ */
+ int32_t parseOffsetFieldWithLocalizedDigits(const UnicodeString& text, int32_t start,
+ uint8_t minDigits, uint8_t maxDigits, uint16_t minVal, uint16_t maxVal, int32_t& parsedLen) const;
+
+ /**
+ * Reads a single decimal digit, either localized digits used by this object
+ * or any Unicode numeric character.
+ * @param text the text
+ * @param start the start index
+ * @param len the actual length read from the text
+ * the start index is not a decimal number.
+ * @return the integer value of the parsed digit, or -1 on failure.
+ */
+ int32_t parseSingleLocalizedDigit(const UnicodeString& text, int32_t start, int32_t& len) const;
+
+ /**
+ * Formats offset using ASCII digits. The input offset range must be
+ * within +/-24 hours (exclusive).
+ * @param offset The offset
+ * @param sep The field separator character or 0 if not required
+ * @param minFields The minimum fields
+ * @param maxFields The maximum fields
+ * @return The offset string
+ */
+ static UnicodeString& formatOffsetWithAsciiDigits(int32_t offset, UChar sep,
+ OffsetFields minFields, OffsetFields maxFields, UnicodeString& result);
+
+ /**
+ * Parses offset represented by contiguous ASCII digits.
+ * + * Note: This method expects the input position is already at the start of + * ASCII digits and does not parse sign (+/-). + * @param text The text contains a sequence of ASCII digits + * @param pos The parse position + * @param minFields The minimum Fields to be parsed + * @param maxFields The maximum Fields to be parsed + * @param fixedHourWidth true if hour field must be width of 2 + * @return Parsed offset, 0 or positive number. + */ + static int32_t parseAbuttingAsciiOffsetFields(const UnicodeString& text, ParsePosition& pos, + OffsetFields minFields, OffsetFields maxFields, UBool fixedHourWidth); + + /** + * Parses offset represented by ASCII digits and separators. + *
+ * Note: This method expects the input position is already at the start of
+ * ASCII digits and does not parse sign (+/-).
+ * @param text The text
+ * @param pos The parse position
+ * @param sep The separator character
+ * @param minFields The minimum Fields to be parsed
+ * @param maxFields The maximum Fields to be parsed
+ * @param fixedHourWidth true if hour field must be width of 2
+ * @return Parsed offset, 0 or positive number.
+ */
+ static int32_t parseAsciiOffsetFields(const UnicodeString& text, ParsePosition& pos, UChar sep,
+ OffsetFields minFields, OffsetFields maxFields, UBool fixedHourWidth);
+
+ /**
+ * Unquotes the message format style pattern.
+ * @param pattern the pattern
+ * @param result receive the unquoted pattern.
+ * @return A reference to result.
+ */
+ static UnicodeString& unquote(const UnicodeString& pattern, UnicodeString& result);
+
+ /**
+ * Initialize localized GMT format offset hour/min/sec patterns.
+ * This method parses patterns into optimized run-time format.
+ * @param status receives the status.
+ */
+ void initGMTOffsetPatterns(UErrorCode& status);
+
+ /**
+ * Creates an instance of TimeZone for the given offset
+ * @param offset the offset
+ * @return A TimeZone with the given offset
+ */
+ TimeZone* createTimeZoneForOffset(int32_t offset) const;
+
+ /**
+ * Returns the time type for the given name type
+ * @param nameType the name type
+ * @return the time type (unknown/standard/daylight)
+ */
+ static UTimeZoneFormatTimeType getTimeType(UTimeZoneNameType nameType);
+
+ /*
+ * Returns the time zone ID of a match at the specified index within
+ * the MatchInfoCollection.
+ * @param matches the collection of matches
+ * @param idx the index withing matches
+ * @param tzID receives the resolved time zone ID
+ * @return a reference to tzID.
+ */
+ UnicodeString& getTimeZoneID(const TimeZoneNames::MatchInfoCollection* matches, int32_t idx, UnicodeString& tzID) const;
+};
+
+U_NAMESPACE_END
+
+#endif /* U_HIDE_INTERNAL_API */
+#endif
+#endif
+
diff --git a/icu4c/source/i18n/unicode/tznames.h b/icu4c/source/i18n/unicode/tznames.h
new file mode 100644
index 00000000000..b90df2af275
--- /dev/null
+++ b/icu4c/source/i18n/unicode/tznames.h
@@ -0,0 +1,378 @@
+/*
+*******************************************************************************
+* Copyright (C) 2011-2012, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*/
+#ifndef __TZNAMES_H
+#define __TZNAMES_H
+
+/**
+ * \file
+ * \brief C++ API: TimeZoneNames
+ */
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef U_HIDE_INTERNAL_API
+
+#include "unicode/uloc.h"
+#include "unicode/unistr.h"
+
+U_CDECL_BEGIN
+
+/**
+ * Constants for time zone display name types.
+ * @internal ICU 49 technology preview
+ */
+typedef enum UTimeZoneNameType {
+ /**
+ * Unknown display name type.
+ * @internal ICU 49 technology preview
+ */
+ UTZNM_UNKNOWN = 0x00,
+ /**
+ * Long display name, such as "Eastern Time".
+ * @internal ICU 49 technology preview
+ */
+ UTZNM_LONG_GENERIC = 0x01,
+ /**
+ * Long display name for standard time, such as "Eastern Standard Time".
+ * @internal ICU 49 technology preview
+ */
+ UTZNM_LONG_STANDARD = 0x02,
+ /**
+ * Long display name for daylight saving time, such as "Eastern Daylight Time".
+ * @internal ICU 49 technology preview
+ */
+ UTZNM_LONG_DAYLIGHT = 0x04,
+ /**
+ * Short display name, such as "ET".
+ * @internal ICU 49 technology preview
+ */
+ UTZNM_SHORT_GENERIC = 0x08,
+ /**
+ * Short display name for standard time, such as "EST".
+ * @internal ICU 49 technology preview
+ */
+ UTZNM_SHORT_STANDARD = 0x10,
+ /**
+ * Short display name for daylight saving time, such as "EDT".
+ * @internal ICU 49 technology preview
+ */
+ UTZNM_SHORT_DAYLIGHT = 0x20
+} UTimeZoneNameType;
+
+U_CDECL_END
+
+U_NAMESPACE_BEGIN
+
+class UVector;
+struct MatchInfo;
+
+/**
+ * TimeZoneNames
is an abstract class representing the time zone display name data model defined
+ * by UTS#35 Unicode Locale Data Markup Language (LDML).
+ * The model defines meta zone, which is used for storing a set of display names. A meta zone can be shared
+ * by multiple time zones. Also a time zone may have multiple meta zone historic mappings.
+ *
+ * For example, people in the United States refer the zone used by the east part of North America as "Eastern Time". + * The tz database contains multiple time zones "America/New_York", "America/Detroit", "America/Montreal" and some + * others that belong to "Eastern Time". However, assigning different display names to these time zones does not make + * much sense for most of people. + *
+ * In CLDR (which uses LDML for representing locale data), the display name + * "Eastern Time" is stored as long generic display name of a meta zone identified by the ID "America_Eastern". + * Then, there is another table maintaining the historic mapping to meta zones for each time zone. The time zones in + * the above example ("America/New_York", "America/Detroit"...) are mapped to the meta zone "America_Eastern". + *
+ * Sometimes, a time zone is mapped to a different time zone in the past. For example, "America/Indiana/Knox" + * had been moving "Eastern Time" and "Central Time" back and forth. Therefore, it is necessary that time zone + * to meta zones mapping data are stored by date range. + * + *
Note: + * The methods in this class assume that time zone IDs are already canonicalized. For example, you may not get proper + * result returned by a method with time zone ID "America/Indiana/Indianapolis", because it's not a canonical time zone + * ID (the canonical time zone ID for the time zone is "America/Indianapolis". See + * {@link TimeZone#getCanonicalID(const UnicodeString& id, UnicodeString& canonicalID, UErrorCode& status)} about ICU + * canonical time zone IDs. + * + *
+ * In CLDR, most of time zone display names except location names are provided through meta zones. But a time zone may + * have a specific name that is not shared with other time zones. + * + * For example, time zone "Europe/London" has English long name for standard time "Greenwich Mean Time", which is also + * shared with other time zones. However, the long name for daylight saving time is "British Summer Time", which is only + * used for "Europe/London". + * + *
+ * {@link #getTimeZoneDisplayName} is designed for accessing a name only used by a single time zone.
+ * But is not necessarily mean that a subclass implementation use the same model with CLDR. A subclass implementation
+ * may provide time zone names only through {@link #getTimeZoneDisplayName}, or only through {@link #getMetaZoneDisplayName},
+ * or both.
+ *
+ * @internal ICU 49 technology preview
+ */
+class U_I18N_API TimeZoneNames : public UObject {
+public:
+ /**
+ * Destructor.
+ * @internal ICU 49 technology preview
+ */
+ virtual ~TimeZoneNames();
+
+ /**
+ * Return true if the given TimeZoneNames objects are emantically equal.
+ * @param other the object to be compared with.
+ * @return Return TRUE if the given Format objects are semantically equal.
+ * @internal ICU 49 technology preview
+ */
+ virtual UBool operator==(const TimeZoneNames& other) const = 0;
+
+ /**
+ * Return true if the given TimeZoneNames objects are not semantically
+ * equal.
+ * @param other the object to be compared with.
+ * @return Return TRUE if the given Format objects are not semantically equal.
+ * @internal ICU 49 technology preview
+ */
+ UBool operator!=(const TimeZoneNames& other) const { return !operator==(other); }
+
+ /**
+ * Clone this object polymorphically. The caller is responsible
+ * for deleting the result when done.
+ * @return A copy of the object
+ * @internal ICU 49 technology preview
+ */
+ virtual TimeZoneNames* clone() const = 0;
+
+ /**
+ * Returns an instance of TimeZoneDisplayNames
for the specified locale.
+ *
+ * @param locale The locale.
+ * @param status Recevies the status.
+ * @return An instance of TimeZoneDisplayNames
+ * @internal ICU 49 technology preview
+ */
+ static TimeZoneNames* U_EXPORT2 createInstance(const Locale& locale, UErrorCode& status);
+
+ /**
+ * Returns an enumeration of all available meta zone IDs.
+ * @param status Recevies the status.
+ * @return an enumeration object, owned by the caller.
+ * @internal ICU 49 technology preview
+ */
+ virtual StringEnumeration* getAvailableMetaZoneIDs(UErrorCode& status) const = 0;
+
+ /**
+ * Returns an enumeration of all available meta zone IDs used by the given time zone.
+ * @param tzID The canoical tiem zone ID.
+ * @param status Recevies the status.
+ * @return an enumeration object, owned by the caller.
+ * @internal ICU 49 technology preview
+ */
+ virtual StringEnumeration* getAvailableMetaZoneIDs(const UnicodeString& tzID, UErrorCode& status) const = 0;
+
+ /**
+ * Returns the meta zone ID for the given canonical time zone ID at the given date.
+ * @param tzID The canonical time zone ID.
+ * @param date The date.
+ * @param mzID Receives the meta zone ID for the given time zone ID at the given date. If the time zone does not have a
+ * corresponding meta zone at the given date or the implementation does not support meta zones, "bogus" state
+ * is set.
+ * @return A reference to the result.
+ * @internal ICU 49 technology preview
+ */
+ virtual UnicodeString& getMetaZoneID(const UnicodeString& tzID, UDate date, UnicodeString& mzID) const = 0;
+
+ /**
+ * Returns the reference zone ID for the given meta zone ID for the region.
+ * @param mzID The meta zone ID.
+ * @param region The region.
+ * @param tzID Receives the reference zone ID ("golden zone" in the LDML specification) for the given time zone ID for the
+ * region. If the meta zone is unknown or the implementation does not support meta zones, "bogus" state
+ * is set.
+ * @return A reference to the result.
+ * @internal ICU 49 technology preview
+ */
+ virtual UnicodeString& getReferenceZoneID(const UnicodeString& mzID, const char* region, UnicodeString& tzID) const = 0;
+
+ /**
+ * Returns the display name of the meta zone.
+ * @param mzID The meta zone ID.
+ * @param type The display name type. See {@link #UTimeZoneNameType}.
+ * @param name Receives the display name of the meta zone. When this object does not have a localized display name for the given
+ * meta zone with the specified type or the implementation does not provide any display names associated
+ * with meta zones, "bogus" state is set.
+ * @return A reference to the result.
+ * @internal ICU 49 technology preview
+ */
+ virtual UnicodeString& getMetaZoneDisplayName(const UnicodeString& mzID, UTimeZoneNameType type, UnicodeString& name) const = 0;
+
+ /**
+ * Returns the display name of the time zone. Unlike {@link #getDisplayName},
+ * this method does not get a name from a meta zone used by the time zone.
+ * @param tzID The canonical time zone ID.
+ * @param type The display name type. See {@link #UTimeZoneNameType}.
+ * @param name Receives the display name for the time zone. When this object does not have a localized display name for the given
+ * time zone with the specified type, "bogus" state is set.
+ * @return A reference to the result.
+ * @internal ICU 49 technology preview
+ */
+ virtual UnicodeString& getTimeZoneDisplayName(const UnicodeString& tzID, UTimeZoneNameType type, UnicodeString& name) const = 0;
+
+ /**
+ * Returns the exemplar location name for the given time zone. When this object does not have a localized location
+ * name, the default implementation may still returns a programmatically generated name with the logic described
+ * below.
+ *
+ * Note: This method calls the subclass's {@link #getTimeZoneDisplayName} first. When the
+ * result is bogus, this method calls {@link #getMetaZoneID} to get the meta zone ID mapped from the
+ * time zone, then calls {@link #getMetaZoneDisplayName}.
+ *
+ * @param tzID The canonical time zone ID.
+ * @param type The display name type. See {@link #UTimeZoneNameType}.
+ * @param date The date.
+ * @param name Receives the display name for the time zone at the given date. When this object does not have a localized display
+ * name for the time zone with the specified type and date, "bogus" state is set.
+ * @return A reference to the result.
+ * @internal ICU 49 technology preview
+ */
+ virtual UnicodeString& getDisplayName(const UnicodeString& tzID, UTimeZoneNameType type, UDate date, UnicodeString& name) const;
+
+ /**
+ * MatchInfoCollection
represents a collection of time zone name matches used by
+ * {@link TimeZoneNames#find}.
+ * @internal ICU 49 technology preview
+ */
+ class U_I18N_API MatchInfoCollection : public UMemory {
+ public:
+ /**
+ * Constructor.
+ * @internal ICU 49 technology preview
+ */
+ MatchInfoCollection();
+ /**
+ * Destructor.
+ * @internal ICU 49 technology preview
+ */
+ virtual ~MatchInfoCollection();
+
+ /**
+ * Adds a zone match.
+ * @param nameType The name type.
+ * @param matchLength The match length.
+ * @param tzID The time zone ID.
+ * @param status Receives the status
+ * @internal ICU 49 technology preview
+ */
+ void addZone(UTimeZoneNameType nameType, int32_t matchLength,
+ const UnicodeString& tzID, UErrorCode& status);
+
+ /**
+ * Adds a meata zone match.
+ * @param nameType The name type.
+ * @param matchLength The match length.
+ * @param mzID The metazone ID.
+ * @param status Receives the status
+ * @internal ICU 49 technology preview
+ */
+ void addMetaZone(UTimeZoneNameType nameType, int32_t matchLength,
+ const UnicodeString& mzID, UErrorCode& status);
+
+ /**
+ * Returns the number of entries available in this object.
+ * @return The number of entries.
+ * @internal ICU 49 technology preview
+ */
+ int32_t size() const;
+
+ /**
+ * Returns the time zone name type of a match at the specified index.
+ * @param idx The index
+ * @return The time zone name type. If the specified idx is out of range,
+ * it returns UTZNM_UNKNOWN.
+ * @see UTimeZoneNameType
+ * @internal ICU 49 technology preview
+ */
+ UTimeZoneNameType getNameTypeAt(int32_t idx) const;
+
+ /**
+ * Returns the match length of a match at the specified index.
+ * @param idx The index
+ * @param status Receives the status
+ * @return The match length. If the specified idx is out of range,
+ * it returns 0.
+ * @internal ICU 49 technology preview
+ */
+ int32_t getMatchLengthAt(int32_t idx) const;
+
+ /**
+ * Gets the zone ID of a match at the specified index.
+ * @param idx The index
+ * @param tzID Receives the zone ID.
+ * @return TRUE if the zone ID was set to tzID.
+ * @internal ICU 49 technology preview
+ */
+ UBool getTimeZoneIDAt(int32_t idx, UnicodeString& tzID) const;
+
+ /**
+ * Gets the metazone ID of a match at the specified index.
+ * @param idx The index
+ * @param mzID Receives the metazone ID
+ * @param status Receives the status.
+ * @return TRUE if the meta zone ID was set to mzID.
+ * @internal ICU 49 technology preview
+ */
+ UBool getMetaZoneIDAt(int32_t idx, UnicodeString& mzID) const;
+
+ private:
+ UVector* fMatches; // vector of MatchEntry
+
+ UVector* matches(UErrorCode& status);
+ };
+
+ /**
+ * Finds time zone name prefix matches for the input text at the
+ * given offset and returns a collection of the matches.
+ * @param text The text.
+ * @param start The starting offset within the text.
+ * @param types The set of name types represented by bitwise flags of UTimeZoneNameType enums,
+ * or UTZNM_UNKNOWN for all name types.
+ * @param status Receives the status.
+ * @return A collection of matches (owned by the caller), or NULL if no matches are found.
+ * @see UTimeZoneNameType
+ * @see MatchInfoCollection
+ * @internal ICU 49 technology preview
+ */
+ virtual MatchInfoCollection* find(const UnicodeString& text, int32_t start, uint32_t types, UErrorCode& status) const = 0;
+
+private:
+ // No ICU "poor man's RTTI" for this class nor its subclasses.
+ virtual UClassID getDynamicClassID() const;
+};
+
+U_NAMESPACE_END
+
+#endif /* U_HIDE_INTERNAL_API */
+#endif
+#endif
diff --git a/icu4c/source/i18n/zonemeta.cpp b/icu4c/source/i18n/zonemeta.cpp
index 0d90498cf2e..e244f9c2f82 100644
--- a/icu4c/source/i18n/zonemeta.cpp
+++ b/icu4c/source/i18n/zonemeta.cpp
@@ -1,6 +1,6 @@
/*
*******************************************************************************
-* Copyright (C) 2007-2011, International Business Machines Corporation and *
+* Copyright (C) 2007-2012, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@@ -14,6 +14,7 @@
#include "unicode/timezone.h"
#include "unicode/ustring.h"
#include "unicode/putil.h"
+#include "unicode/simpletz.h"
#include "umutex.h"
#include "uvector.h"
@@ -132,6 +133,8 @@ static const UChar gDefaultFrom[] = {0x31, 0x39, 0x37, 0x30, 0x2D, 0x30, 0x31, 0
static const UChar gDefaultTo[] = {0x39, 0x39, 0x39, 0x39, 0x2D, 0x31, 0x32, 0x2D, 0x33, 0x31,
0x20, 0x32, 0x33, 0x3A, 0x35, 0x39, 0x00}; // "9999-12-31 23:59"
+static const UChar gCustomTzPrefix[] = {0x47, 0x4D, 0x54, 0}; // "GMT"
+
#define ASCII_DIGIT(c) (((c)>=0x30 && (c)<=0x39) ? (c)-0x30 : -1)
/*
@@ -842,6 +845,54 @@ ZoneMeta::findTimeZoneID(const UnicodeString& tzid) {
return TimeZone::findID(tzid);
}
+
+TimeZone*
+ZoneMeta::createCustomTimeZone(int32_t offset) {
+ UBool negative = FALSE;
+ int32_t tmp = offset;
+ if (offset < 0) {
+ negative = TRUE;
+ tmp = -offset;
+ }
+ int32_t hour, min, sec;
+
+ tmp /= 1000;
+ sec = tmp % 60;
+ tmp /= 60;
+ min = tmp % 60;
+ hour = tmp / 60;
+
+ UnicodeString zid;
+ formatCustomID(hour, min, sec, negative, zid);
+ return new SimpleTimeZone(offset, zid);
+}
+
+UnicodeString&
+ZoneMeta::formatCustomID(uint8_t hour, uint8_t min, uint8_t sec, UBool negative, UnicodeString& id) {
+ // Create normalized time zone ID - GMT[+|-]HH:mm[:ss]
+ id.setTo(gCustomTzPrefix, -1);
+ if (hour != 0 || min != 0) {
+ if (negative) {
+ id.append(0x2D); // '-'
+ } else {
+ id.append(0x2B); // '+'
+ }
+ // Always use US-ASCII digits
+ id.append(0x30 + (hour%100)/10);
+ id.append(0x30 + (hour%10));
+ id.append(0x3A); // ':'
+ id.append(0x30 + (min%100)/10);
+ id.append(0x30 + (min%10));
+ if (sec != 0) {
+ id.append(0x3A); // ':'
+ id.append(0x30 + (sec%100)/10);
+ id.append(0x30 + (sec%10));
+ }
+ }
+ return id;
+}
+
+
U_NAMESPACE_END
#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/icu4c/source/i18n/zonemeta.h b/icu4c/source/i18n/zonemeta.h
index 085c2af023d..433957dedb7 100644
--- a/icu4c/source/i18n/zonemeta.h
+++ b/icu4c/source/i18n/zonemeta.h
@@ -1,6 +1,6 @@
/*
*******************************************************************************
-* Copyright (C) 2007-2011, International Business Machines Corporation and *
+* Copyright (C) 2007-2012, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@@ -87,10 +87,18 @@ public:
*/
static const UChar* U_EXPORT2 findMetaZoneID(const UnicodeString& mzid);
+ /**
+ * Creates a custom zone for the offset
+ * @param offset GMT offset in milliseconds
+ * @return A custom TimeZone for the offset with normalized time zone id
+ */
+ static TimeZone* createCustomTimeZone(int32_t offset);
+
private:
ZoneMeta(); // Prevent construction.
static UVector* createMetazoneMappings(const UnicodeString &tzid);
static void initAvailableMetaZoneIDs();
+ static UnicodeString& formatCustomID(uint8_t hour, uint8_t min, uint8_t sec, UBool negative, UnicodeString& id);
};
U_NAMESPACE_END
diff --git a/icu4c/source/test/intltest/dtfmttst.cpp b/icu4c/source/test/intltest/dtfmttst.cpp
index a9361cdb353..a043da8c9cc 100644
--- a/icu4c/source/test/intltest/dtfmttst.cpp
+++ b/icu4c/source/test/intltest/dtfmttst.cpp
@@ -2291,6 +2291,7 @@ void DateFormatTest::TestTimeZoneDisplayName()
const char *fallbackTests[][6] = {
{ "en", "America/Los_Angeles", "2004-01-15T00:00:00Z", "Z", "-0800", "-8:00" },
{ "en", "America/Los_Angeles", "2004-01-15T00:00:00Z", "ZZZZ", "GMT-08:00", "-8:00" },
+ { "en", "America/Los_Angeles", "2004-01-15T00:00:00Z", "ZZZZZ", "-08:00", "-8:00" },
{ "en", "America/Los_Angeles", "2004-01-15T00:00:00Z", "z", "PST", "America/Los_Angeles" },
{ "en", "America/Los_Angeles", "2004-01-15T00:00:00Z", "V", "PST", "America/Los_Angeles" },
{ "en", "America/Los_Angeles", "2004-01-15T00:00:00Z", "zzzz", "Pacific Standard Time", "America/Los_Angeles" },
@@ -3423,8 +3424,10 @@ void DateFormatTest::TestGMTParsing() {
"HH:mm:ss zzzz", "10:20:30 UTC", "10:20:30 +0000", // standalone "UTC"
"ZZZZ HH:mm:ss", "UT 10:20:30", "10:20:30 +0000",
"V HH:mm:ss", "UT+0130 10:20:30", "10:20:30 +0130",
- "V HH:mm:ss", "UTC+0130 10:20:30", NULL, // UTC+0130 is not a supported pattern
+ "V HH:mm:ss", "UTC+0130 10:20:30", "10:20:30 +0130",
"HH mm Z ss", "10 20 GMT-1100 30", "10:20:30 -1100",
+ "HH:mm:ssZZZZZ", "14:25:45Z", "14:25:45 +0000",
+ "HH:mm:ssZZZZZ", "15:00:00-08:00", "15:00:00 -0800",
};
const int32_t DATA_len = sizeof(DATA)/sizeof(DATA[0]);
expectParse(DATA, DATA_len, Locale("en"));
diff --git a/icu4c/source/test/intltest/tzfmttst.cpp b/icu4c/source/test/intltest/tzfmttst.cpp
index 92da28304b2..2fbb62ccd37 100644
--- a/icu4c/source/test/intltest/tzfmttst.cpp
+++ b/icu4c/source/test/intltest/tzfmttst.cpp
@@ -1,6 +1,6 @@
/*
*******************************************************************************
-* Copyright (C) 2007-2011, International Business Machines Corporation and *
+* Copyright (C) 2007-2012, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@@ -20,7 +20,7 @@
#include "unicode/basictz.h"
#include "cstring.h"
-static const char* PATTERNS[] = {"z", "zzzz", "Z", "ZZZZ", "v", "vvvv", "V", "VVVV"};
+static const char* PATTERNS[] = {"z", "zzzz", "Z", "ZZZZ", "ZZZZZ", "v", "vvvv", "V", "VVVV"};
static const int NUM_PATTERNS = sizeof(PATTERNS)/sizeof(const char*);
void
@@ -202,13 +202,18 @@ TimeZoneFormatTest::TestTimeZoneRoundTrip(void) {
} else {
// Check if localized GMT format or RFC format is used.
- int32_t numDigits = 0;
- for (int n = 0; n < tzstr.length(); n++) {
- if (u_isdigit(tzstr.charAt(n))) {
- numDigits++;
+ UBool isOffsetFormat = (*PATTERNS[patidx] == 'Z');
+ if (!isOffsetFormat) {
+ // Check if localized GMT format is used as a fallback of name styles
+ int32_t numDigits = 0;
+ for (int n = 0; n < tzstr.length(); n++) {
+ if (u_isdigit(tzstr.charAt(n))) {
+ numDigits++;
+ }
}
+ isOffsetFormat = (numDigits >= 3);
}
- if (tzstr == localGMTString || numDigits >= 3) {
+ if (isOffsetFormat || tzstr == localGMTString) {
// Localized GMT or RFC: total offset (raw + dst) must be preserved.
int32_t inOffset = inRaw + inDst;
int32_t outOffset = outRaw + outDst;
@@ -260,9 +265,9 @@ public:
UBool REALLY_VERBOSE = FALSE;
// Whether each pattern is ambiguous at DST->STD local time overlap
- UBool AMBIGUOUS_DST_DECESSION[] = { FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE };
+ UBool AMBIGUOUS_DST_DECESSION[] = { FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE };
// Whether each pattern is ambiguous at STD->STD/DST->DST local time overlap
- UBool AMBIGUOUS_NEGATIVE_SHIFT[] = { TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE };
+ UBool AMBIGUOUS_NEGATIVE_SHIFT[] = { TRUE, TRUE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE };
// Workaround for #6338
//UnicodeString BASEPATTERN("yyyy-MM-dd'T'HH:mm:ss.SSS");