ICU 55.1 55.1

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

- File List
- Globals

All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tzfmt.h
Go to the documentation of this file.
1 /*
2 *******************************************************************************
3 * Copyright (C) 2011-2014, 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
237 #ifndef U_HIDE_DRAFT_API
238 ,
246 UTZFMT_PARSE_OPTION_TZ_DATABASE_ABBREVIATIONS = 0x02
247 #endif /* U_HIDE_DRAFT_API */
248 } UTimeZoneFormatParseOption;
249
250 U_CDECL_END
251
252 U_NAMESPACE_BEGIN
253
254 class TimeZoneGenericNames;
255 class TZDBTimeZoneNames;
256 class UVector;
257
273 class U_I18N_API TimeZoneFormat : public Format {
274 public:
279 TimeZoneFormat(const TimeZoneFormat& other);
280
285 virtual ~TimeZoneFormat();
286
291 TimeZoneFormat& operator=(const TimeZoneFormat& other);
292
301 virtual UBool operator==(const Format& other) const;
302
309 virtual Format* clone() const;
310
319 static TimeZoneFormat* U_EXPORT2 createInstance(const Locale& locale, UErrorCode& status);
320
326 const TimeZoneNames* getTimeZoneNames() const;
327
335 void adoptTimeZoneNames(TimeZoneNames *tznames);
336
342 void setTimeZoneNames(const TimeZoneNames &tznames);
343
351 UnicodeString& getGMTPattern(UnicodeString& pattern) const;
352
361 void setGMTPattern(const UnicodeString& pattern, UErrorCode& status);
362
371 UnicodeString& getGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, UnicodeString& pattern) const;
372
381 void setGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, const UnicodeString& pattern, UErrorCode& status);
382
392 UnicodeString& getGMTOffsetDigits(UnicodeString& digits) const;
393
406 void setGMTOffsetDigits(const UnicodeString& digits, UErrorCode& status);
407
415 UnicodeString& getGMTZeroFormat(UnicodeString& gmtZeroFormat) const;
416
424 void setGMTZeroFormat(const UnicodeString& gmtZeroFormat, UErrorCode& status);
425
433 uint32_t getDefaultParseOptions(void) const;
434
443 void setDefaultParseOptions(uint32_t flags);
444
460 UnicodeString& formatOffsetISO8601Basic(int32_t offset, UBool useUtcIndicator, UBool isShort, UBool ignoreSeconds,
461 UnicodeString& result, UErrorCode& status) const;
462
478 UnicodeString& formatOffsetISO8601Extended(int32_t offset, UBool useUtcIndicator, UBool isShort, UBool ignoreSeconds,
479 UnicodeString& result, UErrorCode& status) const;
480
500 UnicodeString& formatOffsetLocalizedGMT(int32_t offset, UnicodeString& result, UErrorCode& status) const;
501
521 UnicodeString& formatOffsetShortLocalizedGMT(int32_t offset, UnicodeString& result, UErrorCode& status) const;
522
523 using Format::format;
524
538 virtual UnicodeString& format(UTimeZoneFormatStyle style, const TimeZone& tz, UDate date,
539 UnicodeString& name, UTimeZoneFormatTimeType* timeType = NULL) const;
540
555 int32_t parseOffsetISO8601(const UnicodeString& text, ParsePosition& pos) const;
556
569 int32_t parseOffsetLocalizedGMT(const UnicodeString& text, ParsePosition& pos) const;
570
583 int32_t parseOffsetShortLocalizedGMT(const UnicodeString& text, ParsePosition& pos) const;
584
601 virtual TimeZone* parse(UTimeZoneFormatStyle style, const UnicodeString& text, ParsePosition& pos,
602 int32_t parseOptions, UTimeZoneFormatTimeType* timeType = NULL) const;
603
619 TimeZone* parse(UTimeZoneFormatStyle style, const UnicodeString& text, ParsePosition& pos,
620 UTimeZoneFormatTimeType* timeType = NULL) const;
621
622 /* ----------------------------------------------
623 * Format APIs
624 * ---------------------------------------------- */
625
637 virtual UnicodeString& format(const Formattable& obj, UnicodeString& appendTo,
638 FieldPosition& pos, UErrorCode& status) const;
639
652 virtual void parseObject(const UnicodeString& source, Formattable& result, ParsePosition& parse_pos) const;
653
658 static UClassID U_EXPORT2 getStaticClassID(void);
659
664 virtual UClassID getDynamicClassID() const;
665
666 protected:
673 TimeZoneFormat(const Locale& locale, UErrorCode& status);
674
675 private:
676 /* Locale of this object */
677 Locale fLocale;
678
679 /* Stores the region (could be implicit default) */
680 char fTargetRegion[ULOC_COUNTRY_CAPACITY];
681
682 /* TimeZoneNames object used by this formatter */
683 TimeZoneNames* fTimeZoneNames;
684
685 /* TimeZoneGenericNames object used by this formatter - lazily instantiated */
686 TimeZoneGenericNames* fTimeZoneGenericNames;
687
688 /* Localized GMT format pattern - e.g. "GMT{0}" */
689 UnicodeString fGMTPattern;
690
691 /* Array of offset patterns used by Localized GMT format - e.g. "+HH:mm" */
692 UnicodeString fGMTOffsetPatterns[UTZFMT_PAT_COUNT];
693
694 /* Localized decimal digits used by Localized GMT format */
695 UChar32 fGMTOffsetDigits[10];
696
697 /* Localized GMT zero format - e.g. "GMT" */
698 UnicodeString fGMTZeroFormat;
699
700 /* Bit flags representing parse options */
701 uint32_t fDefParseOptionFlags;
702
703 /* Constant parts of GMT format pattern, populated from localized GMT format pattern*/
704 UnicodeString fGMTPatternPrefix; /* Substring before {0} */
705 UnicodeString fGMTPatternSuffix; /* Substring after {0} */
706
707 /* Compiled offset patterns generated from fGMTOffsetPatterns[] */
708 UVector* fGMTOffsetPatternItems[UTZFMT_PAT_COUNT];
709
710 UBool fAbuttingOffsetHoursAndMinutes;
711
712 /* TZDBTimeZoneNames object used for parsing */
713 TZDBTimeZoneNames* fTZDBTimeZoneNames;
714
725 UnicodeString& formatSpecific(const TimeZone& tz, UTimeZoneNameType stdType, UTimeZoneNameType dstType,
726 UDate date, UnicodeString& name, UTimeZoneFormatTimeType *timeType) const;
727
736 UnicodeString& formatGeneric(const TimeZone& tz, int32_t genType, UDate date, UnicodeString& name) const;
737
743 const TimeZoneGenericNames* getTimeZoneGenericNames(UErrorCode& status) const;
744
750 const TZDBTimeZoneNames* getTZDBTimeZoneNames(UErrorCode& status) const;
751
759 UnicodeString& formatExemplarLocation(const TimeZone& tz, UnicodeString& name) const;
760
764 enum OffsetFields {
765 FIELDS_H,
766 FIELDS_HM,
767 FIELDS_HMS
768 };
769
777 void initGMTPattern(const UnicodeString& gmtPattern, UErrorCode& status);
778
787 static UVector* parseOffsetPattern(const UnicodeString& pattern, OffsetFields required, UErrorCode& status);
788
797 static UnicodeString& expandOffsetPattern(const UnicodeString& offsetHM, UnicodeString& result, UErrorCode& status);
798
807 static UnicodeString& truncateOffsetPattern(const UnicodeString& offsetHM, UnicodeString& result, UErrorCode& status);
808
819 static UBool toCodePoints(const UnicodeString& str, UChar32* codeArray, int32_t capacity);
820
831 UnicodeString& formatOffsetISO8601(int32_t offset, UBool isBasic, UBool useUtcIndicator,
832 UBool isShort, UBool ignoreSeconds, UnicodeString& result, UErrorCode& status) const;
833
841 UnicodeString& formatOffsetLocalizedGMT(int32_t offset, UBool isShort, UnicodeString& result, UErrorCode& status) const;
842
857 int32_t parseOffsetISO8601(const UnicodeString& text, ParsePosition& pos, UBool extendedOnly,
858 UBool* hasDigitOffset = NULL) const;
859
867 void appendOffsetDigits(UnicodeString& buf, int32_t n, uint8_t minDigits) const;
868
881 int32_t parseOffsetLocalizedGMT(const UnicodeString& text, ParsePosition& pos,
882 UBool isShort, UBool* hasDigitOffset) const;
883
893 int32_t parseOffsetLocalizedGMTPattern(const UnicodeString& text, int32_t start,
894 UBool isShort, int32_t& parsedLen) const;
895
904 int32_t parseOffsetFields(const UnicodeString& text, int32_t start, UBool isShort, int32_t& parsedLen) const;
905
917 int32_t parseOffsetFieldsWithPattern(const UnicodeString& text, int32_t start,
918 UVector* patternItems, UBool forceSingleHourDigit, int32_t& hour, int32_t& min, int32_t& sec) const;
919
927 int32_t parseAbuttingOffsetFields(const UnicodeString& text, int32_t start, int32_t& parsedLen) const;
928
936 int32_t parseOffsetDefaultLocalizedGMT(const UnicodeString& text, int start, int32_t& parsedLen) const;
937
946 int32_t parseDefaultOffsetFields(const UnicodeString& text, int32_t start, UChar separator,
947 int32_t& parsedLen) const;
948
963 int32_t parseOffsetFieldWithLocalizedDigits(const UnicodeString& text, int32_t start,
964 uint8_t minDigits, uint8_t maxDigits, uint16_t minVal, uint16_t maxVal, int32_t& parsedLen) const;
965
975 int32_t parseSingleLocalizedDigit(const UnicodeString& text, int32_t start, int32_t& len) const;
976
986 static UnicodeString& formatOffsetWithAsciiDigits(int32_t offset, UChar sep,
987 OffsetFields minFields, OffsetFields maxFields, UnicodeString& result);
988
1001 static int32_t parseAbuttingAsciiOffsetFields(const UnicodeString& text, ParsePosition& pos,
1002 OffsetFields minFields, OffsetFields maxFields, UBool fixedHourWidth);
1003
1016 static int32_t parseAsciiOffsetFields(const UnicodeString& text, ParsePosition& pos, UChar sep,
1017 OffsetFields minFields, OffsetFields maxFields);
1018
1025 static UnicodeString& unquote(const UnicodeString& pattern, UnicodeString& result);
1026
1032 void initGMTOffsetPatterns(UErrorCode& status);
1033
1040 void checkAbuttingHoursAndMinutes();
1041
1047 TimeZone* createTimeZoneForOffset(int32_t offset) const;
1048
1054 static UTimeZoneFormatTimeType getTimeType(UTimeZoneNameType nameType);
1055
1064 UnicodeString& getTimeZoneID(const TimeZoneNames::MatchInfoCollection* matches, int32_t idx, UnicodeString& tzID) const;
1065
1066
1074 UnicodeString& parseZoneID(const UnicodeString& text, ParsePosition& pos, UnicodeString& tzID) const;
1075
1083 UnicodeString& parseShortZoneID(const UnicodeString& text, ParsePosition& pos, UnicodeString& tzID) const;
1084
1092 UnicodeString& parseExemplarLocation(const UnicodeString& text, ParsePosition& pos, UnicodeString& tzID) const;
1093 };
1094
1095 U_NAMESPACE_END
1096
1097 #endif /* !UCONFIG_NO_FORMATTING */
1098 #endif