TimeZoneFormat
265 * ICU implements the time zone display names defined by UTS#35 266 * Unicode Locale Data Markup Language (LDML). {@link TimeZoneNames} represents the 267 * time zone display name data model and this class implements the algorithm for actual 268 * formatting and parsing. 269 * 270 * @see SimpleDateFormat 271 * @see TimeZoneNames 272 * @stable ICU 50 273 */ 274 class U_I18N_API TimeZoneFormat : public Format { 275 public: 276 /** 277 * Copy constructor. 278 * @stable ICU 50 279 */ 280 TimeZoneFormat(const TimeZoneFormat& other); 281 282 /** 283 * Destructor. 284 * @stable ICU 50 285 */ 286 virtual ~TimeZoneFormat(); 287 288 /** 289 * Assignment operator. 290 * @stable ICU 50 291 */ 292 TimeZoneFormat& operator=(const TimeZoneFormat& other); 293 294 /** 295 * Return true if the given Format objects are semantically equal. 296 * Objects of different subclasses are considered unequal. 297 * @param other The object to be compared with. 298 * @return Return true if the given Format objects are semantically equal. 299 * Objects of different subclasses are considered unequal. 300 * @stable ICU 50 301 */ 302 virtual bool operator==(const Format& other) const override; 303 304 /** 305 * Clone this object polymorphically. The caller is responsible 306 * for deleting the result when done. 307 * @return A copy of the object 308 * @stable ICU 50 309 */ 310 virtual TimeZoneFormat* clone() const override; 311 312 /** 313 * Creates an instance of TimeZoneFormat for the given locale. 314 * @param locale The locale. 315 * @param status Receives the status. 316 * @return An instance of TimeZoneFormat for the given locale, 317 * owned by the caller. 318 * @stable ICU 50 319 */ 320 static TimeZoneFormat* U_EXPORT2 createInstance(const Locale& locale, UErrorCode& status); 321 322 /** 323 * Returns the time zone display name data used by this instance. 324 * @return The time zone display name data. 325 * @stable ICU 50 326 */ 327 const TimeZoneNames* getTimeZoneNames() const; 328 329 /** 330 * Sets the time zone display name data to this format instance. 331 * The caller should not delete the TimeZoenNames object after it is adopted 332 * by this call. 333 * @param tznames TimeZoneNames object to be adopted. 334 * @stable ICU 50 335 */ 336 void adoptTimeZoneNames(TimeZoneNames *tznames); 337 338 /** 339 * Sets the time zone display name data to this format instance. 340 * @param tznames TimeZoneNames object to be set. 341 * @stable ICU 50 342 */ 343 void setTimeZoneNames(const TimeZoneNames &tznames); 344 345 /** 346 * Returns the localized GMT format pattern. 347 * @param pattern Receives the localized GMT format pattern. 348 * @return A reference to the result pattern. 349 * @see #setGMTPattern 350 * @stable ICU 50 351 */ 352 UnicodeString& getGMTPattern(UnicodeString& pattern) const; 353 354 /** 355 * Sets the localized GMT format pattern. The pattern must contain 356 * a single argument {0}, for example "GMT {0}". 357 * @param pattern The localized GMT format pattern to be used by this object. 358 * @param status Receives the status. 359 * @see #getGMTPattern 360 * @stable ICU 50 361 */ 362 void setGMTPattern(const UnicodeString& pattern, UErrorCode& status); 363 364 /** 365 * Returns the offset pattern used for localized GMT format. 366 * @param type The offset pattern type enum. 367 * @param pattern Receives the offset pattern. 368 * @return A reference to the result pattern. 369 * @see #setGMTOffsetPattern 370 * @stable ICU 50 371 */ 372 UnicodeString& getGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, UnicodeString& pattern) const; 373 374 /** 375 * Sets the offset pattern for the given offset type. 376 * @param type The offset pattern type enum. 377 * @param pattern The offset pattern used for localized GMT format for the type. 378 * @param status Receives the status. 379 * @see #getGMTOffsetPattern 380 * @stable ICU 50 381 */ 382 void setGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, const UnicodeString& pattern, UErrorCode& status); 383 384 /** 385 * Returns the decimal digit characters used for localized GMT format. 386 * The return string contains exactly 10 code points (may include Unicode 387 * supplementary character) representing digit 0 to digit 9 in the ascending 388 * order. 389 * @param digits Receives the decimal digits used for localized GMT format. 390 * @see #setGMTOffsetDigits 391 * @stable ICU 50 392 */ 393 UnicodeString& getGMTOffsetDigits(UnicodeString& digits) const; 394 395 /** 396 * Sets the decimal digit characters used for localized GMT format. 397 * The input digits must contain exactly 10 code points 398 * (Unicode supplementary characters are also allowed) representing 399 * digit 0 to digit 9 in the ascending order. When the input digits 400 * does not satisfy the condition, U_ILLEGAL_ARGUMENT_ERROR 401 * will be set to the return status. 402 * @param digits The decimal digits used for localized GMT format. 403 * @param status Receives the status. 404 * @see #getGMTOffsetDigits 405 * @stable ICU 50 406 */ 407 void setGMTOffsetDigits(const UnicodeString& digits, UErrorCode& status); 408 409 /** 410 * Returns the localized GMT format string for GMT(UTC) itself (GMT offset is 0). 411 * @param gmtZeroFormat Receives the localized GMT string string for GMT(UTC) itself. 412 * @return A reference to the result GMT string. 413 * @see #setGMTZeroFormat 414 * @stable ICU 50 415 */ 416 UnicodeString& getGMTZeroFormat(UnicodeString& gmtZeroFormat) const; 417 418 /** 419 * Sets the localized GMT format string for GMT(UTC) itself (GMT offset is 0). 420 * @param gmtZeroFormat The localized GMT format string for GMT(UTC). 421 * @param status Receives the status. 422 * @see #getGMTZeroFormat 423 * @stable ICU 50 424 */ 425 void setGMTZeroFormat(const UnicodeString& gmtZeroFormat, UErrorCode& status); 426 427 /** 428 * Returns the bitwise flags of UTimeZoneFormatParseOption representing the default parse 429 * options used by this object. 430 * @return the default parse options. 431 * @see ParseOption 432 * @stable ICU 50 433 */ 434 uint32_t getDefaultParseOptions(void) const; 435 436 /** 437 * Sets the default parse options. 438 *
digits
U_ILLEGAL_ARGUMENT_ERROR
Note: By default, an instance of TimeZoneFormat 439 * created by {@link #createInstance} has no parse options set (UTZFMT_PARSE_OPTION_NONE). 440 * To specify multiple options, use bitwise flags of UTimeZoneFormatParseOption. 441 * @see #UTimeZoneFormatParseOption 442 * @stable ICU 50 443 */ 444 void setDefaultParseOptions(uint32_t flags); 445 446 /** 447 * Returns the ISO 8601 basic time zone string for the given offset. 448 * For example, "-08", "-0830" and "Z" 449 * 450 * @param offset the offset from GMT(UTC) in milliseconds. 451 * @param useUtcIndicator true if ISO 8601 UTC indicator "Z" is used when the offset is 0. 452 * @param isShort true if shortest form is used. 453 * @param ignoreSeconds true if non-zero offset seconds is appended. 454 * @param result Receives the ISO format string. 455 * @param status Receives the status 456 * @return the ISO 8601 basic format. 457 * @see #formatOffsetISO8601Extended 458 * @see #parseOffsetISO8601 459 * @stable ICU 51 460 */ 461 UnicodeString& formatOffsetISO8601Basic(int32_t offset, UBool useUtcIndicator, UBool isShort, UBool ignoreSeconds, 462 UnicodeString& result, UErrorCode& status) const; 463 464 /** 465 * Returns the ISO 8601 extended time zone string for the given offset. 466 * For example, "-08:00", "-08:30" and "Z" 467 * 468 * @param offset the offset from GMT(UTC) in milliseconds. 469 * @param useUtcIndicator true if ISO 8601 UTC indicator "Z" is used when the offset is 0. 470 * @param isShort true if shortest form is used. 471 * @param ignoreSeconds true if non-zero offset seconds is appended. 472 * @param result Receives the ISO format string. 473 * @param status Receives the status 474 * @return the ISO 8601 basic format. 475 * @see #formatOffsetISO8601Extended 476 * @see #parseOffsetISO8601 477 * @stable ICU 51 478 */ 479 UnicodeString& formatOffsetISO8601Extended(int32_t offset, UBool useUtcIndicator, UBool isShort, UBool ignoreSeconds, 480 UnicodeString& result, UErrorCode& status) const; 481 482 /** 483 * Returns the localized GMT(UTC) offset format for the given offset. 484 * The localized GMT offset is defined by; 485 *
UTZFMT_STYLE_GENERIC_LONG
UTZFMT_STYLE_LOCALIZED_GMT
ParsePosition pos
TimeZone
maxDigits
maxVal
993 * Note: This method expects the input position is already at the start of 994 * ASCII digits and does not parse sign (+/-). 995 * @param text The text contains a sequence of ASCII digits 996 * @param pos The parse position 997 * @param minFields The minimum Fields to be parsed 998 * @param maxFields The maximum Fields to be parsed 999 * @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 *
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