ICU 50.1.2  50.1.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 
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 
30 typedef enum UTimeZoneFormatStyle {
72 
99 
122 
141 
143 
145 
146 class TimeZoneGenericNames;
147 class UVector;
148 
165 public:
170  TimeZoneFormat(const TimeZoneFormat& other);
171 
176  virtual ~TimeZoneFormat();
177 
182  TimeZoneFormat& operator=(const TimeZoneFormat& other);
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 
217  const TimeZoneNames* getTimeZoneNames() const;
218 
226  void adoptTimeZoneNames(TimeZoneNames *tznames);
227 
233  void setTimeZoneNames(const TimeZoneNames &tznames);
234 
242  UnicodeString& getGMTPattern(UnicodeString& pattern) const;
243 
252  void setGMTPattern(const UnicodeString& pattern, UErrorCode& status);
253 
262  UnicodeString& getGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, UnicodeString& pattern) const;
263 
272  void setGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, const UnicodeString& pattern, UErrorCode& status);
273 
283  UnicodeString& getGMTOffsetDigits(UnicodeString& digits) const;
284 
297  void setGMTOffsetDigits(const UnicodeString& digits, UErrorCode& status);
298 
306  UnicodeString& getGMTZeroFormat(UnicodeString& gmtZeroFormat) const;
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 
456  virtual TimeZone* parse(UTimeZoneFormatStyle style, const UnicodeString& text, ParsePosition& pos,
457  int32_t parseOptions, UTimeZoneFormatTimeType* timeType = NULL) const;
458 
474  TimeZone* parse(UTimeZoneFormatStyle style, const UnicodeString& text, ParsePosition& pos,
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 
519  virtual UClassID getDynamicClassID() const;
520 
521 protected:
528  TimeZoneFormat(const Locale& locale, UErrorCode& status);
529 
530 private:
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 
ISO 8601 format (extended), such as "-05:00", "Z"(UTC)
Definition: tzfmt.h:70
When a time zone display name is not found within a set of display names used for the specified style...
Definition: tzfmt.h:139
Base class for all formats.
Definition: format.h:94
UTimeZoneFormatGMTOffsetPatternType
Constants for GMT offset pattern types.
Definition: tzfmt.h:77
Negative offset with hour and minute fields.
Definition: tzfmt.h:92
TimeZoneFormat supports time zone display name formatting and parsing.
Definition: tzfmt.h:164
UTimeZoneFormatParseOption
Constants for parse option flags, used for specifying optional parse behavior.
Definition: tzfmt.h:127
UTimeZoneFormatTimeType
Constants for time types used by TimeZoneFormat APIs for receiving time type (standard time...
Definition: tzfmt.h:105
Generic location format, such as "United States Time (New York)", "Italy Time".
Definition: tzfmt.h:35
C++ API: TimeZone object.
double UDate
Date and Time data type.
Definition: utypes.h:201
virtual UClassID getDynamicClassID() const =0
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
#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
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
Negative offset with hour, minute and second fields.
Definition: tzfmt.h:97
virtual Format * clone() const =0
Clone this object polymorphically.
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition: timezone.h:129
C++ API: Base class for all formats.
#define U_CDECL_BEGIN
This is used to begin a declaration of a library private ICU C API.
Definition: umachine.h:82
#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_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129
MatchInfoCollection represents a collection of time zone name matches used by TimeZoneNames#find.
Definition: tznames.h:267
Daylight saving time.
Definition: tzfmt.h:120
Positive offset with hour and minute fields.
Definition: tzfmt.h:82
TimeZoneNames is an abstract class representing the time zone display name data model defined by UTS#...
Definition: tznames.h:116
C++ API: TimeZoneNames.
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition: umachine.h:298
#define NULL
Define NULL if necessary, to 0 for C++ and to ((void *)0) for C.
Definition: utypes.h:186
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
UTimeZoneFormatStyle
Constants for time zone display format style used by format/parse APIs in TimeZoneFormat.
Definition: tzfmt.h:30
Specific short format, such as "EST", "PDT".
Definition: tzfmt.h:55
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
#define U_CDECL_END
This is used to end a declaration of a library private ICU C API.
Definition: umachine.h:83
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:130
Positive offset with hour, minute and second fields.
Definition: tzfmt.h:87
Generic long non-location format, such as "Eastern Time".
Definition: tzfmt.h:40
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:476
RFC822 format, such as "-0500".
Definition: tzfmt.h:60
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:106
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:47
virtual UBool operator==(const Format &other) const =0
Return true if the given Format objects are semantically equal.
Standard time.
Definition: tzfmt.h:115
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const =0
Parse a string to produce an object.
Basic definitions for ICU, for both C and C++ APIs.
Format & operator=(const Format &)
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:246
Specific long format, such as "Eastern Standard Time".
Definition: tzfmt.h:50
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:62
UTimeZoneNameType
Constants for time zone display name types.
Definition: tznames.h:28
Localized GMT offset format, such as "GMT-05:00", "UTC+0100".
Definition: tzfmt.h:65
Generic short non-location format, such as "ET".
Definition: tzfmt.h:45
int8_t UBool
The ICU boolean type.
Definition: umachine.h:200
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:182