TimeZoneFormat
* 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 * @stable ICU 50 */ class U_I18N_API TimeZoneFormat : public Format { public: /** * Copy constructor. * @stable ICU 50 */ TimeZoneFormat(const TimeZoneFormat& other); /** * Destructor. * @stable ICU 50 */ virtual ~TimeZoneFormat(); /** * Assignment operator. * @stable ICU 50 */ 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. * @stable ICU 50 */ 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 * @stable ICU 50 */ virtual TimeZoneFormat* clone() const; /** * Creates an instance of TimeZoneFormat for the given locale. * @param locale The locale. * @param status Receives the status. * @return An instance of TimeZoneFormat for the given locale, * owned by the caller. * @stable ICU 50 */ 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. * @stable ICU 50 */ 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. * @stable ICU 50 */ void adoptTimeZoneNames(TimeZoneNames *tznames); /** * Sets the time zone display name data to this format instnace. * @param tznames TimeZoneNames object to be set. * @stable ICU 50 */ 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 * @stable ICU 50 */ 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 * @stable ICU 50 */ 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 * @stable ICU 50 */ 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 * @stable ICU 50 */ void setGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, const UnicodeString& pattern, UErrorCode& status); /** * Returns the decimal digit characters used for localized GMT format. * The return string contains exactly 10 code points (may include Unicode * supplementary character) representing digit 0 to digit 9 in the ascending * order. * @param digits Receives the decimal digits used for localized GMT format. * @see #setGMTOffsetDigits * @stable ICU 50 */ UnicodeString& getGMTOffsetDigits(UnicodeString& digits) const; /** * Sets the decimal digit characters used for localized GMT format. * The input digits must contain exactly 10 code points * (Unicode supplementary characters are also allowed) representing * digit 0 to digit 9 in the ascending order. When the input digits * does not satisfy the condition, U_ILLEGAL_ARGUMENT_ERROR * will be set to the return status. * @param digits The decimal digits used for localized GMT format. * @param status Receives the status. * @see #getGMTOffsetDigits * @stable ICU 50 */ 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 * @stable ICU 50 */ 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 * @stable ICU 50 */ 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 * @stable ICU 50 */ uint32_t getDefaultParseOptions(void) const; /** * Sets the default parse options. *
digits
U_ILLEGAL_ARGUMENT_ERROR
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 * @stable ICU 50 */ void setDefaultParseOptions(uint32_t flags); /** * Returns the ISO 8601 basic time zone string for the given offset. * For example, "-08", "-0830" and "Z" * * @param offset the offset from GMT(UTC) in milliseconds. * @param useUtcIndicator true if ISO 8601 UTC indicator "Z" is used when the offset is 0. * @param isShort true if shortest form is used. * @param ignoreSeconds true if non-zero offset seconds is appended. * @param result Receives the ISO format string. * @param status Receives the status * @return the ISO 8601 basic format. * @see #formatOffsetISO8601Extended * @see #parseOffsetISO8601 * @stable ICU 51 */ UnicodeString& formatOffsetISO8601Basic(int32_t offset, UBool useUtcIndicator, UBool isShort, UBool ignoreSeconds, UnicodeString& result, UErrorCode& status) const; /** * Returns the ISO 8601 extended time zone string for the given offset. * For example, "-08:00", "-08:30" and "Z" * * @param offset the offset from GMT(UTC) in milliseconds. * @param useUtcIndicator true if ISO 8601 UTC indicator "Z" is used when the offset is 0. * @param isShort true if shortest form is used. * @param ignoreSeconds true if non-zero offset seconds is appended. * @param result Receives the ISO format string. * @param status Receives the status * @return the ISO 8601 basic format. * @see #formatOffsetISO8601Extended * @see #parseOffsetISO8601 * @stable ICU 51 */ UnicodeString& formatOffsetISO8601Extended(int32_t offset, UBool useUtcIndicator, UBool isShort, UBool ignoreSeconds, 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
ParsePosition pos
TimeZone
maxDigits
maxVal
* 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 hours 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 * @return Parsed offset, 0 or positive number. */ static int32_t parseAsciiOffsetFields(const UnicodeString& text, ParsePosition& pos, char16_t sep, OffsetFields minFields, OffsetFields maxFields); /** * 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); /** * Check if there are any GMT format offset patterns without * any separators between hours field and minutes field and update * fAbuttingOffsetHoursAndMinutes field. This method must be called * after all patterns are parsed into pattern items. */ void checkAbuttingHoursAndMinutes(); /** * 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; /** * Parse a zone ID. * @param text the text contains a time zone ID string at the position. * @param pos the position * @param tzID receives the zone ID * @return a reference to tzID */ UnicodeString& parseZoneID(const UnicodeString& text, ParsePosition& pos, UnicodeString& tzID) const; /** * Parse a short zone ID. * @param text the text contains a short time zone ID string at the position. * @param pos the position * @param tzID receives the short zone ID * @return a reference to tzID */ UnicodeString& parseShortZoneID(const UnicodeString& text, ParsePosition& pos, UnicodeString& tzID) const; /** * Parse an exemplar location string. * @param text the text contains an exemplar location string at the position. * @param pos the position. * @param tzID receives the time zone ID * @return a reference to tzID */ UnicodeString& parseExemplarLocation(const UnicodeString& text, ParsePosition& pos, UnicodeString& tzID) const; }; U_NAMESPACE_END #endif /* !UCONFIG_NO_FORMATTING */ #endif /* U_SHOW_CPLUSPLUS_API */ #endif