ICU 49.1.1  49.1.1
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 
144 typedef void *UMTX;
145 
147 
148 class TimeZoneGenericNames;
149 class UVector;
150 
167 public:
172  TimeZoneFormat(const TimeZoneFormat& other);
173 
178  virtual ~TimeZoneFormat();
179 
184  TimeZoneFormat& operator=(const TimeZoneFormat& other);
185 
194  virtual UBool operator==(const Format& other) const;
195 
202  virtual Format* clone() const;
203 
212  static TimeZoneFormat* U_EXPORT2 createInstance(const Locale& locale, UErrorCode& status);
213 
219  const TimeZoneNames* getTimeZoneNames() const;
220 
228  void adoptTimeZoneNames(TimeZoneNames *tznames);
229 
235  void setTimeZoneNames(const TimeZoneNames &tznames);
236 
244  UnicodeString& getGMTPattern(UnicodeString& pattern) const;
245 
254  void setGMTPattern(const UnicodeString& pattern, UErrorCode& status);
255 
264  UnicodeString& getGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, UnicodeString& pattern) const;
265 
274  void setGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, const UnicodeString& pattern, UErrorCode& status);
275 
282  UnicodeString& getGMTOffsetDigits(UnicodeString& digits) const;
283 
290  void setGMTOffsetDigits(const UnicodeString& digits, UErrorCode& status);
291 
298  UnicodeString& getGMTZeroFormat(UnicodeString& gmtZeroFormat) const;
299 
306  void setGMTZeroFormat(const UnicodeString& gmtZeroFormat, UErrorCode& status);
307 
315  int32_t getDefaultParseOptions(void) const;
316 
325  void setDefaultParseOptions(int32_t flags);
326 
336  UnicodeString& formatOffsetRFC822(int32_t offset, UnicodeString& result, UErrorCode& status) const;
337 
347  UnicodeString& formatOffsetISO8601(int32_t offset, UnicodeString& result, UErrorCode& status) const;
348 
364  UnicodeString& formatOffsetLocalizedGMT(int32_t offset, UnicodeString& result, UErrorCode& status) const;
365 
379  virtual UnicodeString& format(UTimeZoneFormatStyle style, const TimeZone& tz, UDate date,
380  UnicodeString& name, UTimeZoneFormatTimeType* timeType = NULL) const;
381 
395  int32_t parseOffsetRFC822(const UnicodeString& text, ParsePosition& pos) const;
396 
410  int32_t parseOffsetISO8601(const UnicodeString& text, ParsePosition& pos) const;
411 
424  int32_t parseOffsetLocalizedGMT(const UnicodeString& text, ParsePosition& pos) const;
425 
442  virtual TimeZone* parse(UTimeZoneFormatStyle style, const UnicodeString& text, ParsePosition& pos,
443  int32_t parseOptions, UTimeZoneFormatTimeType* timeType = NULL) const;
444 
460  TimeZone* parse(UTimeZoneFormatStyle style, const UnicodeString& text, ParsePosition& pos,
461  UTimeZoneFormatTimeType* timeType = NULL) const;
462 
463  /* ----------------------------------------------
464  * Format APIs
465  * ---------------------------------------------- */
466 
478  virtual UnicodeString& format(const Formattable& obj, UnicodeString& appendTo,
479  FieldPosition& pos, UErrorCode& status) const;
480 
493  virtual void parseObject(const UnicodeString& source, Formattable& result, ParsePosition& parse_pos) const;
494 
499  static UClassID U_EXPORT2 getStaticClassID(void);
500 
505  virtual UClassID getDynamicClassID() const;
506 
507 protected:
514  TimeZoneFormat(const Locale& locale, UErrorCode& status);
515 
516 private:
517  /* mutex */
518  UMTX fLock;
519 
520  /* Locale of this object */
521  Locale fLocale;
522 
523  /* Stores the region (could be implicit default) */
524  char fTargetRegion[ULOC_COUNTRY_CAPACITY];
525 
526  /* TimeZoneNames object used by this formatter */
527  TimeZoneNames* fTimeZoneNames;
528 
529  /* TimeZoneGenericNames object used by this formatter - lazily instantiated */
530  TimeZoneGenericNames* fTimeZoneGenericNames;
531 
532  /* Localized GMT format pattern - e.g. "GMT{0}" */
533  UnicodeString fGMTPattern;
534 
535  /* Array of offset patterns used by Localized GMT format - e.g. "+HH:mm" */
536  UnicodeString fGMTOffsetPatterns[UTZFMT_PAT_NEGATIVE_HMS + 1];
537 
538  /* Localized decimal digits used by Localized GMT format */
539  UChar32 fGMTOffsetDigits[10];
540 
541  /* Localized GMT zero format - e.g. "GMT" */
542  UnicodeString fGMTZeroFormat;
543 
544  /* Bit flags representing parse options */
545  int32_t fDefParseOptionFlags;
546 
547  /* Constant parts of GMT format pattern, populated from localized GMT format pattern*/
548  UnicodeString fGMTPatternPrefix; /* Substring before {0} */
549  UnicodeString fGMTPatternSuffix; /* Substring after {0} */
550 
551  /* Compiled offset patterns generated from fGMTOffsetPatterns[] */
552  UVector* fGMTOffsetPatternItems[UTZFMT_PAT_NEGATIVE_HMS + 1];
553 
564  UnicodeString& formatSpecific(const TimeZone& tz, UTimeZoneNameType stdType, UTimeZoneNameType dstType,
565  UDate date, UnicodeString& name, UTimeZoneFormatTimeType *timeType) const;
566 
575  UnicodeString& formatGeneric(const TimeZone& tz, int32_t genType, UDate date, UnicodeString& name) const;
576 
582  const TimeZoneGenericNames* getTimeZoneGenericNames(UErrorCode& status) const;
583 
587  enum OffsetFields {
588  FIELDS_H,
589  FIELDS_HM,
590  FIELDS_HMS
591  };
592 
600  void initGMTPattern(const UnicodeString& gmtPattern, UErrorCode& status);
601 
610  static UVector* parseOffsetPattern(const UnicodeString& pattern, OffsetFields required, UErrorCode& status);
611 
619  static UnicodeString& expandOffsetPattern(const UnicodeString& offsetHM, UnicodeString& result);
620 
631  static UBool toCodePoints(const UnicodeString& str, UChar32* codeArray, int32_t capacity);
632 
647  int32_t parseOffsetISO8601(const UnicodeString& text, ParsePosition& pos, UBool extendedOnly,
648  UBool* hasDigitOffset = NULL) const;
649 
657  void appendOffsetDigits(UnicodeString& buf, int32_t n, uint8_t minDigits) const;
658 
670  int32_t parseOffsetLocalizedGMT(const UnicodeString& text, ParsePosition& pos,
671  UBool* hasDigitOffset) const;
672 
681  int32_t parseOffsetFields(const UnicodeString& text, int32_t start, UBool minimumHourWidth,
682  int32_t& parsedLen) const;
683 
691  int32_t parseAbuttingOffsetFields(const UnicodeString& text, int32_t start, int32_t& parsedLen) const;
692 
700  int32_t parseOffsetDefaultLocalizedGMT(const UnicodeString& text, int start, int32_t& parsedLen) const;
701 
710  int32_t parseDefaultOffsetFields(const UnicodeString& text, int32_t start, UChar separator,
711  int32_t& parsedLen) const;
712 
727  int32_t parseOffsetFieldWithLocalizedDigits(const UnicodeString& text, int32_t start,
728  uint8_t minDigits, uint8_t maxDigits, uint16_t minVal, uint16_t maxVal, int32_t& parsedLen) const;
729 
739  int32_t parseSingleLocalizedDigit(const UnicodeString& text, int32_t start, int32_t& len) const;
740 
750  static UnicodeString& formatOffsetWithAsciiDigits(int32_t offset, UChar sep,
751  OffsetFields minFields, OffsetFields maxFields, UnicodeString& result);
752 
765  static int32_t parseAbuttingAsciiOffsetFields(const UnicodeString& text, ParsePosition& pos,
766  OffsetFields minFields, OffsetFields maxFields, UBool fixedHourWidth);
767 
781  static int32_t parseAsciiOffsetFields(const UnicodeString& text, ParsePosition& pos, UChar sep,
782  OffsetFields minFields, OffsetFields maxFields, UBool fixedHourWidth);
783 
790  static UnicodeString& unquote(const UnicodeString& pattern, UnicodeString& result);
791 
797  void initGMTOffsetPatterns(UErrorCode& status);
798 
804  TimeZone* createTimeZoneForOffset(int32_t offset) const;
805 
811  static UTimeZoneFormatTimeType getTimeType(UTimeZoneNameType nameType);
812 
813  /*
814  * Returns the time zone ID of a match at the specified index within
815  * the MatchInfoCollection.
816  * @param matches the collection of matches
817  * @param idx the index withing matches
818  * @param tzID receives the resolved time zone ID
819  * @return a reference to tzID.
820  */
821  UnicodeString& getTimeZoneID(const TimeZoneNames::MatchInfoCollection* matches, int32_t idx, UnicodeString& tzID) const;
822 };
823 
825 
826 #endif /* U_HIDE_INTERNAL_API */
827 #endif
828 #endif
829