ICU 62.1 62.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
154
198
221
248
250
252
253class TimeZoneGenericNames;
254class TZDBTimeZoneNames;
255class UVector;
256
273public:
279
285
291
300 virtual UBool operator==(const Format& other) const;
301
308 virtual Format* clone() const;
309
319
326
335
342
351
361
371
381
392
406
415
424
432 uint32_t getDefaultParseOptions(void) const;
433
442 void setDefaultParseOptions(uint32_t flags);
443
461
479
500
521
522 using Format::format;
523
539
554 int32_t parseOffsetISO8601(const UnicodeString& text, ParsePosition& pos) const;
555
568 int32_t parseOffsetLocalizedGMT(const UnicodeString& text, ParsePosition& pos) const;
569
583
602
620
621 /* ----------------------------------------------
622 * Format APIs
623 * ---------------------------------------------- */
624
637 FieldPosition& pos, UErrorCode& status) const;
638
651 virtual void parseObject(const UnicodeString& source, Formattable& result, ParsePosition& parse_pos) const;
652
658
664
665protected:
673
674private:
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
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,
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,
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
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
1095
1096#endif /* !UCONFIG_NO_FORMATTING */
1097#endif
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition fieldpos.h:108
Base class for all formats.
Definition format.h:96
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition fmtable.h:62
"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:188
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition parsepos.h:49
TimeZoneFormat supports time zone display name formatting and parsing.
Definition tzfmt.h:272
virtual Format * clone() const
Clone this object polymorphically.
UnicodeString & formatOffsetLocalizedGMT(int32_t offset, UnicodeString &result, UErrorCode &status) const
Returns the localized GMT(UTC) offset format for the given offset.
static UClassID getStaticClassID(void)
ICU "poor man's RTTI", returns a UClassID for this class.
TimeZoneFormat(const TimeZoneFormat &other)
Copy constructor.
void setGMTZeroFormat(const UnicodeString &gmtZeroFormat, UErrorCode &status)
Sets the localized GMT format string for GMT(UTC) itself (GMT offset is 0).
void setGMTOffsetDigits(const UnicodeString &digits, UErrorCode &status)
Sets the decimal digit characters used for localized GMT format.
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.
TimeZoneFormat(const Locale &locale, UErrorCode &status)
Constructs a TimeZoneFormat object for the specified locale.
UnicodeString & formatOffsetShortLocalizedGMT(int32_t offset, UnicodeString &result, UErrorCode &status) const
Returns the short localized GMT(UTC) offset format for the given offset.
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.
static TimeZoneFormat * createInstance(const Locale &locale, UErrorCode &status)
Creates an instance of TimeZoneFormat for the given locale.
void setGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, const UnicodeString &pattern, UErrorCode &status)
Sets the offset pattern for the given offset type.
void setGMTPattern(const UnicodeString &pattern, UErrorCode &status)
Sets the localized GMT format pattern.
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const
Parse a string to produce an object.
int32_t parseOffsetLocalizedGMT(const UnicodeString &text, ParsePosition &pos) const
Returns offset from GMT(UTC) in milliseconds for the given localized GMT offset format string.
virtual ~TimeZoneFormat()
Destructor.
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.
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.
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,...
virtual UClassID getDynamicClassID() const
ICU "poor man's RTTI", returns a UClassID for the actual class.
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.
UnicodeString & getGMTZeroFormat(UnicodeString &gmtZeroFormat) const
Returns the localized GMT format string for GMT(UTC) itself (GMT offset is 0).
TimeZoneFormat & operator=(const TimeZoneFormat &other)
Assignment operator.
void adoptTimeZoneNames(TimeZoneNames *tznames)
Sets the time zone display name data to this format instnace.
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,...
void setTimeZoneNames(const TimeZoneNames &tznames)
Sets the time zone display name data to this format instnace.
uint32_t getDefaultParseOptions(void) const
Returns the bitwise flags of UTimeZoneFormatParseOption representing the default parse options used b...
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 & getGMTPattern(UnicodeString &pattern) const
Returns the localized GMT format pattern.
void setDefaultParseOptions(uint32_t flags)
Sets the default parse options.
UnicodeString & getGMTOffsetDigits(UnicodeString &digits) const
Returns the decimal digit characters used for localized GMT 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.
MatchInfoCollection represents a collection of time zone name matches used by TimeZoneNames#find.
Definition tznames.h:308
TimeZoneNames is an abstract class representing the time zone display name data model defined by UTS#...
Definition tznames.h:129
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition timezone.h:131
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:287
C++ API: Base class for all formats.
C++ API: TimeZone object.
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
@ UTZFMT_PAT_POSITIVE_HMS
Positive offset with hours, minutes and seconds fields.
Definition tzfmt.h:169
@ UTZFMT_PAT_NEGATIVE_HMS
Negative offset with hours, minutes and seconds fields.
Definition tzfmt.h:179
@ UTZFMT_PAT_POSITIVE_HM
Positive offset with hours and minutes fields.
Definition tzfmt.h:164
@ UTZFMT_PAT_NEGATIVE_H
Negative offset with hours field.
Definition tzfmt.h:189
@ UTZFMT_PAT_COUNT
Number of UTimeZoneFormatGMTOffsetPatternType types.
Definition tzfmt.h:196
@ UTZFMT_PAT_POSITIVE_H
Positive offset with hours field.
Definition tzfmt.h:184
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_ISO_BASIC_LOCAL_SHORT
Short ISO 8601 locale time difference (basic format).
Definition tzfmt.h:81
@ 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_EXTENDED_LOCAL_FIXED
Fixed width ISO 8601 local time difference (extended format).
Definition tzfmt.h:123
@ 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_STYLE_ISO_BASIC_LOCAL_FIXED
Fixed width ISO 8601 local time difference (basic format).
Definition tzfmt.h:95
@ UTZFMT_STYLE_ISO_EXTENDED_FIXED
Fixed width ISO 8601 local time difference (extended format) or the UTC indicator.
Definition tzfmt.h:116
@ UTZFMT_STYLE_ISO_EXTENDED_LOCAL_FULL
ISO 8601 local time difference (extended format) with optional seconds field.
Definition tzfmt.h:137
@ UTZFMT_STYLE_GENERIC_LONG
Generic long non-location format, such as "Eastern Time".
Definition tzfmt.h:41
@ UTZFMT_STYLE_LOCALIZED_GMT
Localized GMT offset format, such as "GMT-05:00", "UTC+0100".
Definition tzfmt.h:61
@ UTZFMT_STYLE_EXEMPLAR_LOCATION
Exemplar location, such as "Los Angeles" and "Paris".
Definition tzfmt.h:152
@ UTZFMT_STYLE_ISO_BASIC_SHORT
Short ISO 8601 local time difference (basic format) or the UTC indicator.
Definition tzfmt.h:74
@ UTZFMT_STYLE_ISO_BASIC_FULL
ISO 8601 local time difference (basic format) with optional seconds field, or the UTC indicator.
Definition tzfmt.h:102
@ UTZFMT_STYLE_ISO_BASIC_LOCAL_FULL
ISO 8601 local time difference (basic format) with optional seconds field.
Definition tzfmt.h:109
@ 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_ISO_EXTENDED_FULL
ISO 8601 local time difference (extended format) with optional seconds field, or the UTC indicator.
Definition tzfmt.h:130
@ UTZFMT_STYLE_GENERIC_LOCATION
Generic location format, such as "United States Time (New York)", "Italy Time".
Definition tzfmt.h:36
@ UTZFMT_STYLE_SPECIFIC_SHORT
Specific short format, such as "EST", "PDT".
Definition tzfmt.h:56
@ UTZFMT_STYLE_GENERIC_SHORT
Generic short non-location format, such as "ET".
Definition tzfmt.h:46
@ UTZFMT_STYLE_SPECIFIC_LONG
Specific long format, such as "Eastern Standard Time".
Definition tzfmt.h:51
UTimeZoneFormatParseOption
Constants for parse option flags, used for specifying optional parse behavior.
Definition tzfmt.h:226
@ 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
@ 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_PARSE_OPTION_NONE
No option.
Definition tzfmt.h:231
UTimeZoneFormatTimeType
Constants for time types used by TimeZoneFormat APIs for receiving time type (standard time,...
Definition tzfmt.h:204
@ UTZFMT_TIME_TYPE_DAYLIGHT
Daylight saving time.
Definition tzfmt.h:219
@ UTZFMT_TIME_TYPE_UNKNOWN
Unknown.
Definition tzfmt.h:209
@ UTZFMT_TIME_TYPE_STANDARD
Standard time.
Definition tzfmt.h:214
C++ API: TimeZoneNames.
UTimeZoneNameType
Constants for time zone display name types.
Definition tznames.h:29
#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
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition umachine.h:400
#define U_CDECL_END
This is used to end a declaration of a library private ICU C API.
Definition umachine.h:85
int8_t UBool
The ICU boolean type.
Definition umachine.h:236
#define U_CDECL_BEGIN
This is used to begin a declaration of a library private ICU C API.
Definition umachine.h:84
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:93
Basic definitions for ICU, for both C and C++ APIs.
#define NULL
Define NULL if necessary, to nullptr for C++ and to ((void *)0) for C.
Definition utypes.h:188
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition utypes.h:396
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:360
double UDate
Date and Time data type.
Definition utypes.h:203
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition uversion.h:138
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition uversion.h:137