ICU 50.2 50.2
tzfmt.h
Go to the documentation of this file.
1/*
2*******************************************************************************
3* Copyright (C) 2011-2012, International Business Machines Corporation and *
4* others. All Rights Reserved. *
5*******************************************************************************
6*/
7#ifndef __TZFMT_H
8#define __TZFMT_H
9
14
15#include "unicode/utypes.h"
16
17#if !UCONFIG_NO_FORMATTING
18#ifndef U_HIDE_INTERNAL_API
19
20#include "unicode/format.h"
21#include "unicode/timezone.h"
22#include "unicode/tznames.h"
23
72
99
122
141
143
145
146class TimeZoneGenericNames;
147class UVector;
148
165public:
171
177
183
192 virtual UBool operator==(const Format& other) const;
193
200 virtual Format* clone() const;
201
210 static TimeZoneFormat* U_EXPORT2 createInstance(const Locale& locale, UErrorCode& status);
211
218
227
233 void setTimeZoneNames(const TimeZoneNames &tznames);
234
243
252 void setGMTPattern(const UnicodeString& pattern, UErrorCode& status);
253
263
273
284
297 void setGMTOffsetDigits(const UnicodeString& digits, UErrorCode& status);
298
307
315 void setGMTZeroFormat(const UnicodeString& gmtZeroFormat, UErrorCode& status);
316
324 uint32_t getDefaultParseOptions(void) const;
325
334 void setDefaultParseOptions(uint32_t flags);
335
346 UnicodeString& formatOffsetRFC822(int32_t offset, UnicodeString& result, UErrorCode& status) const;
347
358 UnicodeString& formatOffsetISO8601(int32_t offset, UnicodeString& result, UErrorCode& status) const;
359
376 UnicodeString& formatOffsetLocalizedGMT(int32_t offset, UnicodeString& result, UErrorCode& status) const;
377
378 using Format::format;
379
393 virtual UnicodeString& format(UTimeZoneFormatStyle style, const TimeZone& tz, UDate date,
394 UnicodeString& name, UTimeZoneFormatTimeType* timeType = NULL) const;
395
409 int32_t parseOffsetRFC822(const UnicodeString& text, ParsePosition& pos) const;
410
424 int32_t parseOffsetISO8601(const UnicodeString& text, ParsePosition& pos) const;
425
438 int32_t parseOffsetLocalizedGMT(const UnicodeString& text, ParsePosition& pos) const;
439
457 int32_t parseOptions, UTimeZoneFormatTimeType* timeType = NULL) const;
458
475 UTimeZoneFormatTimeType* timeType = NULL) const;
476
477 /* ----------------------------------------------
478 * Format APIs
479 * ---------------------------------------------- */
480
492 virtual UnicodeString& format(const Formattable& obj, UnicodeString& appendTo,
493 FieldPosition& pos, UErrorCode& status) const;
494
507 virtual void parseObject(const UnicodeString& source, Formattable& result, ParsePosition& parse_pos) const;
508
513 static UClassID U_EXPORT2 getStaticClassID(void);
514
520
521protected:
528 TimeZoneFormat(const Locale& locale, UErrorCode& status);
529
530private:
531 /* Locale of this object */
532 Locale fLocale;
533
534 /* Stores the region (could be implicit default) */
535 char fTargetRegion[ULOC_COUNTRY_CAPACITY];
536
537 /* TimeZoneNames object used by this formatter */
538 TimeZoneNames* fTimeZoneNames;
539
540 /* TimeZoneGenericNames object used by this formatter - lazily instantiated */
541 TimeZoneGenericNames* fTimeZoneGenericNames;
542
543 /* Localized GMT format pattern - e.g. "GMT{0}" */
544 UnicodeString fGMTPattern;
545
546 /* Array of offset patterns used by Localized GMT format - e.g. "+HH:mm" */
547 UnicodeString fGMTOffsetPatterns[UTZFMT_PAT_NEGATIVE_HMS + 1];
548
549 /* Localized decimal digits used by Localized GMT format */
550 UChar32 fGMTOffsetDigits[10];
551
552 /* Localized GMT zero format - e.g. "GMT" */
553 UnicodeString fGMTZeroFormat;
554
555 /* Bit flags representing parse options */
556 uint32_t fDefParseOptionFlags;
557
558 /* Constant parts of GMT format pattern, populated from localized GMT format pattern*/
559 UnicodeString fGMTPatternPrefix; /* Substring before {0} */
560 UnicodeString fGMTPatternSuffix; /* Substring after {0} */
561
562 /* Compiled offset patterns generated from fGMTOffsetPatterns[] */
563 UVector* fGMTOffsetPatternItems[UTZFMT_PAT_NEGATIVE_HMS + 1];
564
575 UnicodeString& formatSpecific(const TimeZone& tz, UTimeZoneNameType stdType, UTimeZoneNameType dstType,
576 UDate date, UnicodeString& name, UTimeZoneFormatTimeType *timeType) const;
577
586 UnicodeString& formatGeneric(const TimeZone& tz, int32_t genType, UDate date, UnicodeString& name) const;
587
593 const TimeZoneGenericNames* getTimeZoneGenericNames(UErrorCode& status) const;
594
598 enum OffsetFields {
599 FIELDS_H,
600 FIELDS_HM,
601 FIELDS_HMS
602 };
603
611 void initGMTPattern(const UnicodeString& gmtPattern, UErrorCode& status);
612
621 static UVector* parseOffsetPattern(const UnicodeString& pattern, OffsetFields required, UErrorCode& status);
622
630 static UnicodeString& expandOffsetPattern(const UnicodeString& offsetHM, UnicodeString& result);
631
642 static UBool toCodePoints(const UnicodeString& str, UChar32* codeArray, int32_t capacity);
643
658 int32_t parseOffsetISO8601(const UnicodeString& text, ParsePosition& pos, UBool extendedOnly,
659 UBool* hasDigitOffset = NULL) const;
660
668 void appendOffsetDigits(UnicodeString& buf, int32_t n, uint8_t minDigits) const;
669
681 int32_t parseOffsetLocalizedGMT(const UnicodeString& text, ParsePosition& pos,
682 UBool* hasDigitOffset) const;
683
692 int32_t parseOffsetFields(const UnicodeString& text, int32_t start, UBool minimumHourWidth,
693 int32_t& parsedLen) const;
694
702 int32_t parseAbuttingOffsetFields(const UnicodeString& text, int32_t start, int32_t& parsedLen) const;
703
711 int32_t parseOffsetDefaultLocalizedGMT(const UnicodeString& text, int start, int32_t& parsedLen) const;
712
721 int32_t parseDefaultOffsetFields(const UnicodeString& text, int32_t start, UChar separator,
722 int32_t& parsedLen) const;
723
738 int32_t parseOffsetFieldWithLocalizedDigits(const UnicodeString& text, int32_t start,
739 uint8_t minDigits, uint8_t maxDigits, uint16_t minVal, uint16_t maxVal, int32_t& parsedLen) const;
740
750 int32_t parseSingleLocalizedDigit(const UnicodeString& text, int32_t start, int32_t& len) const;
751
761 static UnicodeString& formatOffsetWithAsciiDigits(int32_t offset, UChar sep,
762 OffsetFields minFields, OffsetFields maxFields, UnicodeString& result);
763
776 static int32_t parseAbuttingAsciiOffsetFields(const UnicodeString& text, ParsePosition& pos,
777 OffsetFields minFields, OffsetFields maxFields, UBool fixedHourWidth);
778
792 static int32_t parseAsciiOffsetFields(const UnicodeString& text, ParsePosition& pos, UChar sep,
793 OffsetFields minFields, OffsetFields maxFields, UBool fixedHourWidth);
794
801 static UnicodeString& unquote(const UnicodeString& pattern, UnicodeString& result);
802
808 void initGMTOffsetPatterns(UErrorCode& status);
809
815 TimeZone* createTimeZoneForOffset(int32_t offset) const;
816
822 static UTimeZoneFormatTimeType getTimeType(UTimeZoneNameType nameType);
823
824 /*
825 * Returns the time zone ID of a match at the specified index within
826 * the MatchInfoCollection.
827 * @param matches the collection of matches
828 * @param idx the index withing matches
829 * @param tzID receives the resolved time zone ID
830 * @return a reference to tzID.
831 */
832 UnicodeString& getTimeZoneID(const TimeZoneNames::MatchInfoCollection* matches, int32_t idx, UnicodeString& tzID) const;
833};
834
836
837#endif /* U_HIDE_INTERNAL_API */
838#endif
839#endif
840
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition fieldpos.h:106
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
Format()
Default constructor for subclass use only.
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition fmtable.h:62
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:182
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition parsepos.h:47
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.
UnicodeString & formatOffsetRFC822(int32_t offset, UnicodeString &result, UErrorCode &status) const
Returns the RFC822 style time zone string 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).
int32_t parseOffsetRFC822(const UnicodeString &text, ParsePosition &pos) const
Returns offset from GMT(UTC) in milliseconds for the given RFC822 style time zone string.
void setGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, const UnicodeString &pattern, UErrorCode &status)
Sets the offset pattern for the given offset type.
UnicodeString & formatOffsetISO8601(int32_t offset, UnicodeString &result, UErrorCode &status) const
Returns the ISO 8601 style time zone string for the given offset.
TimeZoneFormat & operator=(const TimeZoneFormat &other)
Assignment operator.
UnicodeString & getGMTOffsetDigits(UnicodeString &digits) const
Returns the decimal digit characters used for localized GMT format.
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.
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:267
TimeZoneNames is an abstract class representing the time zone display name data model defined by UTS#...
Definition tznames.h:116
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:247
C++ API: Base class for all formats.
C++ API: TimeZone object.
UTimeZoneFormatGMTOffsetPatternType
Constants for GMT offset pattern types.
Definition tzfmt.h:77
@ UTZFMT_PAT_NEGATIVE_HM
Negative offset with hour and minute fields.
Definition tzfmt.h:92
@ UTZFMT_PAT_POSITIVE_HMS
Positive offset with hour, minute and second fields.
Definition tzfmt.h:87
@ UTZFMT_PAT_NEGATIVE_HMS
Negative offset with hour, minute and second fields.
Definition tzfmt.h:97
@ UTZFMT_PAT_POSITIVE_HM
Positive offset with hour and minute fields.
Definition tzfmt.h:82
UTimeZoneFormatStyle
Constants for time zone display format style used by format/parse APIs in TimeZoneFormat.
Definition tzfmt.h:30
@ UTZFMT_STYLE_ISO8601
ISO 8601 format (extended), such as "-05:00", "Z"(UTC)
Definition tzfmt.h:70
@ UTZFMT_STYLE_GENERIC_LONG
Generic long non-location format, such as "Eastern Time".
Definition tzfmt.h:40
@ UTZFMT_STYLE_LOCALIZED_GMT
Localized GMT offset format, such as "GMT-05:00", "UTC+0100".
Definition tzfmt.h:65
@ UTZFMT_STYLE_RFC822
RFC822 format, such as "-0500".
Definition tzfmt.h:60
@ UTZFMT_STYLE_GENERIC_LOCATION
Generic location format, such as "United States Time (New York)", "Italy Time".
Definition tzfmt.h:35
@ UTZFMT_STYLE_SPECIFIC_SHORT
Specific short format, such as "EST", "PDT".
Definition tzfmt.h:55
@ UTZFMT_STYLE_GENERIC_SHORT
Generic short non-location format, such as "ET".
Definition tzfmt.h:45
@ UTZFMT_STYLE_SPECIFIC_LONG
Specific long format, such as "Eastern Standard Time".
Definition tzfmt.h:50
UTimeZoneFormatParseOption
Constants for parse option flags, used for specifying optional parse behavior.
Definition tzfmt.h:127
@ 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:139
@ UTZFMT_PARSE_OPTION_NONE
No option.
Definition tzfmt.h:132
UTimeZoneFormatTimeType
Constants for time types used by TimeZoneFormat APIs for receiving time type (standard time,...
Definition tzfmt.h:105
@ UTZFMT_TIME_TYPE_DAYLIGHT
Daylight saving time.
Definition tzfmt.h:120
@ UTZFMT_TIME_TYPE_UNKNOWN
Unknown.
Definition tzfmt.h:110
@ UTZFMT_TIME_TYPE_STANDARD
Standard time.
Definition tzfmt.h:115
C++ API: TimeZoneNames.
UTimeZoneNameType
Constants for time zone display name types.
Definition tznames.h:28
#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
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition umachine.h:298
#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:200
#define U_CDECL_BEGIN
This is used to begin a declaration of a library private ICU C API.
Definition umachine.h:82
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:278
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:96
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
double UDate
Date and Time data type.
Definition utypes.h:201
#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