ICU 56.1: tzfmt.h Source File

ICU 56.1 56.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

tzfmt.h
Go to the documentation of this file.
1 /*
2 *******************************************************************************
3 * Copyright (C) 2011-2015, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 *******************************************************************************
6 */
7 #ifndef __TZFMT_H
8 #define __TZFMT_H
9
15 #include "unicode/utypes.h"
16
17 #if !UCONFIG_NO_FORMATTING
18
19 #include "unicode/format.h"
20 #include "unicode/timezone.h"
21 #include "unicode/tznames.h"
22
23 U_CDECL_BEGIN
29 typedef enum UTimeZoneFormatStyle {
34 UTZFMT_STYLE_GENERIC_LOCATION,
39 UTZFMT_STYLE_GENERIC_LONG,
44 UTZFMT_STYLE_GENERIC_SHORT,
49 UTZFMT_STYLE_SPECIFIC_LONG,
54 UTZFMT_STYLE_SPECIFIC_SHORT,
59 UTZFMT_STYLE_LOCALIZED_GMT,
65 UTZFMT_STYLE_LOCALIZED_GMT_SHORT,
72 UTZFMT_STYLE_ISO_BASIC_SHORT,
79 UTZFMT_STYLE_ISO_BASIC_LOCAL_SHORT,
86 UTZFMT_STYLE_ISO_BASIC_FIXED,
93 UTZFMT_STYLE_ISO_BASIC_LOCAL_FIXED,
100 UTZFMT_STYLE_ISO_BASIC_FULL,
107 UTZFMT_STYLE_ISO_BASIC_LOCAL_FULL,
114 UTZFMT_STYLE_ISO_EXTENDED_FIXED,
121 UTZFMT_STYLE_ISO_EXTENDED_LOCAL_FIXED,
128 UTZFMT_STYLE_ISO_EXTENDED_FULL,
135 UTZFMT_STYLE_ISO_EXTENDED_LOCAL_FULL,
140 UTZFMT_STYLE_ZONE_ID,
145 UTZFMT_STYLE_ZONE_ID_SHORT,
150 UTZFMT_STYLE_EXEMPLAR_LOCATION
151 } UTimeZoneFormatStyle;
152
157 typedef enum UTimeZoneFormatGMTOffsetPatternType {
162 UTZFMT_PAT_POSITIVE_HM,
167 UTZFMT_PAT_POSITIVE_HMS,
172 UTZFMT_PAT_NEGATIVE_HM,
177 UTZFMT_PAT_NEGATIVE_HMS,
182 UTZFMT_PAT_POSITIVE_H,
187 UTZFMT_PAT_NEGATIVE_H,
188
189 /* The following cannot be #ifndef U_HIDE_INTERNAL_API, needed for other .h declarations */
194 UTZFMT_PAT_COUNT = 6
195 } UTimeZoneFormatGMTOffsetPatternType;
196
202 typedef enum UTimeZoneFormatTimeType {
207 UTZFMT_TIME_TYPE_UNKNOWN,
212 UTZFMT_TIME_TYPE_STANDARD,
217 UTZFMT_TIME_TYPE_DAYLIGHT
218 } UTimeZoneFormatTimeType;
219
224 typedef enum UTimeZoneFormatParseOption {
229 UTZFMT_PARSE_OPTION_NONE = 0x00,
236 UTZFMT_PARSE_OPTION_ALL_STYLES = 0x01,
244 UTZFMT_PARSE_OPTION_TZ_DATABASE_ABBREVIATIONS = 0x02
245 } UTimeZoneFormatParseOption;
246
247 U_CDECL_END
248
249 U_NAMESPACE_BEGIN
250
251 class TimeZoneGenericNames;
252 class TZDBTimeZoneNames;
253 class UVector;
254
270 class U_I18N_API TimeZoneFormat : public Format {
271 public:
276 TimeZoneFormat(const TimeZoneFormat& other);
277
282 virtual ~TimeZoneFormat();
283
288 TimeZoneFormat& operator=(const TimeZoneFormat& other);
289
298 virtual UBool operator==(const Format& other) const;
299
306 virtual Format* clone() const;
307
316 static TimeZoneFormat* U_EXPORT2 createInstance(const Locale& locale, UErrorCode& status);
317
323 const TimeZoneNames* getTimeZoneNames() const;
324
332 void adoptTimeZoneNames(TimeZoneNames *tznames);
333
339 void setTimeZoneNames(const TimeZoneNames &tznames);
340
348 UnicodeString& getGMTPattern(UnicodeString& pattern) const;
349
358 void setGMTPattern(const UnicodeString& pattern, UErrorCode& status);
359
368 UnicodeString& getGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, UnicodeString& pattern) const;
369
378 void setGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, const UnicodeString& pattern, UErrorCode& status);
379
389 UnicodeString& getGMTOffsetDigits(UnicodeString& digits) const;
390
403 void setGMTOffsetDigits(const UnicodeString& digits, UErrorCode& status);
404
412 UnicodeString& getGMTZeroFormat(UnicodeString& gmtZeroFormat) const;
413
421 void setGMTZeroFormat(const UnicodeString& gmtZeroFormat, UErrorCode& status);
422
430 uint32_t getDefaultParseOptions(void) const;
431
440 void setDefaultParseOptions(uint32_t flags);
441
457 UnicodeString& formatOffsetISO8601Basic(int32_t offset, UBool useUtcIndicator, UBool isShort, UBool ignoreSeconds,
458 UnicodeString& result, UErrorCode& status) const;
459
475 UnicodeString& formatOffsetISO8601Extended(int32_t offset, UBool useUtcIndicator, UBool isShort, UBool ignoreSeconds,
476 UnicodeString& result, UErrorCode& status) const;
477
497 UnicodeString& formatOffsetLocalizedGMT(int32_t offset, UnicodeString& result, UErrorCode& status) const;
498
518 UnicodeString& formatOffsetShortLocalizedGMT(int32_t offset, UnicodeString& result, UErrorCode& status) const;
519
520 using Format::format;
521
535 virtual UnicodeString& format(UTimeZoneFormatStyle style, const TimeZone& tz, UDate date,
536 UnicodeString& name, UTimeZoneFormatTimeType* timeType = NULL) const;
537
552 int32_t parseOffsetISO8601(const UnicodeString& text, ParsePosition& pos) const;
553
566 int32_t parseOffsetLocalizedGMT(const UnicodeString& text, ParsePosition& pos) const;
567
580 int32_t parseOffsetShortLocalizedGMT(const UnicodeString& text, ParsePosition& pos) const;
581
598 virtual TimeZone* parse(UTimeZoneFormatStyle style, const UnicodeString& text, ParsePosition& pos,
599 int32_t parseOptions, UTimeZoneFormatTimeType* timeType = NULL) const;
600
616 TimeZone* parse(UTimeZoneFormatStyle style, const UnicodeString& text, ParsePosition& pos,
617 UTimeZoneFormatTimeType* timeType = NULL) const;
618
619 /* ----------------------------------------------
620 * Format APIs
621 * ---------------------------------------------- */
622
634 virtual UnicodeString& format(const Formattable& obj, UnicodeString& appendTo,
635 FieldPosition& pos, UErrorCode& status) const;
636
649 virtual void parseObject(const UnicodeString& source, Formattable& result, ParsePosition& parse_pos) const;
650
655 static UClassID U_EXPORT2 getStaticClassID(void);
656
661 virtual UClassID getDynamicClassID() const;
662
663 protected:
670 TimeZoneFormat(const Locale& locale, UErrorCode& status);
671
672 private:
673 /* Locale of this object */
674 Locale fLocale;
675
676 /* Stores the region (could be implicit default) */
677 char fTargetRegion[ULOC_COUNTRY_CAPACITY];
678
679 /* TimeZoneNames object used by this formatter */
680 TimeZoneNames* fTimeZoneNames;
681
682 /* TimeZoneGenericNames object used by this formatter - lazily instantiated */
683 TimeZoneGenericNames* fTimeZoneGenericNames;
684
685 /* Localized GMT format pattern - e.g. "GMT{0}" */
686 UnicodeString fGMTPattern;
687
688 /* Array of offset patterns used by Localized GMT format - e.g. "+HH:mm" */
689 UnicodeString fGMTOffsetPatterns[UTZFMT_PAT_COUNT];
690
691 /* Localized decimal digits used by Localized GMT format */
692 UChar32 fGMTOffsetDigits[10];
693
694 /* Localized GMT zero format - e.g. "GMT" */
695 UnicodeString fGMTZeroFormat;
696
697 /* Bit flags representing parse options */
698 uint32_t fDefParseOptionFlags;
699
700 /* Constant parts of GMT format pattern, populated from localized GMT format pattern*/
701 UnicodeString fGMTPatternPrefix; /* Substring before {0} */
702 UnicodeString fGMTPatternSuffix; /* Substring after {0} */
703
704 /* Compiled offset patterns generated from fGMTOffsetPatterns[] */
705 UVector* fGMTOffsetPatternItems[UTZFMT_PAT_COUNT];
706
707 UBool fAbuttingOffsetHoursAndMinutes;
708
709 /* TZDBTimeZoneNames object used for parsing */
710 TZDBTimeZoneNames* fTZDBTimeZoneNames;
711
722 UnicodeString& formatSpecific(const TimeZone& tz, UTimeZoneNameType stdType, UTimeZoneNameType dstType,
723 UDate date, UnicodeString& name, UTimeZoneFormatTimeType *timeType) const;
724
733 UnicodeString& formatGeneric(const TimeZone& tz, int32_t genType, UDate date, UnicodeString& name) const;
734
740 const TimeZoneGenericNames* getTimeZoneGenericNames(UErrorCode& status) const;
741
747 const TZDBTimeZoneNames* getTZDBTimeZoneNames(UErrorCode& status) const;
748
756 UnicodeString& formatExemplarLocation(const TimeZone& tz, UnicodeString& name) const;
757
761 enum OffsetFields {
762 FIELDS_H,
763 FIELDS_HM,
764 FIELDS_HMS
765 };
766
774 void initGMTPattern(const UnicodeString& gmtPattern, UErrorCode& status);
775
784 static UVector* parseOffsetPattern(const UnicodeString& pattern, OffsetFields required, UErrorCode& status);
785
794 static UnicodeString& expandOffsetPattern(const UnicodeString& offsetHM, UnicodeString& result, UErrorCode& status);
795
804 static UnicodeString& truncateOffsetPattern(const UnicodeString& offsetHM, UnicodeString& result, UErrorCode& status);
805
816 static UBool toCodePoints(const UnicodeString& str, UChar32* codeArray, int32_t capacity);
817
828 UnicodeString& formatOffsetISO8601(int32_t offset, UBool isBasic, UBool useUtcIndicator,
829 UBool isShort, UBool ignoreSeconds, UnicodeString& result, UErrorCode& status) const;
830
838 UnicodeString& formatOffsetLocalizedGMT(int32_t offset, UBool isShort, UnicodeString& result, UErrorCode& status) const;
839
854 int32_t parseOffsetISO8601(const UnicodeString& text, ParsePosition& pos, UBool extendedOnly,
855 UBool* hasDigitOffset = NULL) const;
856
864 void appendOffsetDigits(UnicodeString& buf, int32_t n, uint8_t minDigits) const;
865
878 int32_t parseOffsetLocalizedGMT(const UnicodeString& text, ParsePosition& pos,
879 UBool isShort, UBool* hasDigitOffset) const;
880
890 int32_t parseOffsetLocalizedGMTPattern(const UnicodeString& text, int32_t start,
891 UBool isShort, int32_t& parsedLen) const;
892
901 int32_t parseOffsetFields(const UnicodeString& text, int32_t start, UBool isShort, int32_t& parsedLen) const;
902
914 int32_t parseOffsetFieldsWithPattern(const UnicodeString& text, int32_t start,
915 UVector* patternItems, UBool forceSingleHourDigit, int32_t& hour, int32_t& min, int32_t& sec) const;
916
924 int32_t parseAbuttingOffsetFields(const UnicodeString& text, int32_t start, int32_t& parsedLen) const;
925
933 int32_t parseOffsetDefaultLocalizedGMT(const UnicodeString& text, int start, int32_t& parsedLen) const;
934
943 int32_t parseDefaultOffsetFields(const UnicodeString& text, int32_t start, UChar separator,
944 int32_t& parsedLen) const;
945
960 int32_t parseOffsetFieldWithLocalizedDigits(const UnicodeString& text, int32_t start,
961 uint8_t minDigits, uint8_t maxDigits, uint16_t minVal, uint16_t maxVal, int32_t& parsedLen) const;
962
972 int32_t parseSingleLocalizedDigit(const UnicodeString& text, int32_t start, int32_t& len) const;
973
983 static UnicodeString& formatOffsetWithAsciiDigits(int32_t offset, UChar sep,
984 OffsetFields minFields, OffsetFields maxFields, UnicodeString& result);
985
998 static int32_t parseAbuttingAsciiOffsetFields(const UnicodeString& text, ParsePosition& pos,
999 OffsetFields minFields, OffsetFields maxFields, UBool fixedHourWidth);
1000
1013 static int32_t parseAsciiOffsetFields(const UnicodeString& text, ParsePosition& pos, UChar sep,
1014 OffsetFields minFields, OffsetFields maxFields);
1015
1022 static UnicodeString& unquote(const UnicodeString& pattern, UnicodeString& result);
1023
1029 void initGMTOffsetPatterns(UErrorCode& status);
1030
1037 void checkAbuttingHoursAndMinutes();
1038
1044 TimeZone* createTimeZoneForOffset(int32_t offset) const;
1045
1051 static UTimeZoneFormatTimeType getTimeType(UTimeZoneNameType nameType);
1052
1061 UnicodeString& getTimeZoneID(const TimeZoneNames::MatchInfoCollection* matches, int32_t idx, UnicodeString& tzID) const;
1062
1063
1071 UnicodeString& parseZoneID(const UnicodeString& text, ParsePosition& pos, UnicodeString& tzID) const;
1072
1080 UnicodeString& parseShortZoneID(const UnicodeString& text, ParsePosition& pos, UnicodeString& tzID) const;
1081
1089 UnicodeString& parseExemplarLocation(const UnicodeString& text, ParsePosition& pos, UnicodeString& tzID) const;
1090 };
1091
1092 U_NAMESPACE_END
1093
1094 #endif /* !UCONFIG_NO_FORMATTING */
1095 #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:236
icu::Format
Base class for all formats.
Definition: format.h:94
UTimeZoneFormatGMTOffsetPatternType
UTimeZoneFormatGMTOffsetPatternType
Constants for GMT offset pattern types.
Definition: tzfmt.h:157
UTZFMT_PAT_NEGATIVE_HM
Negative offset with hours and minutes fields.
Definition: tzfmt.h:172
icu::TimeZoneFormat
TimeZoneFormat supports time zone display name formatting and parsing.
Definition: tzfmt.h:270
UTZFMT_STYLE_ISO_BASIC_FIXED
Fixed width ISO 8601 local time difference (basic format) or the UTC indicator.
Definition: tzfmt.h:86
UTZFMT_STYLE_ISO_BASIC_LOCAL_FULL
ISO 8601 local time difference (basic format) with optional seconds field.
Definition: tzfmt.h:107
UTimeZoneFormatParseOption
UTimeZoneFormatParseOption
Constants for parse option flags, used for specifying optional parse behavior.
Definition: tzfmt.h:224
UTZFMT_PAT_NEGATIVE_H
Negative offset with hours field.
Definition: tzfmt.h:187
UTimeZoneFormatTimeType
UTimeZoneFormatTimeType
Constants for time types used by TimeZoneFormat APIs for receiving time type (standard time...
Definition: tzfmt.h:202
UTZFMT_STYLE_GENERIC_LOCATION
Generic location format, such as "United States Time (New York)", "Italy Time".
Definition: tzfmt.h:34
UTZFMT_STYLE_ISO_EXTENDED_FULL
ISO 8601 local time difference (extended format) with optional seconds field, or the UTC indicator...
Definition: tzfmt.h:128
icu::UObject::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
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:65
UTZFMT_PAT_POSITIVE_H
Positive offset with hours field.
Definition: tzfmt.h:182
timezone.h
C++ API: TimeZone object.
UDate
double UDate
Date and Time data type.
Definition: utypes.h:201
UTZFMT_PARSE_OPTION_NONE
No option.
Definition: tzfmt.h:229
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:256
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:91
UTZFMT_PAT_NEGATIVE_HMS
Negative offset with hours, minutes and seconds fields.
Definition: tzfmt.h:177
icu::TimeZone
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition: timezone.h:129
UTZFMT_TIME_TYPE_UNKNOWN
Unknown.
Definition: tzfmt.h:207
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:82
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:358
UTZFMT_STYLE_ISO_BASIC_LOCAL_FIXED
Fixed width ISO 8601 local time difference (basic format).
Definition: tzfmt.h:93
UTZFMT_STYLE_EXEMPLAR_LOCATION
Exemplar location, such as "Los Angeles" and "Paris".
Definition: tzfmt.h:150
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129
icu::TimeZoneNames::MatchInfoCollection
MatchInfoCollection represents a collection of time zone name matches used by TimeZoneNames#find.
Definition: tznames.h:296
UTZFMT_STYLE_ISO_EXTENDED_FIXED
Fixed width ISO 8601 local time difference (extended format) or the UTC indicator.
Definition: tzfmt.h:114
UTZFMT_TIME_TYPE_DAYLIGHT
Daylight saving time.
Definition: tzfmt.h:217
UTZFMT_PAT_POSITIVE_HM
Positive offset with hours and minutes fields.
Definition: tzfmt.h:162
icu::TimeZoneNames
TimeZoneNames is an abstract class representing the time zone display name data model defined by UTS#...
Definition: tznames.h:127
UTZFMT_STYLE_ISO_BASIC_LOCAL_SHORT
Short ISO 8601 locale time difference (basic format).
Definition: tzfmt.h:79
tznames.h
C++ API: TimeZoneNames.
UChar32
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition: umachine.h:332
NULL
#define NULL
Define NULL if necessary, to 0 for C++ and to ((void *)0) for C.
Definition: utypes.h:186
UTZFMT_STYLE_ISO_BASIC_FULL
ISO 8601 local time difference (basic format) with optional seconds field, or the UTC indicator...
Definition: tzfmt.h:100
icu::Format::format
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
UTimeZoneFormatStyle
UTimeZoneFormatStyle
Constants for time zone display format style used by format/parse APIs in TimeZoneFormat.
Definition: tzfmt.h:29
UTZFMT_STYLE_ZONE_ID
Time Zone ID, such as "America/Los_Angeles".
Definition: tzfmt.h:140
UTZFMT_STYLE_SPECIFIC_SHORT
Specific short format, such as "EST", "PDT".
Definition: tzfmt.h:54
UChar
uint16_t UChar
Define UChar to be UCHAR_TYPE, if that is #defined (for example, to char16_t), or wchar_t if that is ...
Definition: umachine.h:312
U_CDECL_END
#define U_CDECL_END
This is used to end a declaration of a library private ICU C API.
Definition: umachine.h:83
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:130
icu::Format::parseObject
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const =0
Parse a string to produce an object.
icu::Format::operator==
virtual UBool operator==(const Format &other) const =0
Return true if the given Format objects are semantically equal.
UTZFMT_PAT_POSITIVE_HMS
Positive offset with hours, minutes and seconds fields.
Definition: tzfmt.h:167
UTZFMT_STYLE_ZONE_ID_SHORT
Short Time Zone ID (BCP 47 Unicode location extension, time zone type value), such as "uslax"...
Definition: tzfmt.h:145
UTZFMT_STYLE_GENERIC_LONG
Generic long non-location format, such as "Eastern Time".
Definition: tzfmt.h:39
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:476
icu::FieldPosition
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:106
icu::ParsePosition
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:47
UTZFMT_TIME_TYPE_STANDARD
Standard time.
Definition: tzfmt.h:212
UTZFMT_STYLE_ISO_EXTENDED_LOCAL_FIXED
Fixed width ISO 8601 local time difference (extended format).
Definition: tzfmt.h:121
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:293
UTZFMT_STYLE_SPECIFIC_LONG
Specific long format, such as "Eastern Standard Time".
Definition: tzfmt.h:49
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:66
UTimeZoneNameType
UTimeZoneNameType
Constants for time zone display name types.
Definition: tznames.h:27
UTZFMT_STYLE_ISO_BASIC_SHORT
Short ISO 8601 local time difference (basic format) or the UTC indicator.
Definition: tzfmt.h:72
UTZFMT_STYLE_ISO_EXTENDED_LOCAL_FULL
ISO 8601 local time difference (extended format) with optional seconds field.
Definition: tzfmt.h:135
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:244
UTZFMT_STYLE_LOCALIZED_GMT
Localized GMT offset format, such as "GMT-05:00", "UTC+0100".
Definition: tzfmt.h:59
icu::Format::clone
virtual Format * clone() const =0
Clone this object polymorphically.
UTZFMT_PAT_COUNT
Number of UTimeZoneFormatGMTOffsetPatternType types.
Definition: tzfmt.h:194
UTZFMT_STYLE_GENERIC_SHORT
Generic short non-location format, such as "ET".
Definition: tzfmt.h:44
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:234
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:185