Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/unicode/tzfmt.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // © 2016 and later: Unicode, Inc. and others.
0002 // License & terms of use: http://www.unicode.org/copyright.html
0003 /*
0004 *******************************************************************************
0005 * Copyright (C) 2011-2015, International Business Machines Corporation and
0006 * others. All Rights Reserved.
0007 *******************************************************************************
0008 */
0009 #ifndef __TZFMT_H
0010 #define __TZFMT_H
0011 
0012 /**
0013  * \file
0014  * \brief C++ API: TimeZoneFormat
0015  */
0016 
0017 #include "unicode/utypes.h"
0018 
0019 #if U_SHOW_CPLUSPLUS_API
0020 
0021 #if !UCONFIG_NO_FORMATTING
0022 
0023 #include "unicode/format.h"
0024 #include "unicode/timezone.h"
0025 #include "unicode/tznames.h"
0026 
0027 U_CDECL_BEGIN
0028 /**
0029  * Constants for time zone display format style used by format/parse APIs
0030  * in TimeZoneFormat.
0031  * @stable ICU 50
0032  */
0033 typedef enum UTimeZoneFormatStyle {
0034     /**
0035      * Generic location format, such as "United States Time (New York)", "Italy Time"
0036      * @stable ICU 50
0037      */
0038     UTZFMT_STYLE_GENERIC_LOCATION,
0039     /**
0040      * Generic long non-location format, such as "Eastern Time".
0041      * @stable ICU 50
0042      */
0043     UTZFMT_STYLE_GENERIC_LONG,
0044     /**
0045      * Generic short non-location format, such as "ET".
0046      * @stable ICU 50
0047      */
0048     UTZFMT_STYLE_GENERIC_SHORT,
0049     /**
0050      * Specific long format, such as "Eastern Standard Time".
0051      * @stable ICU 50
0052      */
0053     UTZFMT_STYLE_SPECIFIC_LONG,
0054     /**
0055      * Specific short format, such as "EST", "PDT".
0056      * @stable ICU 50
0057      */
0058     UTZFMT_STYLE_SPECIFIC_SHORT,
0059     /**
0060      * Localized GMT offset format, such as "GMT-05:00", "UTC+0100"
0061      * @stable ICU 50
0062      */
0063     UTZFMT_STYLE_LOCALIZED_GMT,
0064     /**
0065      * Short localized GMT offset format, such as "GMT-5", "UTC+1:30"
0066      * This style is equivalent to the LDML date format pattern "O".
0067      * @stable ICU 51
0068      */
0069     UTZFMT_STYLE_LOCALIZED_GMT_SHORT,
0070     /**
0071      * Short ISO 8601 local time difference (basic format) or the UTC indicator.
0072      * For example, "-05", "+0530", and "Z"(UTC).
0073      * This style is equivalent to the LDML date format pattern "X".
0074      * @stable ICU 51
0075      */
0076     UTZFMT_STYLE_ISO_BASIC_SHORT,
0077     /**
0078      * Short ISO 8601 locale time difference (basic format).
0079      * For example, "-05" and "+0530".
0080      * This style is equivalent to the LDML date format pattern "x".
0081      * @stable ICU 51
0082      */
0083     UTZFMT_STYLE_ISO_BASIC_LOCAL_SHORT,
0084     /**
0085      * Fixed width ISO 8601 local time difference (basic format) or the UTC indicator.
0086      * For example, "-0500", "+0530", and "Z"(UTC).
0087      * This style is equivalent to the LDML date format pattern "XX".
0088      * @stable ICU 51
0089      */
0090     UTZFMT_STYLE_ISO_BASIC_FIXED,
0091     /**
0092      * Fixed width ISO 8601 local time difference (basic format).
0093      * For example, "-0500" and "+0530".
0094      * This style is equivalent to the LDML date format pattern "xx".
0095      * @stable ICU 51
0096      */
0097     UTZFMT_STYLE_ISO_BASIC_LOCAL_FIXED,
0098     /**
0099      * ISO 8601 local time difference (basic format) with optional seconds field, or the UTC indicator.
0100      * For example, "-0500", "+052538", and "Z"(UTC).
0101      * This style is equivalent to the LDML date format pattern "XXXX".
0102      * @stable ICU 51
0103      */
0104     UTZFMT_STYLE_ISO_BASIC_FULL,
0105     /**
0106      * ISO 8601 local time difference (basic format) with optional seconds field.
0107      * For example, "-0500" and "+052538".
0108      * This style is equivalent to the LDML date format pattern "xxxx".
0109      * @stable ICU 51
0110      */
0111     UTZFMT_STYLE_ISO_BASIC_LOCAL_FULL,
0112     /**
0113      * Fixed width ISO 8601 local time difference (extended format) or the UTC indicator.
0114      * For example, "-05:00", "+05:30", and "Z"(UTC).
0115      * This style is equivalent to the LDML date format pattern "XXX".
0116      * @stable ICU 51
0117      */
0118     UTZFMT_STYLE_ISO_EXTENDED_FIXED,
0119     /**
0120      * Fixed width ISO 8601 local time difference (extended format).
0121      * For example, "-05:00" and "+05:30".
0122      * This style is equivalent to the LDML date format pattern "xxx" and "ZZZZZ".
0123      * @stable ICU 51
0124      */
0125     UTZFMT_STYLE_ISO_EXTENDED_LOCAL_FIXED,
0126     /**
0127      * ISO 8601 local time difference (extended format) with optional seconds field, or the UTC indicator.
0128      * For example, "-05:00", "+05:25:38", and "Z"(UTC).
0129      * This style is equivalent to the LDML date format pattern "XXXXX".
0130      * @stable ICU 51
0131      */
0132     UTZFMT_STYLE_ISO_EXTENDED_FULL,
0133     /**
0134      * ISO 8601 local time difference (extended format) with optional seconds field.
0135      * For example, "-05:00" and "+05:25:38".
0136      * This style is equivalent to the LDML date format pattern "xxxxx".
0137      * @stable ICU 51
0138      */
0139     UTZFMT_STYLE_ISO_EXTENDED_LOCAL_FULL,
0140     /**
0141      * Time Zone ID, such as "America/Los_Angeles".
0142      * @stable ICU 51
0143      */
0144     UTZFMT_STYLE_ZONE_ID,
0145     /**
0146      * Short Time Zone ID (BCP 47 Unicode location extension, time zone type value), such as "uslax".
0147      * @stable ICU 51
0148      */
0149     UTZFMT_STYLE_ZONE_ID_SHORT,
0150     /**
0151      * Exemplar location, such as "Los Angeles" and "Paris".
0152      * @stable ICU 51
0153      */
0154     UTZFMT_STYLE_EXEMPLAR_LOCATION
0155 } UTimeZoneFormatStyle;
0156 
0157 /**
0158  * Constants for GMT offset pattern types.
0159  * @stable ICU 50
0160  */
0161 typedef enum UTimeZoneFormatGMTOffsetPatternType {
0162     /**
0163      * Positive offset with hours and minutes fields
0164      * @stable ICU 50
0165      */
0166     UTZFMT_PAT_POSITIVE_HM,
0167     /**
0168      * Positive offset with hours, minutes and seconds fields
0169      * @stable ICU 50
0170      */
0171     UTZFMT_PAT_POSITIVE_HMS,
0172     /**
0173      * Negative offset with hours and minutes fields
0174      * @stable ICU 50
0175      */
0176     UTZFMT_PAT_NEGATIVE_HM,
0177     /**
0178      * Negative offset with hours, minutes and seconds fields
0179      * @stable ICU 50
0180      */
0181     UTZFMT_PAT_NEGATIVE_HMS,
0182     /**
0183      * Positive offset with hours field
0184      * @stable ICU 51
0185      */
0186     UTZFMT_PAT_POSITIVE_H,
0187     /**
0188      * Negative offset with hours field
0189      * @stable ICU 51
0190      */
0191     UTZFMT_PAT_NEGATIVE_H,
0192 
0193     /* The following cannot be #ifndef U_HIDE_INTERNAL_API, needed for other .h declarations */
0194     /**
0195      * Number of UTimeZoneFormatGMTOffsetPatternType types.
0196      * @internal
0197      */
0198     UTZFMT_PAT_COUNT = 6
0199 } UTimeZoneFormatGMTOffsetPatternType;
0200 
0201 /**
0202  * Constants for time types used by TimeZoneFormat APIs for
0203  * receiving time type (standard time, daylight time or unknown).
0204  * @stable ICU 50
0205  */
0206 typedef enum UTimeZoneFormatTimeType {
0207     /**
0208      * Unknown
0209      * @stable ICU 50
0210      */
0211     UTZFMT_TIME_TYPE_UNKNOWN,
0212     /**
0213      * Standard time
0214      * @stable ICU 50
0215      */
0216     UTZFMT_TIME_TYPE_STANDARD,
0217     /**
0218      * Daylight saving time
0219      * @stable ICU 50
0220      */
0221     UTZFMT_TIME_TYPE_DAYLIGHT
0222 } UTimeZoneFormatTimeType;
0223 
0224 /**
0225  * Constants for parse option flags, used for specifying optional parse behavior.
0226  * @stable ICU 50
0227  */
0228 typedef enum UTimeZoneFormatParseOption {
0229     /**
0230      * No option.
0231      * @stable ICU 50
0232      */
0233     UTZFMT_PARSE_OPTION_NONE        = 0x00,
0234     /**
0235      * When a time zone display name is not found within a set of display names
0236      * used for the specified style, look for the name from display names used
0237      * by other styles.
0238      * @stable ICU 50
0239      */
0240     UTZFMT_PARSE_OPTION_ALL_STYLES  = 0x01,
0241      /**
0242       * When parsing a time zone display name in \link UTZFMT_STYLE_SPECIFIC_SHORT \endlink,
0243       * look for the IANA tz database compatible zone abbreviations in addition
0244       * to the localized names coming from the icu::TimeZoneNames currently
0245       * used by the icu::TimeZoneFormat.
0246       * @stable ICU 54
0247       */
0248     UTZFMT_PARSE_OPTION_TZ_DATABASE_ABBREVIATIONS = 0x02
0249 } UTimeZoneFormatParseOption;
0250 
0251 U_CDECL_END
0252 
0253 U_NAMESPACE_BEGIN
0254 
0255 class TimeZoneGenericNames;
0256 class TZDBTimeZoneNames;
0257 class UVector;
0258 
0259 /**
0260  * <code>TimeZoneFormat</code> supports time zone display name formatting and parsing.
0261  * An instance of TimeZoneFormat works as a subformatter of {@link SimpleDateFormat},
0262  * but you can also directly get a new instance of <code>TimeZoneFormat</code> and
0263  * formatting/parsing time zone display names.
0264  * <p>
0265  * ICU implements the time zone display names defined by <a href="http://www.unicode.org/reports/tr35/">UTS#35
0266  * Unicode Locale Data Markup Language (LDML)</a>. {@link TimeZoneNames} represents the
0267  * time zone display name data model and this class implements the algorithm for actual
0268  * formatting and parsing.
0269  *
0270  * @see SimpleDateFormat
0271  * @see TimeZoneNames
0272  * @stable ICU 50
0273  */
0274 class U_I18N_API TimeZoneFormat : public Format {
0275 public:
0276     /**
0277      * Copy constructor.
0278      * @stable ICU 50
0279      */
0280     TimeZoneFormat(const TimeZoneFormat& other);
0281 
0282     /**
0283      * Destructor.
0284      * @stable ICU 50
0285      */
0286     virtual ~TimeZoneFormat();
0287 
0288     /**
0289      * Assignment operator.
0290      * @stable ICU 50
0291      */
0292     TimeZoneFormat& operator=(const TimeZoneFormat& other);
0293 
0294     /**
0295      * Return true if the given Format objects are semantically equal.
0296      * Objects of different subclasses are considered unequal.
0297      * @param other The object to be compared with.
0298      * @return Return true if the given Format objects are semantically equal.
0299      *                Objects of different subclasses are considered unequal.
0300      * @stable ICU 50
0301      */
0302     virtual bool operator==(const Format& other) const override;
0303 
0304     /**
0305      * Clone this object polymorphically. The caller is responsible
0306      * for deleting the result when done.
0307      * @return A copy of the object
0308      * @stable ICU 50
0309      */
0310     virtual TimeZoneFormat* clone() const override;
0311 
0312     /**
0313      * Creates an instance of <code>TimeZoneFormat</code> for the given locale.
0314      * @param locale The locale.
0315      * @param status Receives the status.
0316      * @return An instance of <code>TimeZoneFormat</code> for the given locale,
0317      *          owned by the caller.
0318      * @stable ICU 50
0319      */
0320     static TimeZoneFormat* U_EXPORT2 createInstance(const Locale& locale, UErrorCode& status);
0321 
0322     /**
0323      * Returns the time zone display name data used by this instance.
0324      * @return The time zone display name data.
0325      * @stable ICU 50
0326      */
0327     const TimeZoneNames* getTimeZoneNames() const;
0328 
0329     /**
0330      * Sets the time zone display name data to this format instance.
0331      * The caller should not delete the TimeZoenNames object after it is adopted
0332      * by this call.
0333      * @param tznames TimeZoneNames object to be adopted.
0334      * @stable ICU 50
0335      */
0336     void adoptTimeZoneNames(TimeZoneNames *tznames);
0337 
0338     /**
0339      * Sets the time zone display name data to this format instance.
0340      * @param tznames TimeZoneNames object to be set.
0341      * @stable ICU 50
0342      */
0343     void setTimeZoneNames(const TimeZoneNames &tznames);
0344 
0345     /**
0346      * Returns the localized GMT format pattern.
0347      * @param pattern Receives the localized GMT format pattern.
0348      * @return A reference to the result pattern.
0349      * @see #setGMTPattern
0350      * @stable ICU 50
0351      */
0352     UnicodeString& getGMTPattern(UnicodeString& pattern) const;
0353 
0354     /**
0355      * Sets the localized GMT format pattern. The pattern must contain
0356      * a single argument {0}, for example "GMT {0}".
0357      * @param pattern The localized GMT format pattern to be used by this object.
0358      * @param status Receives the status.
0359      * @see #getGMTPattern
0360      * @stable ICU 50
0361      */
0362     void setGMTPattern(const UnicodeString& pattern, UErrorCode& status);
0363 
0364     /**
0365      * Returns the offset pattern used for localized GMT format.
0366      * @param type The offset pattern type enum.
0367      * @param pattern Receives the offset pattern.
0368      * @return A reference to the result pattern.
0369      * @see #setGMTOffsetPattern
0370      * @stable ICU 50
0371      */
0372     UnicodeString& getGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, UnicodeString& pattern) const;
0373 
0374     /**
0375      * Sets the offset pattern for the given offset type.
0376      * @param type The offset pattern type enum.
0377      * @param pattern The offset pattern used for localized GMT format for the type.
0378      * @param status Receives the status.
0379      * @see #getGMTOffsetPattern
0380      * @stable ICU 50
0381      */
0382     void setGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, const UnicodeString& pattern, UErrorCode& status);
0383 
0384     /**
0385      * Returns the decimal digit characters used for localized GMT format.
0386      * The return string contains exactly 10 code points (may include Unicode
0387      * supplementary character) representing digit 0 to digit 9 in the ascending
0388      * order.
0389      * @param digits Receives the decimal digits used for localized GMT format.
0390      * @see #setGMTOffsetDigits
0391      * @stable ICU 50
0392      */
0393     UnicodeString& getGMTOffsetDigits(UnicodeString& digits) const;
0394 
0395     /**
0396      * Sets the decimal digit characters used for localized GMT format.
0397      * The input <code>digits</code> must contain exactly 10 code points
0398      * (Unicode supplementary characters are also allowed) representing
0399      * digit 0 to digit 9 in the ascending order. When the input <code>digits</code>
0400      * does not satisfy the condition, <code>U_ILLEGAL_ARGUMENT_ERROR</code>
0401      * will be set to the return status.
0402      * @param digits The decimal digits used for localized GMT format.
0403      * @param status Receives the status.
0404      * @see #getGMTOffsetDigits
0405      * @stable ICU 50
0406      */
0407     void setGMTOffsetDigits(const UnicodeString& digits, UErrorCode& status);
0408 
0409     /**
0410      * Returns the localized GMT format string for GMT(UTC) itself (GMT offset is 0).
0411      * @param gmtZeroFormat Receives the localized GMT string string for GMT(UTC) itself.
0412      * @return A reference to the result GMT string.
0413      * @see #setGMTZeroFormat
0414      * @stable ICU 50
0415      */
0416     UnicodeString& getGMTZeroFormat(UnicodeString& gmtZeroFormat) const;
0417 
0418     /**
0419      * Sets the localized GMT format string for GMT(UTC) itself (GMT offset is 0).
0420      * @param gmtZeroFormat The localized GMT format string for GMT(UTC).
0421      * @param status Receives the status.
0422      * @see #getGMTZeroFormat
0423      * @stable ICU 50
0424      */
0425     void setGMTZeroFormat(const UnicodeString& gmtZeroFormat, UErrorCode& status);
0426 
0427     /**
0428      * Returns the bitwise flags of UTimeZoneFormatParseOption representing the default parse
0429      * options used by this object.
0430      * @return the default parse options.
0431      * @see ParseOption
0432      * @stable ICU 50
0433      */
0434     uint32_t getDefaultParseOptions(void) const;
0435 
0436     /**
0437      * Sets the default parse options.
0438      * <p><b>Note</b>: By default, an instance of <code>TimeZoneFormat</code>
0439      * created by {@link #createInstance} has no parse options set (UTZFMT_PARSE_OPTION_NONE).
0440      * To specify multiple options, use bitwise flags of UTimeZoneFormatParseOption.
0441      * @see #UTimeZoneFormatParseOption
0442      * @stable ICU 50
0443      */
0444     void setDefaultParseOptions(uint32_t flags);
0445 
0446     /**
0447      * Returns the ISO 8601 basic time zone string for the given offset.
0448      * For example, "-08", "-0830" and "Z"
0449      *
0450      * @param offset the offset from GMT(UTC) in milliseconds.
0451      * @param useUtcIndicator true if ISO 8601 UTC indicator "Z" is used when the offset is 0.
0452      * @param isShort true if shortest form is used.
0453      * @param ignoreSeconds true if non-zero offset seconds is appended.
0454      * @param result Receives the ISO format string.
0455      * @param status Receives the status
0456      * @return the ISO 8601 basic format.
0457      * @see #formatOffsetISO8601Extended
0458      * @see #parseOffsetISO8601
0459      * @stable ICU 51
0460      */
0461     UnicodeString& formatOffsetISO8601Basic(int32_t offset, UBool useUtcIndicator, UBool isShort, UBool ignoreSeconds,
0462         UnicodeString& result, UErrorCode& status) const;
0463 
0464     /**
0465      * Returns the ISO 8601 extended time zone string for the given offset.
0466      * For example, "-08:00", "-08:30" and "Z"
0467      *
0468      * @param offset the offset from GMT(UTC) in milliseconds.
0469      * @param useUtcIndicator true if ISO 8601 UTC indicator "Z" is used when the offset is 0.
0470      * @param isShort true if shortest form is used.
0471      * @param ignoreSeconds true if non-zero offset seconds is appended.
0472      * @param result Receives the ISO format string.
0473      * @param status Receives the status
0474      * @return the ISO 8601 basic format.
0475      * @see #formatOffsetISO8601Extended
0476      * @see #parseOffsetISO8601
0477      * @stable ICU 51
0478      */
0479     UnicodeString& formatOffsetISO8601Extended(int32_t offset, UBool useUtcIndicator, UBool isShort, UBool ignoreSeconds,
0480         UnicodeString& result, UErrorCode& status) const;
0481 
0482     /**
0483      * Returns the localized GMT(UTC) offset format for the given offset.
0484      * The localized GMT offset is defined by;
0485      * <ul>
0486      * <li>GMT format pattern (e.g. "GMT {0}" - see {@link #getGMTPattern})
0487      * <li>Offset time pattern (e.g. "+HH:mm" - see {@link #getGMTOffsetPattern})
0488      * <li>Offset digits (e.g. "0123456789" - see {@link #getGMTOffsetDigits})
0489      * <li>GMT zero format (e.g. "GMT" - see {@link #getGMTZeroFormat})
0490      * </ul>
0491      * This format always uses 2 digit hours and minutes. When the given offset has non-zero
0492      * seconds, 2 digit seconds field will be appended. For example,
0493      * GMT+05:00 and GMT+05:28:06.
0494      * @param offset the offset from GMT(UTC) in milliseconds.
0495      * @param status Receives the status
0496      * @param result Receives the localized GMT format string.
0497      * @return A reference to the result.
0498      * @see #parseOffsetLocalizedGMT
0499      * @stable ICU 50
0500      */
0501     UnicodeString& formatOffsetLocalizedGMT(int32_t offset, UnicodeString& result, UErrorCode& status) const;
0502 
0503     /**
0504      * Returns the short localized GMT(UTC) offset format for the given offset.
0505      * The short localized GMT offset is defined by;
0506      * <ul>
0507      * <li>GMT format pattern (e.g. "GMT {0}" - see {@link #getGMTPattern})
0508      * <li>Offset time pattern (e.g. "+HH:mm" - see {@link #getGMTOffsetPattern})
0509      * <li>Offset digits (e.g. "0123456789" - see {@link #getGMTOffsetDigits})
0510      * <li>GMT zero format (e.g. "GMT" - see {@link #getGMTZeroFormat})
0511      * </ul>
0512      * This format uses the shortest representation of offset. The hours field does not
0513      * have leading zero and lower fields with zero will be truncated. For example,
0514      * GMT+5 and GMT+530.
0515      * @param offset the offset from GMT(UTC) in milliseconds.
0516      * @param status Receives the status
0517      * @param result Receives the short localized GMT format string.
0518      * @return A reference to the result.
0519      * @see #parseOffsetShortLocalizedGMT
0520      * @stable ICU 51
0521      */
0522     UnicodeString& formatOffsetShortLocalizedGMT(int32_t offset, UnicodeString& result, UErrorCode& status) const;
0523 
0524     using Format::format;
0525 
0526     /**
0527      * Returns the display name of the time zone at the given date for the style.
0528      * @param style The style (e.g. <code>UTZFMT_STYLE_GENERIC_LONG</code>, <code>UTZFMT_STYLE_LOCALIZED_GMT</code>...)
0529      * @param tz The time zone.
0530      * @param date The date.
0531      * @param name Receives the display name.
0532      * @param timeType the output argument for receiving the time type (standard/daylight/unknown)
0533      * used for the display name, or nullptr if the information is not necessary.
0534      * @return A reference to the result
0535      * @see #UTimeZoneFormatStyle
0536      * @see #UTimeZoneFormatTimeType
0537      * @stable ICU 50
0538      */
0539     virtual UnicodeString& format(UTimeZoneFormatStyle style, const TimeZone& tz, UDate date,
0540         UnicodeString& name, UTimeZoneFormatTimeType* timeType = nullptr) const;
0541 
0542     /**
0543      * Returns offset from GMT(UTC) in milliseconds for the given ISO 8601
0544      * style time zone string. When the given string is not an ISO 8601 time zone
0545      * string, this method sets the current position as the error index
0546      * to <code>ParsePosition pos</code> and returns 0.
0547      * @param text The text contains ISO8601 style time zone string (e.g. "-08:00", "Z")
0548      *              at the position.
0549      * @param pos The ParsePosition object.
0550      * @return The offset from GMT(UTC) in milliseconds for the given ISO 8601 style
0551      *              time zone string.
0552      * @see #formatOffsetISO8601Basic
0553      * @see #formatOffsetISO8601Extended
0554      * @stable ICU 50
0555      */
0556     int32_t parseOffsetISO8601(const UnicodeString& text, ParsePosition& pos) const;
0557 
0558     /**
0559      * Returns offset from GMT(UTC) in milliseconds for the given localized GMT
0560      * offset format string. When the given string cannot be parsed, this method
0561      * sets the current position as the error index to <code>ParsePosition pos</code>
0562      * and returns 0.
0563      * @param text The text contains a localized GMT offset string at the position.
0564      * @param pos The ParsePosition object.
0565      * @return The offset from GMT(UTC) in milliseconds for the given localized GMT
0566      *          offset format string.
0567      * @see #formatOffsetLocalizedGMT
0568      * @stable ICU 50
0569      */
0570     int32_t parseOffsetLocalizedGMT(const UnicodeString& text, ParsePosition& pos) const;
0571 
0572     /**
0573      * Returns offset from GMT(UTC) in milliseconds for the given short localized GMT
0574      * offset format string. When the given string cannot be parsed, this method
0575      * sets the current position as the error index to <code>ParsePosition pos</code>
0576      * and returns 0.
0577      * @param text The text contains a short localized GMT offset string at the position.
0578      * @param pos The ParsePosition object.
0579      * @return The offset from GMT(UTC) in milliseconds for the given short localized GMT
0580      *          offset format string.
0581      * @see #formatOffsetShortLocalizedGMT
0582      * @stable ICU 51
0583      */
0584     int32_t parseOffsetShortLocalizedGMT(const UnicodeString& text, ParsePosition& pos) const;
0585 
0586     /**
0587      * Returns a <code>TimeZone</code> by parsing the time zone string according to
0588      * the given parse position, the specified format style and parse options.
0589      *
0590      * @param text The text contains a time zone string at the position.
0591      * @param style The format style
0592      * @param pos The position.
0593      * @param parseOptions The parse options represented by bitwise flags of UTimeZoneFormatParseOption.
0594      * @param timeType The output argument for receiving the time type (standard/daylight/unknown),
0595      * or nullptr if the information is not necessary.
0596      * @return A <code>TimeZone</code>, or null if the input could not be parsed.
0597      * @see UTimeZoneFormatStyle
0598      * @see UTimeZoneFormatParseOption
0599      * @see UTimeZoneFormatTimeType
0600      * @stable ICU 50
0601      */
0602     virtual TimeZone* parse(UTimeZoneFormatStyle style, const UnicodeString& text, ParsePosition& pos,
0603         int32_t parseOptions, UTimeZoneFormatTimeType* timeType = nullptr) const;
0604 
0605     /**
0606      * Returns a <code>TimeZone</code> by parsing the time zone string according to
0607      * the given parse position, the specified format style and the default parse options.
0608      *
0609      * @param text The text contains a time zone string at the position.
0610      * @param style The format style
0611      * @param pos The position.
0612      * @param timeType The output argument for receiving the time type (standard/daylight/unknown),
0613      * or nullptr if the information is not necessary.
0614      * @return A <code>TimeZone</code>, or null if the input could not be parsed.
0615      * @see UTimeZoneFormatStyle
0616      * @see UTimeZoneFormatParseOption
0617      * @see UTimeZoneFormatTimeType
0618      * @stable ICU 50
0619      */
0620     TimeZone* parse(UTimeZoneFormatStyle style, const UnicodeString& text, ParsePosition& pos,
0621         UTimeZoneFormatTimeType* timeType = nullptr) const;
0622 
0623     /* ----------------------------------------------
0624      * Format APIs
0625      * ---------------------------------------------- */
0626 
0627     /**
0628      * Format an object to produce a time zone display string using localized GMT offset format.
0629      * This method handles Formattable objects with a <code>TimeZone</code>. If a the Formattable
0630      * object type is not a <code>TimeZone</code>, then it returns a failing UErrorCode.
0631      * @param obj The object to format. Must be a <code>TimeZone</code>.
0632      * @param appendTo Output parameter to receive result. Result is appended to existing contents.
0633      * @param pos On input: an alignment field, if desired. On output: the offsets of the alignment field.
0634      * @param status Output param filled with success/failure status.
0635      * @return Reference to 'appendTo' parameter.
0636      * @stable ICU 50
0637      */
0638     virtual UnicodeString& format(const Formattable& obj, UnicodeString& appendTo,
0639         FieldPosition& pos, UErrorCode& status) const override;
0640 
0641     /**
0642      * Parse a string to produce an object. This methods handles parsing of
0643      * time zone display strings into Formattable objects with <code>TimeZone</code>.
0644      * @param source The string to be parsed into an object.
0645      * @param result Formattable to be set to the parse result. If parse fails, return contents are undefined.
0646      * @param parse_pos The position to start parsing at. Upon return this param is set to the position after the
0647      *                  last character successfully parsed. If the source is not parsed successfully, this param
0648      *                  will remain unchanged.
0649      * @return A newly created Formattable* object, or nullptr on failure.  The caller owns this and should
0650      *                 delete it when done.
0651      * @stable ICU 50
0652      */
0653     virtual void parseObject(const UnicodeString& source, Formattable& result, ParsePosition& parse_pos) const override;
0654 
0655     /**
0656      * ICU "poor man's RTTI", returns a UClassID for this class.
0657      * @stable ICU 50
0658      */
0659     static UClassID U_EXPORT2 getStaticClassID(void);
0660 
0661     /**
0662      * ICU "poor man's RTTI", returns a UClassID for the actual class.
0663      * @stable ICU 50
0664      */
0665     virtual UClassID getDynamicClassID() const override;
0666 
0667 protected:
0668     /**
0669      * Constructs a TimeZoneFormat object for the specified locale.
0670      * @param locale the locale
0671      * @param status receives the status.
0672      * @stable ICU 50
0673      */
0674     TimeZoneFormat(const Locale& locale, UErrorCode& status);
0675 
0676 private:
0677     /* Locale of this object */
0678     Locale fLocale;
0679 
0680     /* Stores the region (could be implicit default) */
0681     char fTargetRegion[ULOC_COUNTRY_CAPACITY];
0682 
0683     /* TimeZoneNames object used by this formatter */
0684     TimeZoneNames* fTimeZoneNames;
0685 
0686     /* TimeZoneGenericNames object used by this formatter - lazily instantiated */
0687     TimeZoneGenericNames* fTimeZoneGenericNames;
0688 
0689     /* Localized GMT format pattern - e.g. "GMT{0}" */
0690     UnicodeString fGMTPattern;
0691 
0692     /* Array of offset patterns used by Localized GMT format - e.g. "+HH:mm" */
0693     UnicodeString fGMTOffsetPatterns[UTZFMT_PAT_COUNT];
0694 
0695     /* Localized decimal digits used by Localized GMT format */
0696     UChar32 fGMTOffsetDigits[10];
0697 
0698     /* Localized GMT zero format - e.g. "GMT" */
0699     UnicodeString fGMTZeroFormat;
0700 
0701     /* Bit flags representing parse options */
0702     uint32_t fDefParseOptionFlags;
0703 
0704     /* Constant parts of GMT format pattern, populated from localized GMT format pattern*/
0705     UnicodeString fGMTPatternPrefix;    /* Substring before {0} */
0706     UnicodeString fGMTPatternSuffix;    /* Substring after {0} */
0707 
0708     /* Compiled offset patterns generated from fGMTOffsetPatterns[] */
0709     UVector* fGMTOffsetPatternItems[UTZFMT_PAT_COUNT];
0710 
0711     UBool fAbuttingOffsetHoursAndMinutes;
0712 
0713     /* TZDBTimeZoneNames object used for parsing */
0714     TZDBTimeZoneNames* fTZDBTimeZoneNames;
0715 
0716     /**
0717      * Returns the time zone's specific format string.
0718      * @param tz the time zone
0719      * @param stdType the name type used for standard time
0720      * @param dstType the name type used for daylight time
0721      * @param date the date
0722      * @param name receives the time zone's specific format name string
0723      * @param timeType when null, actual time type is set
0724      * @return a reference to name.
0725      */
0726     UnicodeString& formatSpecific(const TimeZone& tz, UTimeZoneNameType stdType, UTimeZoneNameType dstType,
0727         UDate date, UnicodeString& name, UTimeZoneFormatTimeType *timeType) const;
0728 
0729     /**
0730      * Returns the time zone's generic format string.
0731      * @param tz the time zone
0732      * @param genType the generic name type
0733      * @param date the date
0734      * @param name receives the time zone's generic format name string
0735      * @return a reference to name.
0736      */
0737     UnicodeString& formatGeneric(const TimeZone& tz, int32_t genType, UDate date, UnicodeString& name) const;
0738 
0739     /**
0740      * Lazily create a TimeZoneGenericNames instance
0741      * @param status receives the status
0742      * @return the cached TimeZoneGenericNames.
0743      */
0744     const TimeZoneGenericNames* getTimeZoneGenericNames(UErrorCode& status) const;
0745 
0746     /**
0747      * Lazily create a TZDBTimeZoneNames instance
0748      * @param status receives the status
0749      * @return the cached TZDBTimeZoneNames.
0750      */
0751     const TZDBTimeZoneNames* getTZDBTimeZoneNames(UErrorCode& status) const;
0752 
0753     /**
0754      * Private method returning the time zone's exemplar location string.
0755      * This method will never return empty.
0756      * @param tz the time zone
0757      * @param name receives the time zone's exemplar location name
0758      * @return a reference to name.
0759      */
0760     UnicodeString& formatExemplarLocation(const TimeZone& tz, UnicodeString& name) const;
0761 
0762     /**
0763      * Private enum specifying a combination of offset fields
0764      */
0765     enum OffsetFields {
0766         FIELDS_H,
0767         FIELDS_HM,
0768         FIELDS_HMS
0769     };
0770 
0771     /**
0772      * Parses the localized GMT pattern string and initialize
0773      * localized gmt pattern fields.
0774      * @param gmtPattern the localized GMT pattern string such as "GMT {0}"
0775      * @param status U_ILLEGAL_ARGUMENT_ERROR is set when the specified pattern does not
0776      *               contain an argument "{0}".
0777      */
0778     void initGMTPattern(const UnicodeString& gmtPattern, UErrorCode& status);
0779 
0780     /**
0781      * Parse the GMT offset pattern into runtime optimized format.
0782      * @param pattern the offset pattern string
0783      * @param required the required set of fields, such as FIELDS_HM
0784      * @param status U_ILLEGAL_ARGUMENT is set when the specified pattern does not contain
0785      *               pattern letters for the required fields.
0786      * @return A list of GMTOffsetField objects, or nullptr on error.
0787      */
0788     static UVector* parseOffsetPattern(const UnicodeString& pattern, OffsetFields required, UErrorCode& status);
0789 
0790     /**
0791      * Appends seconds field to the offset pattern with hour/minute
0792      * Note: This code will be obsoleted once we add hour-minute-second pattern data in CLDR.
0793      * @param offsetHM the offset pattern including hours and minutes fields
0794      * @param result the output offset pattern including hour, minute and seconds fields
0795      * @param status receives the status
0796      * @return a reference to result
0797      */
0798     static UnicodeString& expandOffsetPattern(const UnicodeString& offsetHM, UnicodeString& result, UErrorCode& status);
0799 
0800     /**
0801      * Truncates minutes field to the offset pattern with hour/minute
0802      * Note: This code will be obsoleted once we add hour pattern data in CLDR.
0803      * @param offsetHM the offset pattern including hours and minutes fields
0804      * @param result the output offset pattern including only hours field
0805      * @param status receives the status
0806      * @return a reference to result
0807      */
0808     static UnicodeString& truncateOffsetPattern(const UnicodeString& offsetHM, UnicodeString& result, UErrorCode& status);
0809 
0810     /**
0811      * Break input string into UChar32[]. Each array element represents
0812      * a code point. This method is used for parsing localized digit
0813      * characters and support characters in Unicode supplemental planes.
0814      * @param str the string
0815      * @param codeArray receives the result
0816      * @param capacity the capacity of codeArray
0817      * @return true when the specified code array is fully filled with code points
0818      *         (no under/overflow).
0819      */
0820     static UBool toCodePoints(const UnicodeString& str, UChar32* codeArray, int32_t capacity);
0821 
0822     /**
0823      * Private method supprting all of ISO8601 formats
0824      * @param offset the offset from GMT(UTC) in milliseconds.
0825      * @param useUtcIndicator true if ISO 8601 UTC indicator "Z" is used when the offset is 0.
0826      * @param isShort true if shortest form is used.
0827      * @param ignoreSeconds true if non-zero offset seconds is appended.
0828      * @param result Receives the result
0829      * @param status Receives the status
0830      * @return the ISO 8601 basic format.
0831      */
0832     UnicodeString& formatOffsetISO8601(int32_t offset, UBool isBasic, UBool useUtcIndicator,
0833         UBool isShort, UBool ignoreSeconds, UnicodeString& result, UErrorCode& status) const;
0834 
0835     /**
0836      * Private method used for localized GMT formatting.
0837      * @param offset the zone's UTC offset
0838      * @param isShort true if the short localized GMT format is desired.
0839      * @param result receives the localized GMT format string
0840      * @param status receives the status
0841      */
0842     UnicodeString& formatOffsetLocalizedGMT(int32_t offset, UBool isShort, UnicodeString& result, UErrorCode& status) const;
0843 
0844     /**
0845      * Returns offset from GMT(UTC) in milliseconds for the given ISO 8601 style
0846      * (extended format) time zone string. When the given string is not an ISO 8601 time
0847      * zone string, this method sets the current position as the error index
0848      * to <code>ParsePosition pos</code> and returns 0.
0849      * @param text the text contains ISO 8601 style time zone string (e.g. "-08:00", "Z")
0850      *      at the position.
0851      * @param pos the position, non-negative error index will be set on failure.
0852      * @param extendedOnly true if parsing the text as ISO 8601 extended offset format (e.g. "-08:00"),
0853      *      or false to evaluate the text as basic format.
0854      * @param hasDigitOffset receiving if the parsed zone string contains offset digits.
0855      * @return the offset from GMT(UTC) in milliseconds for the given ISO 8601 style
0856      *      time zone string.
0857      */
0858     int32_t parseOffsetISO8601(const UnicodeString& text, ParsePosition& pos, UBool extendedOnly,
0859         UBool* hasDigitOffset = nullptr) const;
0860 
0861     /**
0862      * Appends localized digits to the buffer.
0863      * This code assumes that the input number is 0 - 59
0864      * @param buf the target buffer
0865      * @param n the integer number
0866      * @param minDigits the minimum digits width
0867      */
0868     void appendOffsetDigits(UnicodeString& buf, int32_t n, uint8_t minDigits) const;
0869 
0870     /**
0871      * Returns offset from GMT(UTC) in milliseconds for the given localized GMT
0872      * offset format string. When the given string cannot be parsed, this method
0873      * sets the current position as the error index to <code>ParsePosition pos</code>
0874      * and returns 0.
0875      * @param text the text contains a localized GMT offset string at the position.
0876      * @param pos the position, non-negative error index will be set on failure.
0877      * @param isShort true if this parser to try the short format first
0878      * @param hasDigitOffset receiving if the parsed zone string contains offset digits.
0879      * @return the offset from GMT(UTC) in milliseconds for the given localized GMT
0880      *      offset format string.
0881      */
0882     int32_t parseOffsetLocalizedGMT(const UnicodeString& text, ParsePosition& pos,
0883         UBool isShort, UBool* hasDigitOffset) const;
0884 
0885     /**
0886      * Parse localized GMT format generated by the patter used by this formatter, except
0887      * GMT Zero format.
0888      * @param text the input text
0889      * @param start the start index
0890      * @param isShort true if the short localized format is parsed.
0891      * @param parsedLen receives the parsed length
0892      * @return the parsed offset in milliseconds
0893      */
0894     int32_t parseOffsetLocalizedGMTPattern(const UnicodeString& text, int32_t start,
0895         UBool isShort, int32_t& parsedLen) const;
0896 
0897     /**
0898      * Parses localized GMT offset fields into offset.
0899      * @param text the input text
0900      * @param start the start index
0901      * @param isShort true if this is a short format - currently not used
0902      * @param parsedLen the parsed length, or 0 on failure.
0903      * @return the parsed offset in milliseconds.
0904      */
0905     int32_t parseOffsetFields(const UnicodeString& text, int32_t start, UBool isShort, int32_t& parsedLen) const;
0906 
0907     /**
0908      * Parse localized GMT offset fields with the given pattern.
0909      * @param text the input text
0910      * @param start the start index
0911      * @param pattenItems the pattern (already itemized)
0912      * @param forceSingleHourDigit true if hours field is parsed as a single digit
0913      * @param hour receives the hour offset field
0914      * @param min receives the minute offset field
0915      * @param sec receives the second offset field
0916      * @return the parsed length
0917      */
0918     int32_t parseOffsetFieldsWithPattern(const UnicodeString& text, int32_t start,
0919         UVector* patternItems, UBool forceSingleHourDigit, int32_t& hour, int32_t& min, int32_t& sec) const;
0920 
0921     /**
0922      * Parses abutting localized GMT offset fields (such as 0800) into offset.
0923      * @param text the input text
0924      * @param start the start index
0925      * @param parsedLen the parsed length, or 0 on failure
0926      * @return the parsed offset in milliseconds.
0927      */
0928     int32_t parseAbuttingOffsetFields(const UnicodeString& text, int32_t start, int32_t& parsedLen) const;
0929 
0930     /**
0931      * Parses the input text using the default format patterns (e.g. "UTC{0}").
0932      * @param text the input text
0933      * @param start the start index
0934      * @param parsedLen the parsed length, or 0 on failure
0935      * @return the parsed offset in milliseconds.
0936      */
0937     int32_t parseOffsetDefaultLocalizedGMT(const UnicodeString& text, int start, int32_t& parsedLen) const;
0938 
0939     /**
0940      * Parses the input GMT offset fields with the default offset pattern.
0941      * @param text the input text
0942      * @param start the start index
0943      * @param separator the separator character, e.g. ':'
0944      * @param parsedLen the parsed length, or 0 on failure.
0945      * @return the parsed offset in milliseconds.
0946      */
0947     int32_t parseDefaultOffsetFields(const UnicodeString& text, int32_t start, char16_t separator,
0948         int32_t& parsedLen) const;
0949 
0950     /**
0951      * Reads an offset field value. This method will stop parsing when
0952      * 1) number of digits reaches <code>maxDigits</code>
0953      * 2) just before already parsed number exceeds <code>maxVal</code>
0954      *
0955      * @param text the text
0956      * @param start the start offset
0957      * @param minDigits the minimum number of required digits
0958      * @param maxDigits the maximum number of digits
0959      * @param minVal the minimum value
0960      * @param maxVal the maximum value
0961      * @param parsedLen the actual parsed length.
0962      * @return the integer value parsed
0963      */
0964     int32_t parseOffsetFieldWithLocalizedDigits(const UnicodeString& text, int32_t start,
0965         uint8_t minDigits, uint8_t maxDigits, uint16_t minVal, uint16_t maxVal, int32_t& parsedLen) const;
0966 
0967     /**
0968      * Reads a single decimal digit, either localized digits used by this object
0969      * or any Unicode numeric character.
0970      * @param text the text
0971      * @param start the start index
0972      * @param len the actual length read from the text
0973      * the start index is not a decimal number.
0974      * @return the integer value of the parsed digit, or -1 on failure.
0975      */
0976     int32_t parseSingleLocalizedDigit(const UnicodeString& text, int32_t start, int32_t& len) const;
0977 
0978     /**
0979      * Formats offset using ASCII digits. The input offset range must be
0980      * within +/-24 hours (exclusive).
0981      * @param offset The offset
0982      * @param sep The field separator character or 0 if not required
0983      * @param minFields The minimum fields
0984      * @param maxFields The maximum fields
0985      * @return The offset string
0986      */
0987     static UnicodeString& formatOffsetWithAsciiDigits(int32_t offset, char16_t sep,
0988         OffsetFields minFields, OffsetFields maxFields, UnicodeString& result);
0989 
0990     /**
0991      * Parses offset represented by contiguous ASCII digits.
0992      * <p>
0993      * Note: This method expects the input position is already at the start of
0994      * ASCII digits and does not parse sign (+/-).
0995      * @param text The text contains a sequence of ASCII digits
0996      * @param pos The parse position
0997      * @param minFields The minimum Fields to be parsed
0998      * @param maxFields The maximum Fields to be parsed
0999      * @param fixedHourWidth true if hours field must be width of 2
1000      * @return Parsed offset, 0 or positive number.
1001      */
1002     static int32_t parseAbuttingAsciiOffsetFields(const UnicodeString& text, ParsePosition& pos,
1003         OffsetFields minFields, OffsetFields maxFields, UBool fixedHourWidth);
1004 
1005     /**
1006      * Parses offset represented by ASCII digits and separators.
1007      * <p>
1008      * Note: This method expects the input position is already at the start of
1009      * ASCII digits and does not parse sign (+/-).
1010      * @param text The text
1011      * @param pos The parse position
1012      * @param sep The separator character
1013      * @param minFields The minimum Fields to be parsed
1014      * @param maxFields The maximum Fields to be parsed
1015      * @return Parsed offset, 0 or positive number.
1016      */
1017     static int32_t parseAsciiOffsetFields(const UnicodeString& text, ParsePosition& pos, char16_t sep,
1018         OffsetFields minFields, OffsetFields maxFields);
1019 
1020     /**
1021      * Unquotes the message format style pattern.
1022      * @param pattern the pattern
1023      * @param result receive the unquoted pattern.
1024      * @return A reference to result.
1025      */
1026     static UnicodeString& unquote(const UnicodeString& pattern, UnicodeString& result);
1027 
1028     /**
1029      * Initialize localized GMT format offset hour/min/sec patterns.
1030      * This method parses patterns into optimized run-time format.
1031      * @param status receives the status.
1032      */
1033     void initGMTOffsetPatterns(UErrorCode& status);
1034 
1035     /**
1036      * Check if there are any GMT format offset patterns without
1037      * any separators between hours field and minutes field and update
1038      * fAbuttingOffsetHoursAndMinutes field. This method must be called
1039      * after all patterns are parsed into pattern items.
1040      */
1041     void checkAbuttingHoursAndMinutes();
1042 
1043     /**
1044      * Creates an instance of TimeZone for the given offset
1045      * @param offset the offset
1046      * @return A TimeZone with the given offset
1047      */
1048     TimeZone* createTimeZoneForOffset(int32_t offset) const;
1049 
1050     /**
1051      * Returns the time type for the given name type
1052      * @param nameType the name type
1053      * @return the time type (unknown/standard/daylight)
1054      */
1055     static UTimeZoneFormatTimeType getTimeType(UTimeZoneNameType nameType);
1056 
1057     /**
1058      * Returns the time zone ID of a match at the specified index within
1059      * the MatchInfoCollection.
1060      * @param matches the collection of matches
1061      * @param idx the index within matches
1062      * @param tzID receives the resolved time zone ID
1063      * @return a reference to tzID.
1064      */
1065     UnicodeString& getTimeZoneID(const TimeZoneNames::MatchInfoCollection* matches, int32_t idx, UnicodeString& tzID) const;
1066 
1067 
1068     /**
1069      * Parse a zone ID.
1070      * @param text the text contains a time zone ID string at the position.
1071      * @param pos the position
1072      * @param tzID receives the zone ID
1073      * @return a reference to tzID
1074      */
1075     UnicodeString& parseZoneID(const UnicodeString& text, ParsePosition& pos, UnicodeString& tzID) const;
1076 
1077     /**
1078      * Parse a short zone ID.
1079      * @param text the text contains a short time zone ID string at the position.
1080      * @param pos the position
1081      * @param tzID receives the short zone ID
1082      * @return a reference to tzID
1083      */
1084     UnicodeString& parseShortZoneID(const UnicodeString& text, ParsePosition& pos, UnicodeString& tzID) const;
1085 
1086     /**
1087      * Parse an exemplar location string.
1088      * @param text the text contains an exemplar location string at the position.
1089      * @param pos the position.
1090      * @param tzID receives the time zone ID
1091      * @return a reference to tzID
1092      */
1093     UnicodeString& parseExemplarLocation(const UnicodeString& text, ParsePosition& pos, UnicodeString& tzID) const;
1094 };
1095 
1096 U_NAMESPACE_END
1097 
1098 #endif /* !UCONFIG_NO_FORMATTING */
1099 
1100 #endif /* U_SHOW_CPLUSPLUS_API */
1101 
1102 #endif