ICU 57.1 57.1
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
152
196
219
246
248
250
253class UVector;
254
271public:
277
283
289
298 virtual UBool operator==(const Format& other) const;
299
306 virtual Format* clone() const;
307
317
324
333
340
349
359
369
379
390
404
413
422
431
441
459
477
498
519
520 using Format::format;
521
537
552 int32_t parseOffsetISO8601(const UnicodeString& text, ParsePosition& pos) const;
553
566 int32_t parseOffsetLocalizedGMT(const UnicodeString& text, ParsePosition& pos) const;
567
581
600
618
619 /* ----------------------------------------------
620 * Format APIs
621 * ---------------------------------------------- */
622
635 FieldPosition& pos, UErrorCode& status) const;
636
649 virtual void parseObject(const UnicodeString& source, Formattable& result, ParsePosition& parse_pos) const;
650
656
662
663protected:
671
672private:
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
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,
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,
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
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
1093
1094#endif /* !UCONFIG_NO_FORMATTING */
1095#endif
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition fieldpos.h:106
Base class for all formats.
Definition format.h:94
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition fmtable.h:66
"Smart pointer" base class; do not use directly: use LocalPointer etc.
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:185
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition parsepos.h:47
TimeZoneFormat supports time zone display name formatting and parsing.
Definition tzfmt.h:270
virtual TimeZone * parse(UTimeZoneFormatStyle style, const UnicodeString &text, ParsePosition &pos, int32_t parseOptions, UTimeZoneFormatTimeType *timeType=NULL) const
Returns a TimeZone by parsing the time zone string according to the given parse position,...
virtual UnicodeString & format(UTimeZoneFormatStyle style, const TimeZone &tz, UDate date, UnicodeString &name, UTimeZoneFormatTimeType *timeType=NULL) const
Returns the display name of the time zone at the given date for the style.
TimeZone * parse(UTimeZoneFormatStyle style, const UnicodeString &text, ParsePosition &pos, UTimeZoneFormatTimeType *timeType=NULL) const
Returns a TimeZone by parsing the time zone string according to the given parse position,...
TimeZoneFormat(const Locale &locale, UErrorCode &status)
Constructs a TimeZoneFormat object for the specified locale.
virtual UBool operator==(const Format &other) const
Return true if the given Format objects are semantically equal.
virtual UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Format an object to produce a time zone display string using localized GMT offset format.
int32_t parseOffsetISO8601(const UnicodeString &text, ParsePosition &pos) const
Returns offset from GMT(UTC) in milliseconds for the given ISO 8601 style time zone string.
static UClassID getStaticClassID(void)
ICU "poor man's RTTI", returns a UClassID for this class.
void setGMTOffsetDigits(const UnicodeString &digits, UErrorCode &status)
Sets the decimal digit characters used for localized GMT format.
void setDefaultParseOptions(uint32_t flags)
Sets the default parse options.
virtual ~TimeZoneFormat()
Destructor.
void adoptTimeZoneNames(TimeZoneNames *tznames)
Sets the time zone display name data to this format instnace.
void setTimeZoneNames(const TimeZoneNames &tznames)
Sets the time zone display name data to this format instnace.
virtual UClassID getDynamicClassID() const
ICU "poor man's RTTI", returns a UClassID for the actual class.
UnicodeString & formatOffsetLocalizedGMT(int32_t offset, UnicodeString &result, UErrorCode &status) const
Returns the localized GMT(UTC) offset format for the given offset.
const TimeZoneNames * getTimeZoneNames() const
Returns the time zone display name data used by this instance.
UnicodeString & getGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, UnicodeString &pattern) const
Returns the offset pattern used for localized GMT format.
void setGMTZeroFormat(const UnicodeString &gmtZeroFormat, UErrorCode &status)
Sets the localized GMT format string for GMT(UTC) itself (GMT offset is 0).
void setGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, const UnicodeString &pattern, UErrorCode &status)
Sets the offset pattern for the given offset type.
TimeZoneFormat & operator=(const TimeZoneFormat &other)
Assignment operator.
UnicodeString & getGMTOffsetDigits(UnicodeString &digits) const
Returns the decimal digit characters used for localized GMT format.
UnicodeString & formatOffsetISO8601Extended(int32_t offset, UBool useUtcIndicator, UBool isShort, UBool ignoreSeconds, UnicodeString &result, UErrorCode &status) const
Returns the ISO 8601 extended time zone string for the given offset.
UnicodeString & formatOffsetISO8601Basic(int32_t offset, UBool useUtcIndicator, UBool isShort, UBool ignoreSeconds, UnicodeString &result, UErrorCode &status) const
Returns the ISO 8601 basic time zone string for the given offset.
uint32_t getDefaultParseOptions(void) const
Returns the bitwise flags of UTimeZoneFormatParseOption representing the default parse options used b...
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const
Parse a string to produce an object.
int32_t parseOffsetShortLocalizedGMT(const UnicodeString &text, ParsePosition &pos) const
Returns offset from GMT(UTC) in milliseconds for the given short localized GMT offset format string.
UnicodeString & formatOffsetShortLocalizedGMT(int32_t offset, UnicodeString &result, UErrorCode &status) const
Returns the short localized GMT(UTC) offset format for the given offset.
void setGMTPattern(const UnicodeString &pattern, UErrorCode &status)
Sets the localized GMT format pattern.
virtual Format * clone() const
Clone this object polymorphically.
static TimeZoneFormat * createInstance(const Locale &locale, UErrorCode &status)
Creates an instance of TimeZoneFormat for the given locale.
TimeZoneFormat(const TimeZoneFormat &other)
Copy constructor.
UnicodeString & getGMTPattern(UnicodeString &pattern) const
Returns the localized GMT format pattern.
int32_t parseOffsetLocalizedGMT(const UnicodeString &text, ParsePosition &pos) const
Returns offset from GMT(UTC) in milliseconds for the given localized GMT offset format string.
UnicodeString & getGMTZeroFormat(UnicodeString &gmtZeroFormat) const
Returns the localized GMT format string for GMT(UTC) itself (GMT offset is 0).
MatchInfoCollection represents a collection of time zone name matches used by TimeZoneNames#find.
Definition tznames.h:296
TimeZoneNames is an abstract class representing the time zone display name data model defined by UTS#...
Definition tznames.h:127
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition timezone.h:129
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:294
C++ API: Base class for all formats.
C++ API: TimeZone object.
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
@ UTZFMT_PAT_POSITIVE_HMS
Positive offset with hours, minutes and seconds fields.
Definition tzfmt.h:167
@ UTZFMT_PAT_NEGATIVE_HMS
Negative offset with hours, minutes and seconds fields.
Definition tzfmt.h:177
@ UTZFMT_PAT_POSITIVE_HM
Positive offset with hours and minutes fields.
Definition tzfmt.h:162
@ UTZFMT_PAT_NEGATIVE_H
Negative offset with hours field.
Definition tzfmt.h:187
@ UTZFMT_PAT_COUNT
Number of UTimeZoneFormatGMTOffsetPatternType types.
Definition tzfmt.h:194
@ UTZFMT_PAT_POSITIVE_H
Positive offset with hours field.
Definition tzfmt.h:182
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_ISO_BASIC_LOCAL_SHORT
Short ISO 8601 locale time difference (basic format).
Definition tzfmt.h:79
@ 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_EXTENDED_LOCAL_FIXED
Fixed width ISO 8601 local time difference (extended format).
Definition tzfmt.h:121
@ 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_STYLE_ISO_BASIC_LOCAL_FIXED
Fixed width ISO 8601 local time difference (basic format).
Definition tzfmt.h:93
@ UTZFMT_STYLE_ISO_EXTENDED_FIXED
Fixed width ISO 8601 local time difference (extended format) or the UTC indicator.
Definition tzfmt.h:114
@ UTZFMT_STYLE_ISO_EXTENDED_LOCAL_FULL
ISO 8601 local time difference (extended format) with optional seconds field.
Definition tzfmt.h:135
@ UTZFMT_STYLE_GENERIC_LONG
Generic long non-location format, such as "Eastern Time".
Definition tzfmt.h:39
@ UTZFMT_STYLE_LOCALIZED_GMT
Localized GMT offset format, such as "GMT-05:00", "UTC+0100".
Definition tzfmt.h:59
@ UTZFMT_STYLE_EXEMPLAR_LOCATION
Exemplar location, such as "Los Angeles" and "Paris".
Definition tzfmt.h:150
@ UTZFMT_STYLE_ISO_BASIC_SHORT
Short ISO 8601 local time difference (basic format) or the UTC indicator.
Definition tzfmt.h:72
@ UTZFMT_STYLE_ISO_BASIC_FULL
ISO 8601 local time difference (basic format) with optional seconds field, or the UTC indicator.
Definition tzfmt.h:100
@ UTZFMT_STYLE_ISO_BASIC_LOCAL_FULL
ISO 8601 local time difference (basic format) with optional seconds field.
Definition tzfmt.h:107
@ 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_ISO_EXTENDED_FULL
ISO 8601 local time difference (extended format) with optional seconds field, or the UTC indicator.
Definition tzfmt.h:128
@ UTZFMT_STYLE_GENERIC_LOCATION
Generic location format, such as "United States Time (New York)", "Italy Time".
Definition tzfmt.h:34
@ UTZFMT_STYLE_SPECIFIC_SHORT
Specific short format, such as "EST", "PDT".
Definition tzfmt.h:54
@ UTZFMT_STYLE_GENERIC_SHORT
Generic short non-location format, such as "ET".
Definition tzfmt.h:44
@ UTZFMT_STYLE_SPECIFIC_LONG
Specific long format, such as "Eastern Standard Time".
Definition tzfmt.h:49
UTimeZoneFormatParseOption
Constants for parse option flags, used for specifying optional parse behavior.
Definition tzfmt.h:224
@ 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
@ 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_PARSE_OPTION_NONE
No option.
Definition tzfmt.h:229
UTimeZoneFormatTimeType
Constants for time types used by TimeZoneFormat APIs for receiving time type (standard time,...
Definition tzfmt.h:202
@ UTZFMT_TIME_TYPE_DAYLIGHT
Daylight saving time.
Definition tzfmt.h:217
@ UTZFMT_TIME_TYPE_UNKNOWN
Unknown.
Definition tzfmt.h:207
@ UTZFMT_TIME_TYPE_STANDARD
Standard time.
Definition tzfmt.h:212
C++ API: TimeZoneNames.
UTimeZoneNameType
Constants for time zone display name types.
Definition tznames.h:27
#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
#define U_CDECL_END
This is used to end a declaration of a library private ICU C API.
Definition umachine.h:83
int8_t UBool
The ICU boolean type.
Definition umachine.h:234
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
#define U_CDECL_BEGIN
This is used to begin a declaration of a library private ICU C API.
Definition umachine.h:82
Basic definitions for ICU, for both C and C++ APIs.
#define NULL
Define NULL if necessary, to 0 for C++ and to ((void *)0) for C.
Definition utypes.h:186
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition utypes.h:476
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:358
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition uversion.h:130
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition uversion.h:129