ICU 63.1 63.1

tzfmt.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 *******************************************************************************
5 * Copyright (C) 2011-2015, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 *******************************************************************************
8 */
9 #ifndef __TZFMT_H
10 #define __TZFMT_H
11
17 #include "unicode/utypes.h"
18
19 #if !UCONFIG_NO_FORMATTING
20
21 #include "unicode/format.h"
22 #include "unicode/timezone.h"
23 #include "unicode/tznames.h"
24
25 U_CDECL_BEGIN
31 typedef enum UTimeZoneFormatStyle {
36 UTZFMT_STYLE_GENERIC_LOCATION,
41 UTZFMT_STYLE_GENERIC_LONG,
46 UTZFMT_STYLE_GENERIC_SHORT,
51 UTZFMT_STYLE_SPECIFIC_LONG,
56 UTZFMT_STYLE_SPECIFIC_SHORT,
61 UTZFMT_STYLE_LOCALIZED_GMT,
67 UTZFMT_STYLE_LOCALIZED_GMT_SHORT,
74 UTZFMT_STYLE_ISO_BASIC_SHORT,
81 UTZFMT_STYLE_ISO_BASIC_LOCAL_SHORT,
88 UTZFMT_STYLE_ISO_BASIC_FIXED,
95 UTZFMT_STYLE_ISO_BASIC_LOCAL_FIXED,
102 UTZFMT_STYLE_ISO_BASIC_FULL,
109 UTZFMT_STYLE_ISO_BASIC_LOCAL_FULL,
116 UTZFMT_STYLE_ISO_EXTENDED_FIXED,
123 UTZFMT_STYLE_ISO_EXTENDED_LOCAL_FIXED,
130 UTZFMT_STYLE_ISO_EXTENDED_FULL,
137 UTZFMT_STYLE_ISO_EXTENDED_LOCAL_FULL,
142 UTZFMT_STYLE_ZONE_ID,
147 UTZFMT_STYLE_ZONE_ID_SHORT,
152 UTZFMT_STYLE_EXEMPLAR_LOCATION
153 } UTimeZoneFormatStyle;
154
159 typedef enum UTimeZoneFormatGMTOffsetPatternType {
164 UTZFMT_PAT_POSITIVE_HM,
169 UTZFMT_PAT_POSITIVE_HMS,
174 UTZFMT_PAT_NEGATIVE_HM,
179 UTZFMT_PAT_NEGATIVE_HMS,
184 UTZFMT_PAT_POSITIVE_H,
189 UTZFMT_PAT_NEGATIVE_H,
190
191 /* The following cannot be #ifndef U_HIDE_INTERNAL_API, needed for other .h declarations */
196 UTZFMT_PAT_COUNT = 6
197 } UTimeZoneFormatGMTOffsetPatternType;
198
204 typedef enum UTimeZoneFormatTimeType {
209 UTZFMT_TIME_TYPE_UNKNOWN,
214 UTZFMT_TIME_TYPE_STANDARD,
219 UTZFMT_TIME_TYPE_DAYLIGHT
220 } UTimeZoneFormatTimeType;
221
226 typedef enum UTimeZoneFormatParseOption {
231 UTZFMT_PARSE_OPTION_NONE = 0x00,
238 UTZFMT_PARSE_OPTION_ALL_STYLES = 0x01,
246 UTZFMT_PARSE_OPTION_TZ_DATABASE_ABBREVIATIONS = 0x02
247 } UTimeZoneFormatParseOption;
248
249 U_CDECL_END
250
251 U_NAMESPACE_BEGIN
252
253 class TimeZoneGenericNames;
254 class TZDBTimeZoneNames;
255 class UVector;
256
272 class U_I18N_API TimeZoneFormat : public Format {
273 public:
278 TimeZoneFormat(const TimeZoneFormat& other);
279
284 virtual ~TimeZoneFormat();
285
290 TimeZoneFormat& operator=(const TimeZoneFormat& other);
291
300 virtual UBool operator==(const Format& other) const;
301
308 virtual Format* clone() const;
309
318 static TimeZoneFormat* U_EXPORT2 createInstance(const Locale& locale, UErrorCode& status);
319
325 const TimeZoneNames* getTimeZoneNames() const;
326
334 void adoptTimeZoneNames(TimeZoneNames *tznames);
335
341 void setTimeZoneNames(const TimeZoneNames &tznames);
342
350 UnicodeString& getGMTPattern(UnicodeString& pattern) const;
351
360 void setGMTPattern(const UnicodeString& pattern, UErrorCode& status);
361
370 UnicodeString& getGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, UnicodeString& pattern) const;
371
380 void setGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, const UnicodeString& pattern, UErrorCode& status);
381
391 UnicodeString& getGMTOffsetDigits(UnicodeString& digits) const;
392
405 void setGMTOffsetDigits(const UnicodeString& digits, UErrorCode& status);
406
414 UnicodeString& getGMTZeroFormat(UnicodeString& gmtZeroFormat) const;
415
423 void setGMTZeroFormat(const UnicodeString& gmtZeroFormat, UErrorCode& status);
424
432 uint32_t getDefaultParseOptions(void) const;
433
442 void setDefaultParseOptions(uint32_t flags);
443
459 UnicodeString& formatOffsetISO8601Basic(int32_t offset, UBool useUtcIndicator, UBool isShort, UBool ignoreSeconds,
460 UnicodeString& result, UErrorCode& status) const;
461
477 UnicodeString& formatOffsetISO8601Extended(int32_t offset, UBool useUtcIndicator, UBool isShort, UBool ignoreSeconds,
478 UnicodeString& result, UErrorCode& status) const;
479
499 UnicodeString& formatOffsetLocalizedGMT(int32_t offset, UnicodeString& result, UErrorCode& status) const;
500
520 UnicodeString& formatOffsetShortLocalizedGMT(int32_t offset, UnicodeString& result, UErrorCode& status) const;
521
522 using Format::format;
523
537 virtual UnicodeString& format(UTimeZoneFormatStyle style, const TimeZone& tz, UDate date,
538 UnicodeString& name, UTimeZoneFormatTimeType* timeType = NULL) const;
539
554 int32_t parseOffsetISO8601(const UnicodeString& text, ParsePosition& pos) const;
555
568 int32_t parseOffsetLocalizedGMT(const UnicodeString& text, ParsePosition& pos) const;
569
582 int32_t parseOffsetShortLocalizedGMT(const UnicodeString& text, ParsePosition& pos) const;
583
600 virtual TimeZone* parse(UTimeZoneFormatStyle style, const UnicodeString& text, ParsePosition& pos,
601 int32_t parseOptions, UTimeZoneFormatTimeType* timeType = NULL) const;
602
618 TimeZone* parse(UTimeZoneFormatStyle style, const UnicodeString& text, ParsePosition& pos,
619 UTimeZoneFormatTimeType* timeType = NULL) const;
620
621 /* ----------------------------------------------
622 * Format APIs
623 * ---------------------------------------------- */
624
636 virtual UnicodeString& format(const Formattable& obj, UnicodeString& appendTo,
637 FieldPosition& pos, UErrorCode& status) const;
638
651 virtual void parseObject(const UnicodeString& source, Formattable& result, ParsePosition& parse_pos) const;
652
657 static UClassID U_EXPORT2 getStaticClassID(void);
658
663 virtual UClassID getDynamicClassID() const;
664
665 protected:
672 TimeZoneFormat(const Locale& locale, UErrorCode& status);
673
674 private:
675 /* Locale of this object */
676 Locale fLocale;
677
678 /* Stores the region (could be implicit default) */
679 char fTargetRegion[ULOC_COUNTRY_CAPACITY];
680
681 /* TimeZoneNames object used by this formatter */
682 TimeZoneNames* fTimeZoneNames;
683
684 /* TimeZoneGenericNames object used by this formatter - lazily instantiated */
685 TimeZoneGenericNames* fTimeZoneGenericNames;
686
687 /* Localized GMT format pattern - e.g. "GMT{0}" */
688 UnicodeString fGMTPattern;
689
690 /* Array of offset patterns used by Localized GMT format - e.g. "+HH:mm" */
691 UnicodeString fGMTOffsetPatterns[UTZFMT_PAT_COUNT];
692
693 /* Localized decimal digits used by Localized GMT format */
694 UChar32 fGMTOffsetDigits[10];
695
696 /* Localized GMT zero format - e.g. "GMT" */
697 UnicodeString fGMTZeroFormat;
698
699 /* Bit flags representing parse options */
700 uint32_t fDefParseOptionFlags;
701
702 /* Constant parts of GMT format pattern, populated from localized GMT format pattern*/
703 UnicodeString fGMTPatternPrefix; /* Substring before {0} */
704 UnicodeString fGMTPatternSuffix; /* Substring after {0} */
705
706 /* Compiled offset patterns generated from fGMTOffsetPatterns[] */
707 UVector* fGMTOffsetPatternItems[UTZFMT_PAT_COUNT];
708
709 UBool fAbuttingOffsetHoursAndMinutes;
710
711 /* TZDBTimeZoneNames object used for parsing */
712 TZDBTimeZoneNames* fTZDBTimeZoneNames;
713
724 UnicodeString& formatSpecific(const TimeZone& tz, UTimeZoneNameType stdType, UTimeZoneNameType dstType,
725 UDate date, UnicodeString& name, UTimeZoneFormatTimeType *timeType) const;
726
735 UnicodeString& formatGeneric(const TimeZone& tz, int32_t genType, UDate date, UnicodeString& name) const;
736
742 const TimeZoneGenericNames* getTimeZoneGenericNames(UErrorCode& status) const;
743
749 const TZDBTimeZoneNames* getTZDBTimeZoneNames(UErrorCode& status) const;
750
758 UnicodeString& formatExemplarLocation(const TimeZone& tz, UnicodeString& name) const;
759
763 enum OffsetFields {
764 FIELDS_H,
765 FIELDS_HM,
766 FIELDS_HMS
767 };
768
776 void initGMTPattern(const UnicodeString& gmtPattern, UErrorCode& status);
777
786 static UVector* parseOffsetPattern(const UnicodeString& pattern, OffsetFields required, UErrorCode& status);
787
796 static UnicodeString& expandOffsetPattern(const UnicodeString& offsetHM, UnicodeString& result, UErrorCode& status);
797
806 static UnicodeString& truncateOffsetPattern(const UnicodeString& offsetHM, UnicodeString& result, UErrorCode& status);
807
818 static UBool toCodePoints(const UnicodeString& str, UChar32* codeArray, int32_t capacity);
819
830 UnicodeString& formatOffsetISO8601(int32_t offset, UBool isBasic, UBool useUtcIndicator,
831 UBool isShort, UBool ignoreSeconds, UnicodeString& result, UErrorCode& status) const;
832
840 UnicodeString& formatOffsetLocalizedGMT(int32_t offset, UBool isShort, UnicodeString& result, UErrorCode& status) const;
841
856 int32_t parseOffsetISO8601(const UnicodeString& text, ParsePosition& pos, UBool extendedOnly,
857 UBool* hasDigitOffset = NULL) const;
858
866 void appendOffsetDigits(UnicodeString& buf, int32_t n, uint8_t minDigits) const;
867
880 int32_t parseOffsetLocalizedGMT(const UnicodeString& text, ParsePosition& pos,
881 UBool isShort, UBool* hasDigitOffset) const;
882
892 int32_t parseOffsetLocalizedGMTPattern(const UnicodeString& text, int32_t start,
893 UBool isShort, int32_t& parsedLen) const;
894
903 int32_t parseOffsetFields(const UnicodeString& text, int32_t start, UBool isShort, int32_t& parsedLen) const;
904
916 int32_t parseOffsetFieldsWithPattern(const UnicodeString& text, int32_t start,
917 UVector* patternItems, UBool forceSingleHourDigit, int32_t& hour, int32_t& min, int32_t& sec) const;
918
926 int32_t parseAbuttingOffsetFields(const UnicodeString& text, int32_t start, int32_t& parsedLen) const;
927
935 int32_t parseOffsetDefaultLocalizedGMT(const UnicodeString& text, int start, int32_t& parsedLen) const;
936
945 int32_t parseDefaultOffsetFields(const UnicodeString& text, int32_t start, char16_t separator,
946 int32_t& parsedLen) const;
947
962 int32_t parseOffsetFieldWithLocalizedDigits(const UnicodeString& text, int32_t start,
963 uint8_t minDigits, uint8_t maxDigits, uint16_t minVal, uint16_t maxVal, int32_t& parsedLen) const;
964
974 int32_t parseSingleLocalizedDigit(const UnicodeString& text, int32_t start, int32_t& len) const;
975
985 static UnicodeString& formatOffsetWithAsciiDigits(int32_t offset, char16_t sep,
986 OffsetFields minFields, OffsetFields maxFields, UnicodeString& result);
987
1000 static int32_t parseAbuttingAsciiOffsetFields(const UnicodeString& text, ParsePosition& pos,
1001 OffsetFields minFields, OffsetFields maxFields, UBool fixedHourWidth);
1002
1015 static int32_t parseAsciiOffsetFields(const UnicodeString& text, ParsePosition& pos, char16_t sep,
1016 OffsetFields minFields, OffsetFields maxFields);
1017
1024 static UnicodeString& unquote(const UnicodeString& pattern, UnicodeString& result);
1025
1031 void initGMTOffsetPatterns(UErrorCode& status);
1032
1039 void checkAbuttingHoursAndMinutes();
1040
1046 TimeZone* createTimeZoneForOffset(int32_t offset) const;
1047
1053 static UTimeZoneFormatTimeType getTimeType(UTimeZoneNameType nameType);
1054
1063 UnicodeString& getTimeZoneID(const TimeZoneNames::MatchInfoCollection* matches, int32_t idx, UnicodeString& tzID) const;
1064
1065
1073 UnicodeString& parseZoneID(const UnicodeString& text, ParsePosition& pos, UnicodeString& tzID) const;
1074
1082 UnicodeString& parseShortZoneID(const UnicodeString& text, ParsePosition& pos, UnicodeString& tzID) const;
1083
1091 UnicodeString& parseExemplarLocation(const UnicodeString& text, ParsePosition& pos, UnicodeString& tzID) const;
1092 };
1093
1094 U_NAMESPACE_END
1095
1096 #endif /* !UCONFIG_NO_FORMATTING */
1097 #endif
UTZFMT_PARSE_OPTION_ALL_STYLES
When a time zone display name is not found within a set of display names used for the specified style...
Definition: tzfmt.h:238
icu::Format
Base class for all formats.
Definition: format.h:96
UTimeZoneFormatGMTOffsetPatternType
UTimeZoneFormatGMTOffsetPatternType
Constants for GMT offset pattern types.
Definition: tzfmt.h:159
UTZFMT_PAT_NEGATIVE_HM
Negative offset with hours and minutes fields.
Definition: tzfmt.h:174
icu::TimeZoneFormat
TimeZoneFormat supports time zone display name formatting and parsing.
Definition: tzfmt.h:272
UTZFMT_STYLE_ISO_BASIC_FIXED
Fixed width ISO 8601 local time difference (basic format) or the UTC indicator.
Definition: tzfmt.h:88
UTZFMT_STYLE_ISO_BASIC_LOCAL_FULL
ISO 8601 local time difference (basic format) with optional seconds field.
Definition: tzfmt.h:109
UTimeZoneFormatParseOption
UTimeZoneFormatParseOption
Constants for parse option flags, used for specifying optional parse behavior.
Definition: tzfmt.h:226
UTZFMT_PAT_NEGATIVE_H
Negative offset with hours field.
Definition: tzfmt.h:189
UTimeZoneFormatTimeType
UTimeZoneFormatTimeType
Constants for time types used by TimeZoneFormat APIs for receiving time type (standard time...
Definition: tzfmt.h:204
icu::Format::format
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
UTZFMT_STYLE_GENERIC_LOCATION
Generic location format, such as "United States Time (New York)", "Italy Time".
Definition: tzfmt.h:36
UTZFMT_STYLE_ISO_EXTENDED_FULL
ISO 8601 local time difference (extended format) with optional seconds field, or the UTC indicator...
Definition: tzfmt.h:130
UTZFMT_STYLE_LOCALIZED_GMT_SHORT
Short localized GMT offset format, such as "GMT-5", "UTC+1:30" This style is equivalent to the LDML d...
Definition: tzfmt.h:67
UTZFMT_PAT_POSITIVE_H
Positive offset with hours field.
Definition: tzfmt.h:184
timezone.h
C++ API: TimeZone object.
UDate
double UDate
Date and Time data type.
Definition: utypes.h:203
UTZFMT_PARSE_OPTION_NONE
No option.
Definition: tzfmt.h:231
ULOC_COUNTRY_CAPACITY
#define ULOC_COUNTRY_CAPACITY
Useful constant for the maximum size of the country part of a locale ID (including the terminating NU...
Definition: uloc.h:258
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler&#39;s RTTI.
Definition: uobject.h:90
UTZFMT_PAT_NEGATIVE_HMS
Negative offset with hours, minutes and seconds fields.
Definition: tzfmt.h:179
icu::Format::clone
virtual Format * clone() const =0
Clone this object polymorphically.
icu::TimeZone
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition: timezone.h:131
UTZFMT_TIME_TYPE_UNKNOWN
Unknown.
Definition: tzfmt.h:209
format.h
C++ API: Base class for all formats.
U_CDECL_BEGIN
#define U_CDECL_BEGIN
This is used to begin a declaration of a library private ICU C API.
Definition: umachine.h:84
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:301
UTZFMT_STYLE_ISO_BASIC_LOCAL_FIXED
Fixed width ISO 8601 local time difference (basic format).
Definition: tzfmt.h:95
UTZFMT_STYLE_EXEMPLAR_LOCATION
Exemplar location, such as "Los Angeles" and "Paris".
Definition: tzfmt.h:152
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:137
icu::TimeZoneNames::MatchInfoCollection
MatchInfoCollection represents a collection of time zone name matches used by TimeZoneNames#find.
Definition: tznames.h:308
UTZFMT_STYLE_ISO_EXTENDED_FIXED
Fixed width ISO 8601 local time difference (extended format) or the UTC indicator.
Definition: tzfmt.h:116
UTZFMT_TIME_TYPE_DAYLIGHT
Daylight saving time.
Definition: tzfmt.h:219
UTZFMT_PAT_POSITIVE_HM
Positive offset with hours and minutes fields.
Definition: tzfmt.h:164
icu::TimeZoneNames
TimeZoneNames is an abstract class representing the time zone display name data model defined by UTS#...
Definition: tznames.h:129
UTZFMT_STYLE_ISO_BASIC_LOCAL_SHORT
Short ISO 8601 locale time difference (basic format).
Definition: tzfmt.h:81
tznames.h
C++ API: TimeZoneNames.
UChar32
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition: umachine.h:389
NULL
#define NULL
Define NULL if necessary, to nullptr for C++ and to ((void *)0) for C.
Definition: utypes.h:188
icu::UObject::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU4C "poor man&#39;s RTTI", returns a UClassID for the actual ICU class.
UTZFMT_STYLE_ISO_BASIC_FULL
ISO 8601 local time difference (basic format) with optional seconds field, or the UTC indicator...
Definition: tzfmt.h:102
UTimeZoneFormatStyle
UTimeZoneFormatStyle
Constants for time zone display format style used by format/parse APIs in TimeZoneFormat.
Definition: tzfmt.h:31
UTZFMT_STYLE_ZONE_ID
Time Zone ID, such as "America/Los_Angeles".
Definition: tzfmt.h:142
UTZFMT_STYLE_SPECIFIC_SHORT
Specific short format, such as "EST", "PDT".
Definition: tzfmt.h:56
U_CDECL_END
#define U_CDECL_END
This is used to end a declaration of a library private ICU C API.
Definition: umachine.h:85
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:138
UTZFMT_PAT_POSITIVE_HMS
Positive offset with hours, minutes and seconds fields.
Definition: tzfmt.h:169
UTZFMT_STYLE_ZONE_ID_SHORT
Short Time Zone ID (BCP 47 Unicode location extension, time zone type value), such as "uslax"...
Definition: tzfmt.h:147
UTZFMT_STYLE_GENERIC_LONG
Generic long non-location format, such as "Eastern Time".
Definition: tzfmt.h:41
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:401
icu::FieldPosition
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:108
icu::ParsePosition
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:49
icu::Format::operator==
virtual UBool operator==(const Format &other) const =0
Return true if the given Format objects are semantically equal.
UTZFMT_TIME_TYPE_STANDARD
Standard time.
Definition: tzfmt.h:214
icu::Format::parseObject
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const =0
Parse a string to produce an object.
UTZFMT_STYLE_ISO_EXTENDED_LOCAL_FIXED
Fixed width ISO 8601 local time difference (extended format).
Definition: tzfmt.h:123
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
icu::Format::operator=
Format & operator=(const Format &)
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:289
UTZFMT_STYLE_SPECIFIC_LONG
Specific long format, such as "Eastern Standard Time".
Definition: tzfmt.h:51
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:62
UTimeZoneNameType
UTimeZoneNameType
Constants for time zone display name types.
Definition: tznames.h:29
UTZFMT_STYLE_ISO_BASIC_SHORT
Short ISO 8601 local time difference (basic format) or the UTC indicator.
Definition: tzfmt.h:74
UTZFMT_STYLE_ISO_EXTENDED_LOCAL_FULL
ISO 8601 local time difference (extended format) with optional seconds field.
Definition: tzfmt.h:137
UTZFMT_PARSE_OPTION_TZ_DATABASE_ABBREVIATIONS
When parsing a time zone display name in UTZFMT_STYLE_SPECIFIC_SHORT, look for the IANA tz database c...
Definition: tzfmt.h:246
UTZFMT_STYLE_LOCALIZED_GMT
Localized GMT offset format, such as "GMT-05:00", "UTC+0100".
Definition: tzfmt.h:61
UTZFMT_PAT_COUNT
Number of UTimeZoneFormatGMTOffsetPatternType types.
Definition: tzfmt.h:196
UTZFMT_STYLE_GENERIC_SHORT
Generic short non-location format, such as "ET".
Definition: tzfmt.h:46
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:225
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:192