Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* |
michael@0 | 2 | ******************************************************************************* |
michael@0 | 3 | * Copyright (C) 2011-2013, International Business Machines Corporation and * |
michael@0 | 4 | * others. All Rights Reserved. * |
michael@0 | 5 | ******************************************************************************* |
michael@0 | 6 | */ |
michael@0 | 7 | #ifndef __TZFMT_H |
michael@0 | 8 | #define __TZFMT_H |
michael@0 | 9 | |
michael@0 | 10 | /** |
michael@0 | 11 | * \file |
michael@0 | 12 | * \brief C++ API: TimeZoneFormat |
michael@0 | 13 | */ |
michael@0 | 14 | |
michael@0 | 15 | #include "unicode/utypes.h" |
michael@0 | 16 | |
michael@0 | 17 | #if !UCONFIG_NO_FORMATTING |
michael@0 | 18 | |
michael@0 | 19 | #include "unicode/format.h" |
michael@0 | 20 | #include "unicode/timezone.h" |
michael@0 | 21 | #include "unicode/tznames.h" |
michael@0 | 22 | |
michael@0 | 23 | U_CDECL_BEGIN |
michael@0 | 24 | /** |
michael@0 | 25 | * Constants for time zone display format style used by format/parse APIs |
michael@0 | 26 | * in TimeZoneFormat. |
michael@0 | 27 | * @stable ICU 50 |
michael@0 | 28 | */ |
michael@0 | 29 | typedef enum UTimeZoneFormatStyle { |
michael@0 | 30 | /** |
michael@0 | 31 | * Generic location format, such as "United States Time (New York)", "Italy Time" |
michael@0 | 32 | * @stable ICU 50 |
michael@0 | 33 | */ |
michael@0 | 34 | UTZFMT_STYLE_GENERIC_LOCATION, |
michael@0 | 35 | /** |
michael@0 | 36 | * Generic long non-location format, such as "Eastern Time". |
michael@0 | 37 | * @stable ICU 50 |
michael@0 | 38 | */ |
michael@0 | 39 | UTZFMT_STYLE_GENERIC_LONG, |
michael@0 | 40 | /** |
michael@0 | 41 | * Generic short non-location format, such as "ET". |
michael@0 | 42 | * @stable ICU 50 |
michael@0 | 43 | */ |
michael@0 | 44 | UTZFMT_STYLE_GENERIC_SHORT, |
michael@0 | 45 | /** |
michael@0 | 46 | * Specific long format, such as "Eastern Standard Time". |
michael@0 | 47 | * @stable ICU 50 |
michael@0 | 48 | */ |
michael@0 | 49 | UTZFMT_STYLE_SPECIFIC_LONG, |
michael@0 | 50 | /** |
michael@0 | 51 | * Specific short format, such as "EST", "PDT". |
michael@0 | 52 | * @stable ICU 50 |
michael@0 | 53 | */ |
michael@0 | 54 | UTZFMT_STYLE_SPECIFIC_SHORT, |
michael@0 | 55 | /** |
michael@0 | 56 | * Localized GMT offset format, such as "GMT-05:00", "UTC+0100" |
michael@0 | 57 | * @stable ICU 50 |
michael@0 | 58 | */ |
michael@0 | 59 | UTZFMT_STYLE_LOCALIZED_GMT, |
michael@0 | 60 | #ifndef U_HIDE_DRAFT_API |
michael@0 | 61 | /** |
michael@0 | 62 | * Short localized GMT offset format, such as "GMT-5", "UTC+1:30" |
michael@0 | 63 | * This style is equivalent to the LDML date format pattern "O". |
michael@0 | 64 | * @draft ICU 51 |
michael@0 | 65 | */ |
michael@0 | 66 | UTZFMT_STYLE_LOCALIZED_GMT_SHORT, |
michael@0 | 67 | /** |
michael@0 | 68 | * Short ISO 8601 local time difference (basic format) or the UTC indicator. |
michael@0 | 69 | * For example, "-05", "+0530", and "Z"(UTC). |
michael@0 | 70 | * This style is equivalent to the LDML date format pattern "X". |
michael@0 | 71 | * @draft ICU 51 |
michael@0 | 72 | */ |
michael@0 | 73 | UTZFMT_STYLE_ISO_BASIC_SHORT, |
michael@0 | 74 | /** |
michael@0 | 75 | * Short ISO 8601 locale time difference (basic format). |
michael@0 | 76 | * For example, "-05" and "+0530". |
michael@0 | 77 | * This style is equivalent to the LDML date format pattern "x". |
michael@0 | 78 | * @draft ICU 51 |
michael@0 | 79 | */ |
michael@0 | 80 | UTZFMT_STYLE_ISO_BASIC_LOCAL_SHORT, |
michael@0 | 81 | /** |
michael@0 | 82 | * Fixed width ISO 8601 local time difference (basic format) or the UTC indicator. |
michael@0 | 83 | * For example, "-0500", "+0530", and "Z"(UTC). |
michael@0 | 84 | * This style is equivalent to the LDML date format pattern "XX". |
michael@0 | 85 | * @draft ICU 51 |
michael@0 | 86 | */ |
michael@0 | 87 | UTZFMT_STYLE_ISO_BASIC_FIXED, |
michael@0 | 88 | /** |
michael@0 | 89 | * Fixed width ISO 8601 local time difference (basic format). |
michael@0 | 90 | * For example, "-0500" and "+0530". |
michael@0 | 91 | * This style is equivalent to the LDML date format pattern "xx". |
michael@0 | 92 | * @draft ICU 51 |
michael@0 | 93 | */ |
michael@0 | 94 | UTZFMT_STYLE_ISO_BASIC_LOCAL_FIXED, |
michael@0 | 95 | /** |
michael@0 | 96 | * ISO 8601 local time difference (basic format) with optional seconds field, or the UTC indicator. |
michael@0 | 97 | * For example, "-0500", "+052538", and "Z"(UTC). |
michael@0 | 98 | * This style is equivalent to the LDML date format pattern "XXXX". |
michael@0 | 99 | * @draft ICU 51 |
michael@0 | 100 | */ |
michael@0 | 101 | UTZFMT_STYLE_ISO_BASIC_FULL, |
michael@0 | 102 | /** |
michael@0 | 103 | * ISO 8601 local time difference (basic format) with optional seconds field. |
michael@0 | 104 | * For example, "-0500" and "+052538". |
michael@0 | 105 | * This style is equivalent to the LDML date format pattern "xxxx". |
michael@0 | 106 | * @draft ICU 51 |
michael@0 | 107 | */ |
michael@0 | 108 | UTZFMT_STYLE_ISO_BASIC_LOCAL_FULL, |
michael@0 | 109 | /** |
michael@0 | 110 | * Fixed width ISO 8601 local time difference (extended format) or the UTC indicator. |
michael@0 | 111 | * For example, "-05:00", "+05:30", and "Z"(UTC). |
michael@0 | 112 | * This style is equivalent to the LDML date format pattern "XXX". |
michael@0 | 113 | * @draft ICU 51 |
michael@0 | 114 | */ |
michael@0 | 115 | UTZFMT_STYLE_ISO_EXTENDED_FIXED, |
michael@0 | 116 | /** |
michael@0 | 117 | * Fixed width ISO 8601 local time difference (extended format). |
michael@0 | 118 | * For example, "-05:00" and "+05:30". |
michael@0 | 119 | * This style is equivalent to the LDML date format pattern "xxx" and "ZZZZZ". |
michael@0 | 120 | * @draft ICU 51 |
michael@0 | 121 | */ |
michael@0 | 122 | UTZFMT_STYLE_ISO_EXTENDED_LOCAL_FIXED, |
michael@0 | 123 | /** |
michael@0 | 124 | * ISO 8601 local time difference (extended format) with optional seconds field, or the UTC indicator. |
michael@0 | 125 | * For example, "-05:00", "+05:25:38", and "Z"(UTC). |
michael@0 | 126 | * This style is equivalent to the LDML date format pattern "XXXXX". |
michael@0 | 127 | * @draft ICU 51 |
michael@0 | 128 | */ |
michael@0 | 129 | UTZFMT_STYLE_ISO_EXTENDED_FULL, |
michael@0 | 130 | /** |
michael@0 | 131 | * ISO 8601 local time difference (extended format) with optional seconds field. |
michael@0 | 132 | * For example, "-05:00" and "+05:25:38". |
michael@0 | 133 | * This style is equivalent to the LDML date format pattern "xxxxx". |
michael@0 | 134 | * @draft ICU 51 |
michael@0 | 135 | */ |
michael@0 | 136 | UTZFMT_STYLE_ISO_EXTENDED_LOCAL_FULL, |
michael@0 | 137 | /** |
michael@0 | 138 | * Time Zone ID, such as "America/Los_Angeles". |
michael@0 | 139 | * @draft ICU 51 |
michael@0 | 140 | */ |
michael@0 | 141 | UTZFMT_STYLE_ZONE_ID, |
michael@0 | 142 | /** |
michael@0 | 143 | * Short Time Zone ID (BCP 47 Unicode location extension, time zone type value), such as "uslax". |
michael@0 | 144 | * @draft ICU 51 |
michael@0 | 145 | */ |
michael@0 | 146 | UTZFMT_STYLE_ZONE_ID_SHORT, |
michael@0 | 147 | /** |
michael@0 | 148 | * Exemplar location, such as "Los Angeles" and "Paris". |
michael@0 | 149 | * @draft ICU 51 |
michael@0 | 150 | */ |
michael@0 | 151 | UTZFMT_STYLE_EXEMPLAR_LOCATION |
michael@0 | 152 | #endif /* U_HIDE_DRAFT_API */ |
michael@0 | 153 | } UTimeZoneFormatStyle; |
michael@0 | 154 | |
michael@0 | 155 | /** |
michael@0 | 156 | * Constants for GMT offset pattern types. |
michael@0 | 157 | * @stable ICU 50 |
michael@0 | 158 | */ |
michael@0 | 159 | typedef enum UTimeZoneFormatGMTOffsetPatternType { |
michael@0 | 160 | /** |
michael@0 | 161 | * Positive offset with hours and minutes fields |
michael@0 | 162 | * @stable ICU 50 |
michael@0 | 163 | */ |
michael@0 | 164 | UTZFMT_PAT_POSITIVE_HM, |
michael@0 | 165 | /** |
michael@0 | 166 | * Positive offset with hours, minutes and seconds fields |
michael@0 | 167 | * @stable ICU 50 |
michael@0 | 168 | */ |
michael@0 | 169 | UTZFMT_PAT_POSITIVE_HMS, |
michael@0 | 170 | /** |
michael@0 | 171 | * Negative offset with hours and minutes fields |
michael@0 | 172 | * @stable ICU 50 |
michael@0 | 173 | */ |
michael@0 | 174 | UTZFMT_PAT_NEGATIVE_HM, |
michael@0 | 175 | /** |
michael@0 | 176 | * Negative offset with hours, minutes and seconds fields |
michael@0 | 177 | * @stable ICU 50 |
michael@0 | 178 | */ |
michael@0 | 179 | UTZFMT_PAT_NEGATIVE_HMS, |
michael@0 | 180 | #ifndef U_HIDE_DRAFT_API |
michael@0 | 181 | /** |
michael@0 | 182 | * Positive offset with hours field |
michael@0 | 183 | * @draft ICU 51 |
michael@0 | 184 | */ |
michael@0 | 185 | UTZFMT_PAT_POSITIVE_H, |
michael@0 | 186 | /** |
michael@0 | 187 | * Negative offset with hours field |
michael@0 | 188 | * @draft ICU 51 |
michael@0 | 189 | */ |
michael@0 | 190 | UTZFMT_PAT_NEGATIVE_H, |
michael@0 | 191 | #endif /* U_HIDE_DRAFT_API */ |
michael@0 | 192 | |
michael@0 | 193 | /** |
michael@0 | 194 | * Number of UTimeZoneFormatGMTOffsetPatternType types. |
michael@0 | 195 | * @internal |
michael@0 | 196 | */ |
michael@0 | 197 | UTZFMT_PAT_COUNT = 6 |
michael@0 | 198 | } UTimeZoneFormatGMTOffsetPatternType; |
michael@0 | 199 | |
michael@0 | 200 | /** |
michael@0 | 201 | * Constants for time types used by TimeZoneFormat APIs for |
michael@0 | 202 | * receiving time type (standard time, daylight time or unknown). |
michael@0 | 203 | * @stable ICU 50 |
michael@0 | 204 | */ |
michael@0 | 205 | typedef enum UTimeZoneFormatTimeType { |
michael@0 | 206 | /** |
michael@0 | 207 | * Unknown |
michael@0 | 208 | * @stable ICU 50 |
michael@0 | 209 | */ |
michael@0 | 210 | UTZFMT_TIME_TYPE_UNKNOWN, |
michael@0 | 211 | /** |
michael@0 | 212 | * Standard time |
michael@0 | 213 | * @stable ICU 50 |
michael@0 | 214 | */ |
michael@0 | 215 | UTZFMT_TIME_TYPE_STANDARD, |
michael@0 | 216 | /** |
michael@0 | 217 | * Daylight saving time |
michael@0 | 218 | * @stable ICU 50 |
michael@0 | 219 | */ |
michael@0 | 220 | UTZFMT_TIME_TYPE_DAYLIGHT |
michael@0 | 221 | } UTimeZoneFormatTimeType; |
michael@0 | 222 | |
michael@0 | 223 | /** |
michael@0 | 224 | * Constants for parse option flags, used for specifying optional parse behavior. |
michael@0 | 225 | * @stable ICU 50 |
michael@0 | 226 | */ |
michael@0 | 227 | typedef enum UTimeZoneFormatParseOption { |
michael@0 | 228 | /** |
michael@0 | 229 | * No option. |
michael@0 | 230 | * @stable ICU 50 |
michael@0 | 231 | */ |
michael@0 | 232 | UTZFMT_PARSE_OPTION_NONE = 0x00, |
michael@0 | 233 | /** |
michael@0 | 234 | * When a time zone display name is not found within a set of display names |
michael@0 | 235 | * used for the specified style, look for the name from display names used |
michael@0 | 236 | * by other styles. |
michael@0 | 237 | * @stable ICU 50 |
michael@0 | 238 | */ |
michael@0 | 239 | UTZFMT_PARSE_OPTION_ALL_STYLES = 0x01 |
michael@0 | 240 | } UTimeZoneFormatParseOption; |
michael@0 | 241 | |
michael@0 | 242 | U_CDECL_END |
michael@0 | 243 | |
michael@0 | 244 | U_NAMESPACE_BEGIN |
michael@0 | 245 | |
michael@0 | 246 | class TimeZoneGenericNames; |
michael@0 | 247 | class UVector; |
michael@0 | 248 | |
michael@0 | 249 | /** |
michael@0 | 250 | * <code>TimeZoneFormat</code> supports time zone display name formatting and parsing. |
michael@0 | 251 | * An instance of TimeZoneFormat works as a subformatter of {@link SimpleDateFormat}, |
michael@0 | 252 | * but you can also directly get a new instance of <code>TimeZoneFormat</code> and |
michael@0 | 253 | * formatting/parsing time zone display names. |
michael@0 | 254 | * <p> |
michael@0 | 255 | * ICU implements the time zone display names defined by <a href="http://www.unicode.org/reports/tr35/">UTS#35 |
michael@0 | 256 | * Unicode Locale Data Markup Language (LDML)</a>. {@link TimeZoneNames} represents the |
michael@0 | 257 | * time zone display name data model and this class implements the algorithm for actual |
michael@0 | 258 | * formatting and parsing. |
michael@0 | 259 | * |
michael@0 | 260 | * @see SimpleDateFormat |
michael@0 | 261 | * @see TimeZoneNames |
michael@0 | 262 | * @stable ICU 50 |
michael@0 | 263 | */ |
michael@0 | 264 | class U_I18N_API TimeZoneFormat : public Format { |
michael@0 | 265 | public: |
michael@0 | 266 | /** |
michael@0 | 267 | * Copy constructor. |
michael@0 | 268 | * @stable ICU 50 |
michael@0 | 269 | */ |
michael@0 | 270 | TimeZoneFormat(const TimeZoneFormat& other); |
michael@0 | 271 | |
michael@0 | 272 | /** |
michael@0 | 273 | * Destructor. |
michael@0 | 274 | * @stable ICU 50 |
michael@0 | 275 | */ |
michael@0 | 276 | virtual ~TimeZoneFormat(); |
michael@0 | 277 | |
michael@0 | 278 | /** |
michael@0 | 279 | * Assignment operator. |
michael@0 | 280 | * @stable ICU 50 |
michael@0 | 281 | */ |
michael@0 | 282 | TimeZoneFormat& operator=(const TimeZoneFormat& other); |
michael@0 | 283 | |
michael@0 | 284 | /** |
michael@0 | 285 | * Return true if the given Format objects are semantically equal. |
michael@0 | 286 | * Objects of different subclasses are considered unequal. |
michael@0 | 287 | * @param other The object to be compared with. |
michael@0 | 288 | * @return Return TRUE if the given Format objects are semantically equal. |
michael@0 | 289 | * Objects of different subclasses are considered unequal. |
michael@0 | 290 | * @stable ICU 50 |
michael@0 | 291 | */ |
michael@0 | 292 | virtual UBool operator==(const Format& other) const; |
michael@0 | 293 | |
michael@0 | 294 | /** |
michael@0 | 295 | * Clone this object polymorphically. The caller is responsible |
michael@0 | 296 | * for deleting the result when done. |
michael@0 | 297 | * @return A copy of the object |
michael@0 | 298 | * @stable ICU 50 |
michael@0 | 299 | */ |
michael@0 | 300 | virtual Format* clone() const; |
michael@0 | 301 | |
michael@0 | 302 | /** |
michael@0 | 303 | * Creates an instance of <code>TimeZoneFormat</code> for the given locale. |
michael@0 | 304 | * @param locale The locale. |
michael@0 | 305 | * @param status Recevies the status. |
michael@0 | 306 | * @return An instance of <code>TimeZoneFormat</code> for the given locale, |
michael@0 | 307 | * owned by the caller. |
michael@0 | 308 | * @stable ICU 50 |
michael@0 | 309 | */ |
michael@0 | 310 | static TimeZoneFormat* U_EXPORT2 createInstance(const Locale& locale, UErrorCode& status); |
michael@0 | 311 | |
michael@0 | 312 | /** |
michael@0 | 313 | * Returns the time zone display name data used by this instance. |
michael@0 | 314 | * @return The time zone display name data. |
michael@0 | 315 | * @stable ICU 50 |
michael@0 | 316 | */ |
michael@0 | 317 | const TimeZoneNames* getTimeZoneNames() const; |
michael@0 | 318 | |
michael@0 | 319 | /** |
michael@0 | 320 | * Sets the time zone display name data to this format instnace. |
michael@0 | 321 | * The caller should not delete the TimeZoenNames object after it is adopted |
michael@0 | 322 | * by this call. |
michael@0 | 323 | * @param tznames TimeZoneNames object to be adopted. |
michael@0 | 324 | * @stable ICU 50 |
michael@0 | 325 | */ |
michael@0 | 326 | void adoptTimeZoneNames(TimeZoneNames *tznames); |
michael@0 | 327 | |
michael@0 | 328 | /** |
michael@0 | 329 | * Sets the time zone display name data to this format instnace. |
michael@0 | 330 | * @param tznames TimeZoneNames object to be set. |
michael@0 | 331 | * @stable ICU 50 |
michael@0 | 332 | */ |
michael@0 | 333 | void setTimeZoneNames(const TimeZoneNames &tznames); |
michael@0 | 334 | |
michael@0 | 335 | /** |
michael@0 | 336 | * Returns the localized GMT format pattern. |
michael@0 | 337 | * @param pattern Receives the localized GMT format pattern. |
michael@0 | 338 | * @return A reference to the result pattern. |
michael@0 | 339 | * @see #setGMTPattern |
michael@0 | 340 | * @stable ICU 50 |
michael@0 | 341 | */ |
michael@0 | 342 | UnicodeString& getGMTPattern(UnicodeString& pattern) const; |
michael@0 | 343 | |
michael@0 | 344 | /** |
michael@0 | 345 | * Sets the localized GMT format pattern. The pattern must contain |
michael@0 | 346 | * a single argument {0}, for example "GMT {0}". |
michael@0 | 347 | * @param pattern The localized GMT format pattern to be used by this object. |
michael@0 | 348 | * @param status Recieves the status. |
michael@0 | 349 | * @see #getGMTPattern |
michael@0 | 350 | * @stable ICU 50 |
michael@0 | 351 | */ |
michael@0 | 352 | void setGMTPattern(const UnicodeString& pattern, UErrorCode& status); |
michael@0 | 353 | |
michael@0 | 354 | /** |
michael@0 | 355 | * Returns the offset pattern used for localized GMT format. |
michael@0 | 356 | * @param type The offset pattern type enum. |
michael@0 | 357 | * @param pattern Receives the offset pattern. |
michael@0 | 358 | * @return A reference to the result pattern. |
michael@0 | 359 | * @see #setGMTOffsetPattern |
michael@0 | 360 | * @stable ICU 50 |
michael@0 | 361 | */ |
michael@0 | 362 | UnicodeString& getGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, UnicodeString& pattern) const; |
michael@0 | 363 | |
michael@0 | 364 | /** |
michael@0 | 365 | * Sets the offset pattern for the given offset type. |
michael@0 | 366 | * @param type The offset pattern type enum. |
michael@0 | 367 | * @param pattern The offset pattern used for localized GMT format for the type. |
michael@0 | 368 | * @param status Receives the status. |
michael@0 | 369 | * @see #getGMTOffsetPattern |
michael@0 | 370 | * @stable ICU 50 |
michael@0 | 371 | */ |
michael@0 | 372 | void setGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, const UnicodeString& pattern, UErrorCode& status); |
michael@0 | 373 | |
michael@0 | 374 | /** |
michael@0 | 375 | * Returns the decimal digit characters used for localized GMT format. |
michael@0 | 376 | * The return string contains exactly 10 code points (may include Unicode |
michael@0 | 377 | * supplementary character) representing digit 0 to digit 9 in the ascending |
michael@0 | 378 | * order. |
michael@0 | 379 | * @param digits Receives the decimal digits used for localized GMT format. |
michael@0 | 380 | * @see #setGMTOffsetDigits |
michael@0 | 381 | * @stable ICU 50 |
michael@0 | 382 | */ |
michael@0 | 383 | UnicodeString& getGMTOffsetDigits(UnicodeString& digits) const; |
michael@0 | 384 | |
michael@0 | 385 | /** |
michael@0 | 386 | * Sets the decimal digit characters used for localized GMT format. |
michael@0 | 387 | * The input <code>digits</code> must contain exactly 10 code points |
michael@0 | 388 | * (Unicode supplementary characters are also allowed) representing |
michael@0 | 389 | * digit 0 to digit 9 in the ascending order. When the input <code>digits</code> |
michael@0 | 390 | * does not satisfy the condition, <code>U_ILLEGAL_ARGUMENT_ERROR</code> |
michael@0 | 391 | * will be set to the return status. |
michael@0 | 392 | * @param digits The decimal digits used for localized GMT format. |
michael@0 | 393 | * @param status Receives the status. |
michael@0 | 394 | * @see #getGMTOffsetDigits |
michael@0 | 395 | * @stable ICU 50 |
michael@0 | 396 | */ |
michael@0 | 397 | void setGMTOffsetDigits(const UnicodeString& digits, UErrorCode& status); |
michael@0 | 398 | |
michael@0 | 399 | /** |
michael@0 | 400 | * Returns the localized GMT format string for GMT(UTC) itself (GMT offset is 0). |
michael@0 | 401 | * @param gmtZeroFormat Receives the localized GMT string string for GMT(UTC) itself. |
michael@0 | 402 | * @return A reference to the result GMT string. |
michael@0 | 403 | * @see #setGMTZeroFormat |
michael@0 | 404 | * @stable ICU 50 |
michael@0 | 405 | */ |
michael@0 | 406 | UnicodeString& getGMTZeroFormat(UnicodeString& gmtZeroFormat) const; |
michael@0 | 407 | |
michael@0 | 408 | /** |
michael@0 | 409 | * Sets the localized GMT format string for GMT(UTC) itself (GMT offset is 0). |
michael@0 | 410 | * @param gmtZeroFormat The localized GMT format string for GMT(UTC). |
michael@0 | 411 | * @param status Receives the status. |
michael@0 | 412 | * @see #getGMTZeroFormat |
michael@0 | 413 | * @stable ICU 50 |
michael@0 | 414 | */ |
michael@0 | 415 | void setGMTZeroFormat(const UnicodeString& gmtZeroFormat, UErrorCode& status); |
michael@0 | 416 | |
michael@0 | 417 | /** |
michael@0 | 418 | * Returns the bitwise flags of UTimeZoneFormatParseOption representing the default parse |
michael@0 | 419 | * options used by this object. |
michael@0 | 420 | * @return the default parse options. |
michael@0 | 421 | * @see ParseOption |
michael@0 | 422 | * @stable ICU 50 |
michael@0 | 423 | */ |
michael@0 | 424 | uint32_t getDefaultParseOptions(void) const; |
michael@0 | 425 | |
michael@0 | 426 | /** |
michael@0 | 427 | * Sets the default parse options. |
michael@0 | 428 | * <p><b>Note</b>: By default, an instance of <code>TimeZoneFormat</code> |
michael@0 | 429 | * created by {@link #createInstance} has no parse options set (UTZFMT_PARSE_OPTION_NONE). |
michael@0 | 430 | * To specify multipe options, use bitwise flags of UTimeZoneFormatParseOption. |
michael@0 | 431 | * @see #UTimeZoneFormatParseOption |
michael@0 | 432 | * @stable ICU 50 |
michael@0 | 433 | */ |
michael@0 | 434 | void setDefaultParseOptions(uint32_t flags); |
michael@0 | 435 | |
michael@0 | 436 | #ifndef U_HIDE_DRAFT_API |
michael@0 | 437 | /** |
michael@0 | 438 | * Returns the ISO 8601 basic time zone string for the given offset. |
michael@0 | 439 | * For example, "-08", "-0830" and "Z" |
michael@0 | 440 | * |
michael@0 | 441 | * @param offset the offset from GMT(UTC) in milliseconds. |
michael@0 | 442 | * @param useUtcIndicator true if ISO 8601 UTC indicator "Z" is used when the offset is 0. |
michael@0 | 443 | * @param isShort true if shortest form is used. |
michael@0 | 444 | * @param ignoreSeconds true if non-zero offset seconds is appended. |
michael@0 | 445 | * @param result Receives the ISO format string. |
michael@0 | 446 | * @param status Receives the status |
michael@0 | 447 | * @return the ISO 8601 basic format. |
michael@0 | 448 | * @see #formatOffsetISO8601Extended |
michael@0 | 449 | * @see #parseOffsetISO8601 |
michael@0 | 450 | * @draft ICU 51 |
michael@0 | 451 | */ |
michael@0 | 452 | UnicodeString& formatOffsetISO8601Basic(int32_t offset, UBool useUtcIndicator, UBool isShort, UBool ignoreSeconds, |
michael@0 | 453 | UnicodeString& result, UErrorCode& status) const; |
michael@0 | 454 | |
michael@0 | 455 | /** |
michael@0 | 456 | * Returns the ISO 8601 extended time zone string for the given offset. |
michael@0 | 457 | * For example, "-08:00", "-08:30" and "Z" |
michael@0 | 458 | * |
michael@0 | 459 | * @param offset the offset from GMT(UTC) in milliseconds. |
michael@0 | 460 | * @param useUtcIndicator true if ISO 8601 UTC indicator "Z" is used when the offset is 0. |
michael@0 | 461 | * @param isShort true if shortest form is used. |
michael@0 | 462 | * @param ignoreSeconds true if non-zero offset seconds is appended. |
michael@0 | 463 | * @param result Receives the ISO format string. |
michael@0 | 464 | * @param status Receives the status |
michael@0 | 465 | * @return the ISO 8601 basic format. |
michael@0 | 466 | * @see #formatOffsetISO8601Extended |
michael@0 | 467 | * @see #parseOffsetISO8601 |
michael@0 | 468 | * @draft ICU 51 |
michael@0 | 469 | */ |
michael@0 | 470 | UnicodeString& formatOffsetISO8601Extended(int32_t offset, UBool useUtcIndicator, UBool isShort, UBool ignoreSeconds, |
michael@0 | 471 | UnicodeString& result, UErrorCode& status) const; |
michael@0 | 472 | #endif /* U_HIDE_DRAFT_API */ |
michael@0 | 473 | |
michael@0 | 474 | /** |
michael@0 | 475 | * Returns the localized GMT(UTC) offset format for the given offset. |
michael@0 | 476 | * The localized GMT offset is defined by; |
michael@0 | 477 | * <ul> |
michael@0 | 478 | * <li>GMT format pattern (e.g. "GMT {0}" - see {@link #getGMTPattern}) |
michael@0 | 479 | * <li>Offset time pattern (e.g. "+HH:mm" - see {@link #getGMTOffsetPattern}) |
michael@0 | 480 | * <li>Offset digits (e.g. "0123456789" - see {@link #getGMTOffsetDigits}) |
michael@0 | 481 | * <li>GMT zero format (e.g. "GMT" - see {@link #getGMTZeroFormat}) |
michael@0 | 482 | * </ul> |
michael@0 | 483 | * This format always uses 2 digit hours and minutes. When the given offset has non-zero |
michael@0 | 484 | * seconds, 2 digit seconds field will be appended. For example, |
michael@0 | 485 | * GMT+05:00 and GMT+05:28:06. |
michael@0 | 486 | * @param offset the offset from GMT(UTC) in milliseconds. |
michael@0 | 487 | * @param status Receives the status |
michael@0 | 488 | * @param result Receives the localized GMT format string. |
michael@0 | 489 | * @return A reference to the result. |
michael@0 | 490 | * @see #parseOffsetLocalizedGMT |
michael@0 | 491 | * @stable ICU 50 |
michael@0 | 492 | */ |
michael@0 | 493 | UnicodeString& formatOffsetLocalizedGMT(int32_t offset, UnicodeString& result, UErrorCode& status) const; |
michael@0 | 494 | |
michael@0 | 495 | #ifndef U_HIDE_DRAFT_API |
michael@0 | 496 | /** |
michael@0 | 497 | * Returns the short localized GMT(UTC) offset format for the given offset. |
michael@0 | 498 | * The short localized GMT offset is defined by; |
michael@0 | 499 | * <ul> |
michael@0 | 500 | * <li>GMT format pattern (e.g. "GMT {0}" - see {@link #getGMTPattern}) |
michael@0 | 501 | * <li>Offset time pattern (e.g. "+HH:mm" - see {@link #getGMTOffsetPattern}) |
michael@0 | 502 | * <li>Offset digits (e.g. "0123456789" - see {@link #getGMTOffsetDigits}) |
michael@0 | 503 | * <li>GMT zero format (e.g. "GMT" - see {@link #getGMTZeroFormat}) |
michael@0 | 504 | * </ul> |
michael@0 | 505 | * This format uses the shortest representation of offset. The hours field does not |
michael@0 | 506 | * have leading zero and lower fields with zero will be truncated. For example, |
michael@0 | 507 | * GMT+5 and GMT+530. |
michael@0 | 508 | * @param offset the offset from GMT(UTC) in milliseconds. |
michael@0 | 509 | * @param status Receives the status |
michael@0 | 510 | * @param result Receives the short localized GMT format string. |
michael@0 | 511 | * @return A reference to the result. |
michael@0 | 512 | * @see #parseOffsetShortLocalizedGMT |
michael@0 | 513 | * @draft ICU 51 |
michael@0 | 514 | */ |
michael@0 | 515 | UnicodeString& formatOffsetShortLocalizedGMT(int32_t offset, UnicodeString& result, UErrorCode& status) const; |
michael@0 | 516 | #endif /* U_HIDE_DRAFT_API */ |
michael@0 | 517 | |
michael@0 | 518 | using Format::format; |
michael@0 | 519 | |
michael@0 | 520 | /** |
michael@0 | 521 | * Returns the display name of the time zone at the given date for the style. |
michael@0 | 522 | * @param style The style (e.g. <code>UTZFMT_STYLE_GENERIC_LONG</code>, <code>UTZFMT_STYLE_LOCALIZED_GMT</code>...) |
michael@0 | 523 | * @param tz The time zone. |
michael@0 | 524 | * @param date The date. |
michael@0 | 525 | * @param name Receives the display name. |
michael@0 | 526 | * @param timeType the output argument for receiving the time type (standard/daylight/unknown) |
michael@0 | 527 | * used for the display name, or NULL if the information is not necessary. |
michael@0 | 528 | * @return A reference to the result |
michael@0 | 529 | * @see #UTimeZoneFormatStyle |
michael@0 | 530 | * @see #UTimeZoneFormatTimeType |
michael@0 | 531 | * @stable ICU 50 |
michael@0 | 532 | */ |
michael@0 | 533 | virtual UnicodeString& format(UTimeZoneFormatStyle style, const TimeZone& tz, UDate date, |
michael@0 | 534 | UnicodeString& name, UTimeZoneFormatTimeType* timeType = NULL) const; |
michael@0 | 535 | |
michael@0 | 536 | /** |
michael@0 | 537 | * Returns offset from GMT(UTC) in milliseconds for the given ISO 8601 |
michael@0 | 538 | * style time zone string. When the given string is not an ISO 8601 time zone |
michael@0 | 539 | * string, this method sets the current position as the error index |
michael@0 | 540 | * to <code>ParsePosition pos</code> and returns 0. |
michael@0 | 541 | * @param text The text contains ISO8601 style time zone string (e.g. "-08:00", "Z") |
michael@0 | 542 | * at the position. |
michael@0 | 543 | * @param pos The ParsePosition object. |
michael@0 | 544 | * @return The offset from GMT(UTC) in milliseconds for the given ISO 8601 style |
michael@0 | 545 | * time zone string. |
michael@0 | 546 | * @see #formatOffsetISO8601Basic |
michael@0 | 547 | * @see #formatOffsetISO8601Extended |
michael@0 | 548 | * @stable ICU 50 |
michael@0 | 549 | */ |
michael@0 | 550 | int32_t parseOffsetISO8601(const UnicodeString& text, ParsePosition& pos) const; |
michael@0 | 551 | |
michael@0 | 552 | /** |
michael@0 | 553 | * Returns offset from GMT(UTC) in milliseconds for the given localized GMT |
michael@0 | 554 | * offset format string. When the given string cannot be parsed, this method |
michael@0 | 555 | * sets the current position as the error index to <code>ParsePosition pos</code> |
michael@0 | 556 | * and returns 0. |
michael@0 | 557 | * @param text The text contains a localized GMT offset string at the position. |
michael@0 | 558 | * @param pos The ParsePosition object. |
michael@0 | 559 | * @return The offset from GMT(UTC) in milliseconds for the given localized GMT |
michael@0 | 560 | * offset format string. |
michael@0 | 561 | * @see #formatOffsetLocalizedGMT |
michael@0 | 562 | * @stable ICU 50 |
michael@0 | 563 | */ |
michael@0 | 564 | int32_t parseOffsetLocalizedGMT(const UnicodeString& text, ParsePosition& pos) const; |
michael@0 | 565 | |
michael@0 | 566 | #ifndef U_HIDE_DRAFT_API |
michael@0 | 567 | /** |
michael@0 | 568 | * Returns offset from GMT(UTC) in milliseconds for the given short localized GMT |
michael@0 | 569 | * offset format string. When the given string cannot be parsed, this method |
michael@0 | 570 | * sets the current position as the error index to <code>ParsePosition pos</code> |
michael@0 | 571 | * and returns 0. |
michael@0 | 572 | * @param text The text contains a short localized GMT offset string at the position. |
michael@0 | 573 | * @param pos The ParsePosition object. |
michael@0 | 574 | * @return The offset from GMT(UTC) in milliseconds for the given short localized GMT |
michael@0 | 575 | * offset format string. |
michael@0 | 576 | * @see #formatOffsetShortLocalizedGMT |
michael@0 | 577 | * @draft ICU 51 |
michael@0 | 578 | */ |
michael@0 | 579 | int32_t parseOffsetShortLocalizedGMT(const UnicodeString& text, ParsePosition& pos) const; |
michael@0 | 580 | #endif /* U_HIDE_DRAFT_API */ |
michael@0 | 581 | |
michael@0 | 582 | /** |
michael@0 | 583 | * Returns a <code>TimeZone</code> by parsing the time zone string according to |
michael@0 | 584 | * the given parse position, the specified format style and parse options. |
michael@0 | 585 | * |
michael@0 | 586 | * @param text The text contains a time zone string at the position. |
michael@0 | 587 | * @param style The format style |
michael@0 | 588 | * @param pos The position. |
michael@0 | 589 | * @param parseOptions The parse options repesented by bitwise flags of UTimeZoneFormatParseOption. |
michael@0 | 590 | * @param timeType The output argument for receiving the time type (standard/daylight/unknown), |
michael@0 | 591 | * or NULL if the information is not necessary. |
michael@0 | 592 | * @return A <code>TimeZone</code>, or null if the input could not be parsed. |
michael@0 | 593 | * @see UTimeZoneFormatStyle |
michael@0 | 594 | * @see UTimeZoneFormatParseOption |
michael@0 | 595 | * @see UTimeZoneFormatTimeType |
michael@0 | 596 | * @stable ICU 50 |
michael@0 | 597 | */ |
michael@0 | 598 | virtual TimeZone* parse(UTimeZoneFormatStyle style, const UnicodeString& text, ParsePosition& pos, |
michael@0 | 599 | int32_t parseOptions, UTimeZoneFormatTimeType* timeType = NULL) const; |
michael@0 | 600 | |
michael@0 | 601 | /** |
michael@0 | 602 | * Returns a <code>TimeZone</code> by parsing the time zone string according to |
michael@0 | 603 | * the given parse position, the specified format style and the default parse options. |
michael@0 | 604 | * |
michael@0 | 605 | * @param text The text contains a time zone string at the position. |
michael@0 | 606 | * @param style The format style |
michael@0 | 607 | * @param pos The position. |
michael@0 | 608 | * @param timeType The output argument for receiving the time type (standard/daylight/unknown), |
michael@0 | 609 | * or NULL if the information is not necessary. |
michael@0 | 610 | * @return A <code>TimeZone</code>, or null if the input could not be parsed. |
michael@0 | 611 | * @see UTimeZoneFormatStyle |
michael@0 | 612 | * @see UTimeZoneFormatParseOption |
michael@0 | 613 | * @see UTimeZoneFormatTimeType |
michael@0 | 614 | * @stable ICU 50 |
michael@0 | 615 | */ |
michael@0 | 616 | TimeZone* parse(UTimeZoneFormatStyle style, const UnicodeString& text, ParsePosition& pos, |
michael@0 | 617 | UTimeZoneFormatTimeType* timeType = NULL) const; |
michael@0 | 618 | |
michael@0 | 619 | /* ---------------------------------------------- |
michael@0 | 620 | * Format APIs |
michael@0 | 621 | * ---------------------------------------------- */ |
michael@0 | 622 | |
michael@0 | 623 | /** |
michael@0 | 624 | * Format an object to produce a time zone display string using localized GMT offset format. |
michael@0 | 625 | * This method handles Formattable objects with a <code>TimeZone</code>. If a the Formattable |
michael@0 | 626 | * object type is not a <code>TimeZone</code>, then it returns a failing UErrorCode. |
michael@0 | 627 | * @param obj The object to format. Must be a <code>TimeZone</code>. |
michael@0 | 628 | * @param appendTo Output parameter to receive result. Result is appended to existing contents. |
michael@0 | 629 | * @param pos On input: an alignment field, if desired. On output: the offsets of the alignment field. |
michael@0 | 630 | * @param status Output param filled with success/failure status. |
michael@0 | 631 | * @return Reference to 'appendTo' parameter. |
michael@0 | 632 | * @stable ICU 50 |
michael@0 | 633 | */ |
michael@0 | 634 | virtual UnicodeString& format(const Formattable& obj, UnicodeString& appendTo, |
michael@0 | 635 | FieldPosition& pos, UErrorCode& status) const; |
michael@0 | 636 | |
michael@0 | 637 | /** |
michael@0 | 638 | * Parse a string to produce an object. This methods handles parsing of |
michael@0 | 639 | * time zone display strings into Formattable objects with <code>TimeZone</code>. |
michael@0 | 640 | * @param source The string to be parsed into an object. |
michael@0 | 641 | * @param result Formattable to be set to the parse result. If parse fails, return contents are undefined. |
michael@0 | 642 | * @param parse_pos The position to start parsing at. Upon return this param is set to the position after the |
michael@0 | 643 | * last character successfully parsed. If the source is not parsed successfully, this param |
michael@0 | 644 | * will remain unchanged. |
michael@0 | 645 | * @return A newly created Formattable* object, or NULL on failure. The caller owns this and should |
michael@0 | 646 | * delete it when done. |
michael@0 | 647 | * @stable ICU 50 |
michael@0 | 648 | */ |
michael@0 | 649 | virtual void parseObject(const UnicodeString& source, Formattable& result, ParsePosition& parse_pos) const; |
michael@0 | 650 | |
michael@0 | 651 | /** |
michael@0 | 652 | * ICU "poor man's RTTI", returns a UClassID for this class. |
michael@0 | 653 | * @stable ICU 50 |
michael@0 | 654 | */ |
michael@0 | 655 | static UClassID U_EXPORT2 getStaticClassID(void); |
michael@0 | 656 | |
michael@0 | 657 | /** |
michael@0 | 658 | * ICU "poor man's RTTI", returns a UClassID for the actual class. |
michael@0 | 659 | * @stable ICU 50 |
michael@0 | 660 | */ |
michael@0 | 661 | virtual UClassID getDynamicClassID() const; |
michael@0 | 662 | |
michael@0 | 663 | protected: |
michael@0 | 664 | /** |
michael@0 | 665 | * Constructs a TimeZoneFormat object for the specified locale. |
michael@0 | 666 | * @param locale the locale |
michael@0 | 667 | * @param status receives the status. |
michael@0 | 668 | * @stable ICU 50 |
michael@0 | 669 | */ |
michael@0 | 670 | TimeZoneFormat(const Locale& locale, UErrorCode& status); |
michael@0 | 671 | |
michael@0 | 672 | private: |
michael@0 | 673 | /* Locale of this object */ |
michael@0 | 674 | Locale fLocale; |
michael@0 | 675 | |
michael@0 | 676 | /* Stores the region (could be implicit default) */ |
michael@0 | 677 | char fTargetRegion[ULOC_COUNTRY_CAPACITY]; |
michael@0 | 678 | |
michael@0 | 679 | /* TimeZoneNames object used by this formatter */ |
michael@0 | 680 | TimeZoneNames* fTimeZoneNames; |
michael@0 | 681 | |
michael@0 | 682 | /* TimeZoneGenericNames object used by this formatter - lazily instantiated */ |
michael@0 | 683 | TimeZoneGenericNames* fTimeZoneGenericNames; |
michael@0 | 684 | |
michael@0 | 685 | /* Localized GMT format pattern - e.g. "GMT{0}" */ |
michael@0 | 686 | UnicodeString fGMTPattern; |
michael@0 | 687 | |
michael@0 | 688 | /* Array of offset patterns used by Localized GMT format - e.g. "+HH:mm" */ |
michael@0 | 689 | UnicodeString fGMTOffsetPatterns[UTZFMT_PAT_COUNT]; |
michael@0 | 690 | |
michael@0 | 691 | /* Localized decimal digits used by Localized GMT format */ |
michael@0 | 692 | UChar32 fGMTOffsetDigits[10]; |
michael@0 | 693 | |
michael@0 | 694 | /* Localized GMT zero format - e.g. "GMT" */ |
michael@0 | 695 | UnicodeString fGMTZeroFormat; |
michael@0 | 696 | |
michael@0 | 697 | /* Bit flags representing parse options */ |
michael@0 | 698 | uint32_t fDefParseOptionFlags; |
michael@0 | 699 | |
michael@0 | 700 | /* Constant parts of GMT format pattern, populated from localized GMT format pattern*/ |
michael@0 | 701 | UnicodeString fGMTPatternPrefix; /* Substring before {0} */ |
michael@0 | 702 | UnicodeString fGMTPatternSuffix; /* Substring after {0} */ |
michael@0 | 703 | |
michael@0 | 704 | /* Compiled offset patterns generated from fGMTOffsetPatterns[] */ |
michael@0 | 705 | UVector* fGMTOffsetPatternItems[UTZFMT_PAT_COUNT]; |
michael@0 | 706 | |
michael@0 | 707 | UBool fAbuttingOffsetHoursAndMinutes; |
michael@0 | 708 | |
michael@0 | 709 | /** |
michael@0 | 710 | * Returns the time zone's specific format string. |
michael@0 | 711 | * @param tz the time zone |
michael@0 | 712 | * @param stdType the name type used for standard time |
michael@0 | 713 | * @param dstType the name type used for daylight time |
michael@0 | 714 | * @param date the date |
michael@0 | 715 | * @param name receives the time zone's specific format name string |
michael@0 | 716 | * @param timeType when null, actual time type is set |
michael@0 | 717 | * @return a reference to name. |
michael@0 | 718 | */ |
michael@0 | 719 | UnicodeString& formatSpecific(const TimeZone& tz, UTimeZoneNameType stdType, UTimeZoneNameType dstType, |
michael@0 | 720 | UDate date, UnicodeString& name, UTimeZoneFormatTimeType *timeType) const; |
michael@0 | 721 | |
michael@0 | 722 | /** |
michael@0 | 723 | * Returns the time zone's generic format string. |
michael@0 | 724 | * @param tz the time zone |
michael@0 | 725 | * @param genType the generic name type |
michael@0 | 726 | * @param date the date |
michael@0 | 727 | * @param name receives the time zone's generic format name string |
michael@0 | 728 | * @return a reference to name. |
michael@0 | 729 | */ |
michael@0 | 730 | UnicodeString& formatGeneric(const TimeZone& tz, int32_t genType, UDate date, UnicodeString& name) const; |
michael@0 | 731 | |
michael@0 | 732 | /** |
michael@0 | 733 | * Lazily create a TimeZoneGenericNames instance |
michael@0 | 734 | * @param status receives the status |
michael@0 | 735 | * @return the cached TimeZoneGenericNames. |
michael@0 | 736 | */ |
michael@0 | 737 | const TimeZoneGenericNames* getTimeZoneGenericNames(UErrorCode& status) const; |
michael@0 | 738 | |
michael@0 | 739 | /** |
michael@0 | 740 | * Private method returning the time zone's exemplar location string. |
michael@0 | 741 | * This method will never return empty. |
michael@0 | 742 | * @param tz the time zone |
michael@0 | 743 | * @param name receives the time zone's exemplar location name |
michael@0 | 744 | * @return a reference to name. |
michael@0 | 745 | */ |
michael@0 | 746 | UnicodeString& formatExemplarLocation(const TimeZone& tz, UnicodeString& name) const; |
michael@0 | 747 | |
michael@0 | 748 | /** |
michael@0 | 749 | * Private enum specifying a combination of offset fields |
michael@0 | 750 | */ |
michael@0 | 751 | enum OffsetFields { |
michael@0 | 752 | FIELDS_H, |
michael@0 | 753 | FIELDS_HM, |
michael@0 | 754 | FIELDS_HMS |
michael@0 | 755 | }; |
michael@0 | 756 | |
michael@0 | 757 | /** |
michael@0 | 758 | * Parses the localized GMT pattern string and initialize |
michael@0 | 759 | * localized gmt pattern fields. |
michael@0 | 760 | * @param gmtPattern the localized GMT pattern string such as "GMT {0}" |
michael@0 | 761 | * @param status U_ILLEGAL_ARGUMENT_ERROR is set when the specified pattern does not |
michael@0 | 762 | * contain an argument "{0}". |
michael@0 | 763 | */ |
michael@0 | 764 | void initGMTPattern(const UnicodeString& gmtPattern, UErrorCode& status); |
michael@0 | 765 | |
michael@0 | 766 | /** |
michael@0 | 767 | * Parse the GMT offset pattern into runtime optimized format. |
michael@0 | 768 | * @param pattern the offset pattern string |
michael@0 | 769 | * @param required the required set of fields, such as FIELDS_HM |
michael@0 | 770 | * @param status U_ILLEGAL_ARGUMENT is set when the specified pattern does not contain |
michael@0 | 771 | * pattern letters for the required fields. |
michael@0 | 772 | * @return A list of GMTOffsetField objects, or NULL on error. |
michael@0 | 773 | */ |
michael@0 | 774 | static UVector* parseOffsetPattern(const UnicodeString& pattern, OffsetFields required, UErrorCode& status); |
michael@0 | 775 | |
michael@0 | 776 | /** |
michael@0 | 777 | * Appends seconds field to the offset pattern with hour/minute |
michael@0 | 778 | * Note: This code will be obsoleted once we add hour-minute-second pattern data in CLDR. |
michael@0 | 779 | * @param offsetHM the offset pattern including hours and minutes fields |
michael@0 | 780 | * @param result the output offset pattern including hour, minute and seconds fields |
michael@0 | 781 | * @param status receives the status |
michael@0 | 782 | * @return a reference to result |
michael@0 | 783 | */ |
michael@0 | 784 | static UnicodeString& expandOffsetPattern(const UnicodeString& offsetHM, UnicodeString& result, UErrorCode& status); |
michael@0 | 785 | |
michael@0 | 786 | /** |
michael@0 | 787 | * Truncates minutes field to the offset pattern with hour/minute |
michael@0 | 788 | * Note: This code will be obsoleted once we add hour pattern data in CLDR. |
michael@0 | 789 | * @param offsetHM the offset pattern including hours and minutes fields |
michael@0 | 790 | * @param result the output offset pattern including only hours field |
michael@0 | 791 | * @param status receives the status |
michael@0 | 792 | * @return a reference to result |
michael@0 | 793 | */ |
michael@0 | 794 | static UnicodeString& truncateOffsetPattern(const UnicodeString& offsetHM, UnicodeString& result, UErrorCode& status); |
michael@0 | 795 | |
michael@0 | 796 | /** |
michael@0 | 797 | * Break input string into UChar32[]. Each array element represents |
michael@0 | 798 | * a code point. This method is used for parsing localized digit |
michael@0 | 799 | * characters and support characters in Unicode supplemental planes. |
michael@0 | 800 | * @param str the string |
michael@0 | 801 | * @param codeArray receives the result |
michael@0 | 802 | * @param capacity the capacity of codeArray |
michael@0 | 803 | * @return TRUE when the specified code array is fully filled with code points |
michael@0 | 804 | * (no under/overflow). |
michael@0 | 805 | */ |
michael@0 | 806 | static UBool toCodePoints(const UnicodeString& str, UChar32* codeArray, int32_t capacity); |
michael@0 | 807 | |
michael@0 | 808 | /** |
michael@0 | 809 | * Private method supprting all of ISO8601 formats |
michael@0 | 810 | * @param offset the offset from GMT(UTC) in milliseconds. |
michael@0 | 811 | * @param useUtcIndicator true if ISO 8601 UTC indicator "Z" is used when the offset is 0. |
michael@0 | 812 | * @param isShort true if shortest form is used. |
michael@0 | 813 | * @param ignoreSeconds true if non-zero offset seconds is appended. |
michael@0 | 814 | * @param result Receives the result |
michael@0 | 815 | * @param status Receives the status |
michael@0 | 816 | * @return the ISO 8601 basic format. |
michael@0 | 817 | */ |
michael@0 | 818 | UnicodeString& formatOffsetISO8601(int32_t offset, UBool isBasic, UBool useUtcIndicator, |
michael@0 | 819 | UBool isShort, UBool ignoreSeconds, UnicodeString& result, UErrorCode& status) const; |
michael@0 | 820 | |
michael@0 | 821 | /** |
michael@0 | 822 | * Private method used for localized GMT formatting. |
michael@0 | 823 | * @param offset the zone's UTC offset |
michael@0 | 824 | * @param isShort true if the short localized GMT format is desired. |
michael@0 | 825 | * @param result receives the localized GMT format string |
michael@0 | 826 | * @param status receives the status |
michael@0 | 827 | */ |
michael@0 | 828 | UnicodeString& formatOffsetLocalizedGMT(int32_t offset, UBool isShort, UnicodeString& result, UErrorCode& status) const; |
michael@0 | 829 | |
michael@0 | 830 | /** |
michael@0 | 831 | * Returns offset from GMT(UTC) in milliseconds for the given ISO 8601 style |
michael@0 | 832 | * (extended format) time zone string. When the given string is not an ISO 8601 time |
michael@0 | 833 | * zone string, this method sets the current position as the error index |
michael@0 | 834 | * to <code>ParsePosition pos</code> and returns 0. |
michael@0 | 835 | * @param text the text contains ISO 8601 style time zone string (e.g. "-08:00", "Z") |
michael@0 | 836 | * at the position. |
michael@0 | 837 | * @param pos the position, non-negative error index will be set on failure. |
michael@0 | 838 | * @param extendedOnly TRUE if parsing the text as ISO 8601 extended offset format (e.g. "-08:00"), |
michael@0 | 839 | * or FALSE to evaluate the text as basic format. |
michael@0 | 840 | * @param hasDigitOffset receiving if the parsed zone string contains offset digits. |
michael@0 | 841 | * @return the offset from GMT(UTC) in milliseconds for the given ISO 8601 style |
michael@0 | 842 | * time zone string. |
michael@0 | 843 | */ |
michael@0 | 844 | int32_t parseOffsetISO8601(const UnicodeString& text, ParsePosition& pos, UBool extendedOnly, |
michael@0 | 845 | UBool* hasDigitOffset = NULL) const; |
michael@0 | 846 | |
michael@0 | 847 | /** |
michael@0 | 848 | * Appends localized digits to the buffer. |
michael@0 | 849 | * This code assumes that the input number is 0 - 59 |
michael@0 | 850 | * @param buf the target buffer |
michael@0 | 851 | * @param n the integer number |
michael@0 | 852 | * @param minDigits the minimum digits width |
michael@0 | 853 | */ |
michael@0 | 854 | void appendOffsetDigits(UnicodeString& buf, int32_t n, uint8_t minDigits) const; |
michael@0 | 855 | |
michael@0 | 856 | /** |
michael@0 | 857 | * Returns offset from GMT(UTC) in milliseconds for the given localized GMT |
michael@0 | 858 | * offset format string. When the given string cannot be parsed, this method |
michael@0 | 859 | * sets the current position as the error index to <code>ParsePosition pos</code> |
michael@0 | 860 | * and returns 0. |
michael@0 | 861 | * @param text the text contains a localized GMT offset string at the position. |
michael@0 | 862 | * @param pos the position, non-negative error index will be set on failure. |
michael@0 | 863 | * @param isShort true if this parser to try the short format first |
michael@0 | 864 | * @param hasDigitOffset receiving if the parsed zone string contains offset digits. |
michael@0 | 865 | * @return the offset from GMT(UTC) in milliseconds for the given localized GMT |
michael@0 | 866 | * offset format string. |
michael@0 | 867 | */ |
michael@0 | 868 | int32_t parseOffsetLocalizedGMT(const UnicodeString& text, ParsePosition& pos, |
michael@0 | 869 | UBool isShort, UBool* hasDigitOffset) const; |
michael@0 | 870 | |
michael@0 | 871 | /** |
michael@0 | 872 | * Parse localized GMT format generated by the patter used by this formatter, except |
michael@0 | 873 | * GMT Zero format. |
michael@0 | 874 | * @param text the input text |
michael@0 | 875 | * @param start the start index |
michael@0 | 876 | * @param isShort true if the short localized format is parsed. |
michael@0 | 877 | * @param parsedLen receives the parsed length |
michael@0 | 878 | * @return the parsed offset in milliseconds |
michael@0 | 879 | */ |
michael@0 | 880 | int32_t parseOffsetLocalizedGMTPattern(const UnicodeString& text, int32_t start, |
michael@0 | 881 | UBool isShort, int32_t& parsedLen) const; |
michael@0 | 882 | |
michael@0 | 883 | /** |
michael@0 | 884 | * Parses localized GMT offset fields into offset. |
michael@0 | 885 | * @param text the input text |
michael@0 | 886 | * @param start the start index |
michael@0 | 887 | * @param isShort true if this is a short format - currently not used |
michael@0 | 888 | * @param parsedLen the parsed length, or 0 on failure. |
michael@0 | 889 | * @return the parsed offset in milliseconds. |
michael@0 | 890 | */ |
michael@0 | 891 | int32_t parseOffsetFields(const UnicodeString& text, int32_t start, UBool isShort, int32_t& parsedLen) const; |
michael@0 | 892 | |
michael@0 | 893 | /** |
michael@0 | 894 | * Parse localized GMT offset fields with the given pattern. |
michael@0 | 895 | * @param text the input text |
michael@0 | 896 | * @param start the start index |
michael@0 | 897 | * @param pattenItems the pattern (already itemized) |
michael@0 | 898 | * @param forceSingleHourDigit true if hours field is parsed as a single digit |
michael@0 | 899 | * @param hour receives the hour offset field |
michael@0 | 900 | * @param min receives the minute offset field |
michael@0 | 901 | * @param sec receives the second offset field |
michael@0 | 902 | * @return the parsed length |
michael@0 | 903 | */ |
michael@0 | 904 | int32_t parseOffsetFieldsWithPattern(const UnicodeString& text, int32_t start, |
michael@0 | 905 | UVector* patternItems, UBool forceSingleHourDigit, int32_t& hour, int32_t& min, int32_t& sec) const; |
michael@0 | 906 | |
michael@0 | 907 | /** |
michael@0 | 908 | * Parses abutting localized GMT offset fields (such as 0800) into offset. |
michael@0 | 909 | * @param text the input text |
michael@0 | 910 | * @param start the start index |
michael@0 | 911 | * @param parsedLen the parsed length, or 0 on failure |
michael@0 | 912 | * @return the parsed offset in milliseconds. |
michael@0 | 913 | */ |
michael@0 | 914 | int32_t parseAbuttingOffsetFields(const UnicodeString& text, int32_t start, int32_t& parsedLen) const; |
michael@0 | 915 | |
michael@0 | 916 | /** |
michael@0 | 917 | * Parses the input text using the default format patterns (e.g. "UTC{0}"). |
michael@0 | 918 | * @param text the input text |
michael@0 | 919 | * @param start the start index |
michael@0 | 920 | * @param parsedLen the parsed length, or 0 on failure |
michael@0 | 921 | * @return the parsed offset in milliseconds. |
michael@0 | 922 | */ |
michael@0 | 923 | int32_t parseOffsetDefaultLocalizedGMT(const UnicodeString& text, int start, int32_t& parsedLen) const; |
michael@0 | 924 | |
michael@0 | 925 | /** |
michael@0 | 926 | * Parses the input GMT offset fields with the default offset pattern. |
michael@0 | 927 | * @param text the input text |
michael@0 | 928 | * @param start the start index |
michael@0 | 929 | * @param separator the separator character, e.g. ':' |
michael@0 | 930 | * @param parsedLen the parsed length, or 0 on failure. |
michael@0 | 931 | * @return the parsed offset in milliseconds. |
michael@0 | 932 | */ |
michael@0 | 933 | int32_t parseDefaultOffsetFields(const UnicodeString& text, int32_t start, UChar separator, |
michael@0 | 934 | int32_t& parsedLen) const; |
michael@0 | 935 | |
michael@0 | 936 | /** |
michael@0 | 937 | * Reads an offset field value. This method will stop parsing when |
michael@0 | 938 | * 1) number of digits reaches <code>maxDigits</code> |
michael@0 | 939 | * 2) just before already parsed number exceeds <code>maxVal</code> |
michael@0 | 940 | * |
michael@0 | 941 | * @param text the text |
michael@0 | 942 | * @param start the start offset |
michael@0 | 943 | * @param minDigits the minimum number of required digits |
michael@0 | 944 | * @param maxDigits the maximum number of digits |
michael@0 | 945 | * @param minVal the minimum value |
michael@0 | 946 | * @param maxVal the maximum value |
michael@0 | 947 | * @param parsedLen the actual parsed length. |
michael@0 | 948 | * @return the integer value parsed |
michael@0 | 949 | */ |
michael@0 | 950 | int32_t parseOffsetFieldWithLocalizedDigits(const UnicodeString& text, int32_t start, |
michael@0 | 951 | uint8_t minDigits, uint8_t maxDigits, uint16_t minVal, uint16_t maxVal, int32_t& parsedLen) const; |
michael@0 | 952 | |
michael@0 | 953 | /** |
michael@0 | 954 | * Reads a single decimal digit, either localized digits used by this object |
michael@0 | 955 | * or any Unicode numeric character. |
michael@0 | 956 | * @param text the text |
michael@0 | 957 | * @param start the start index |
michael@0 | 958 | * @param len the actual length read from the text |
michael@0 | 959 | * the start index is not a decimal number. |
michael@0 | 960 | * @return the integer value of the parsed digit, or -1 on failure. |
michael@0 | 961 | */ |
michael@0 | 962 | int32_t parseSingleLocalizedDigit(const UnicodeString& text, int32_t start, int32_t& len) const; |
michael@0 | 963 | |
michael@0 | 964 | /** |
michael@0 | 965 | * Formats offset using ASCII digits. The input offset range must be |
michael@0 | 966 | * within +/-24 hours (exclusive). |
michael@0 | 967 | * @param offset The offset |
michael@0 | 968 | * @param sep The field separator character or 0 if not required |
michael@0 | 969 | * @param minFields The minimum fields |
michael@0 | 970 | * @param maxFields The maximum fields |
michael@0 | 971 | * @return The offset string |
michael@0 | 972 | */ |
michael@0 | 973 | static UnicodeString& formatOffsetWithAsciiDigits(int32_t offset, UChar sep, |
michael@0 | 974 | OffsetFields minFields, OffsetFields maxFields, UnicodeString& result); |
michael@0 | 975 | |
michael@0 | 976 | /** |
michael@0 | 977 | * Parses offset represented by contiguous ASCII digits. |
michael@0 | 978 | * <p> |
michael@0 | 979 | * Note: This method expects the input position is already at the start of |
michael@0 | 980 | * ASCII digits and does not parse sign (+/-). |
michael@0 | 981 | * @param text The text contains a sequence of ASCII digits |
michael@0 | 982 | * @param pos The parse position |
michael@0 | 983 | * @param minFields The minimum Fields to be parsed |
michael@0 | 984 | * @param maxFields The maximum Fields to be parsed |
michael@0 | 985 | * @param fixedHourWidth true if hours field must be width of 2 |
michael@0 | 986 | * @return Parsed offset, 0 or positive number. |
michael@0 | 987 | */ |
michael@0 | 988 | static int32_t parseAbuttingAsciiOffsetFields(const UnicodeString& text, ParsePosition& pos, |
michael@0 | 989 | OffsetFields minFields, OffsetFields maxFields, UBool fixedHourWidth); |
michael@0 | 990 | |
michael@0 | 991 | /** |
michael@0 | 992 | * Parses offset represented by ASCII digits and separators. |
michael@0 | 993 | * <p> |
michael@0 | 994 | * Note: This method expects the input position is already at the start of |
michael@0 | 995 | * ASCII digits and does not parse sign (+/-). |
michael@0 | 996 | * @param text The text |
michael@0 | 997 | * @param pos The parse position |
michael@0 | 998 | * @param sep The separator character |
michael@0 | 999 | * @param minFields The minimum Fields to be parsed |
michael@0 | 1000 | * @param maxFields The maximum Fields to be parsed |
michael@0 | 1001 | * @return Parsed offset, 0 or positive number. |
michael@0 | 1002 | */ |
michael@0 | 1003 | static int32_t parseAsciiOffsetFields(const UnicodeString& text, ParsePosition& pos, UChar sep, |
michael@0 | 1004 | OffsetFields minFields, OffsetFields maxFields); |
michael@0 | 1005 | |
michael@0 | 1006 | /** |
michael@0 | 1007 | * Unquotes the message format style pattern. |
michael@0 | 1008 | * @param pattern the pattern |
michael@0 | 1009 | * @param result receive the unquoted pattern. |
michael@0 | 1010 | * @return A reference to result. |
michael@0 | 1011 | */ |
michael@0 | 1012 | static UnicodeString& unquote(const UnicodeString& pattern, UnicodeString& result); |
michael@0 | 1013 | |
michael@0 | 1014 | /** |
michael@0 | 1015 | * Initialize localized GMT format offset hour/min/sec patterns. |
michael@0 | 1016 | * This method parses patterns into optimized run-time format. |
michael@0 | 1017 | * @param status receives the status. |
michael@0 | 1018 | */ |
michael@0 | 1019 | void initGMTOffsetPatterns(UErrorCode& status); |
michael@0 | 1020 | |
michael@0 | 1021 | /** |
michael@0 | 1022 | * Check if there are any GMT format offset patterns without |
michael@0 | 1023 | * any separators between hours field and minutes field and update |
michael@0 | 1024 | * fAbuttingOffsetHoursAndMinutes field. This method must be called |
michael@0 | 1025 | * after all patterns are parsed into pattern items. |
michael@0 | 1026 | */ |
michael@0 | 1027 | void checkAbuttingHoursAndMinutes(); |
michael@0 | 1028 | |
michael@0 | 1029 | /** |
michael@0 | 1030 | * Creates an instance of TimeZone for the given offset |
michael@0 | 1031 | * @param offset the offset |
michael@0 | 1032 | * @return A TimeZone with the given offset |
michael@0 | 1033 | */ |
michael@0 | 1034 | TimeZone* createTimeZoneForOffset(int32_t offset) const; |
michael@0 | 1035 | |
michael@0 | 1036 | /** |
michael@0 | 1037 | * Returns the time type for the given name type |
michael@0 | 1038 | * @param nameType the name type |
michael@0 | 1039 | * @return the time type (unknown/standard/daylight) |
michael@0 | 1040 | */ |
michael@0 | 1041 | static UTimeZoneFormatTimeType getTimeType(UTimeZoneNameType nameType); |
michael@0 | 1042 | |
michael@0 | 1043 | /** |
michael@0 | 1044 | * Returns the time zone ID of a match at the specified index within |
michael@0 | 1045 | * the MatchInfoCollection. |
michael@0 | 1046 | * @param matches the collection of matches |
michael@0 | 1047 | * @param idx the index withing matches |
michael@0 | 1048 | * @param tzID receives the resolved time zone ID |
michael@0 | 1049 | * @return a reference to tzID. |
michael@0 | 1050 | */ |
michael@0 | 1051 | UnicodeString& getTimeZoneID(const TimeZoneNames::MatchInfoCollection* matches, int32_t idx, UnicodeString& tzID) const; |
michael@0 | 1052 | |
michael@0 | 1053 | |
michael@0 | 1054 | /** |
michael@0 | 1055 | * Parse a zone ID. |
michael@0 | 1056 | * @param text the text contains a time zone ID string at the position. |
michael@0 | 1057 | * @param pos the position |
michael@0 | 1058 | * @param tzID receives the zone ID |
michael@0 | 1059 | * @return a reference to tzID |
michael@0 | 1060 | */ |
michael@0 | 1061 | UnicodeString& parseZoneID(const UnicodeString& text, ParsePosition& pos, UnicodeString& tzID) const; |
michael@0 | 1062 | |
michael@0 | 1063 | /** |
michael@0 | 1064 | * Parse a short zone ID. |
michael@0 | 1065 | * @param text the text contains a short time zone ID string at the position. |
michael@0 | 1066 | * @param pos the position |
michael@0 | 1067 | * @param tzID receives the short zone ID |
michael@0 | 1068 | * @return a reference to tzID |
michael@0 | 1069 | */ |
michael@0 | 1070 | UnicodeString& parseShortZoneID(const UnicodeString& text, ParsePosition& pos, UnicodeString& tzID) const; |
michael@0 | 1071 | |
michael@0 | 1072 | /** |
michael@0 | 1073 | * Parse an exemplar location string. |
michael@0 | 1074 | * @param text the text contains an exemplar location string at the position. |
michael@0 | 1075 | * @param pos the position. |
michael@0 | 1076 | * @param tzID receives the time zone ID |
michael@0 | 1077 | * @return a reference to tzID |
michael@0 | 1078 | */ |
michael@0 | 1079 | UnicodeString& parseExemplarLocation(const UnicodeString& text, ParsePosition& pos, UnicodeString& tzID) const; |
michael@0 | 1080 | }; |
michael@0 | 1081 | |
michael@0 | 1082 | U_NAMESPACE_END |
michael@0 | 1083 | |
michael@0 | 1084 | #endif /* !UCONFIG_NO_FORMATTING */ |
michael@0 | 1085 | #endif |