ICU 53.1  53.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
timezone.h
Go to the documentation of this file.
1 /*************************************************************************
2 * Copyright (c) 1997-2014, International Business Machines Corporation
3 * and others. All Rights Reserved.
4 **************************************************************************
5 *
6 * File TIMEZONE.H
7 *
8 * Modification History:
9 *
10 * Date Name Description
11 * 04/21/97 aliu Overhauled header.
12 * 07/09/97 helena Changed createInstance to createDefault.
13 * 08/06/97 aliu Removed dependency on internal header for Hashtable.
14 * 08/10/98 stephen Changed getDisplayName() API conventions to match
15 * 08/19/98 stephen Changed createTimeZone() to never return 0
16 * 09/02/98 stephen Sync to JDK 1.2 8/31
17 * - Added getOffset(... monthlen ...)
18 * - Added hasSameRules()
19 * 09/15/98 stephen Added getStaticClassID
20 * 12/03/99 aliu Moved data out of static table into icudata.dll.
21 * Hashtable replaced by new static data structures.
22 * 12/14/99 aliu Made GMT public.
23 * 08/15/01 grhoten Made GMT private and added the getGMT() function
24 **************************************************************************
25 */
26 
27 #ifndef TIMEZONE_H
28 #define TIMEZONE_H
29 
30 #include "unicode/utypes.h"
31 
37 #if !UCONFIG_NO_FORMATTING
38 
39 #include "unicode/uobject.h"
40 #include "unicode/unistr.h"
41 #include "unicode/ures.h"
42 #include "unicode/ucal.h"
43 
45 
46 class StringEnumeration;
47 
129 class U_I18N_API TimeZone : public UObject {
130 public:
134  virtual ~TimeZone();
135 
148  static const TimeZone& U_EXPORT2 getUnknown();
149 
162  static const TimeZone* U_EXPORT2 getGMT(void);
163 
175  static TimeZone* U_EXPORT2 createTimeZone(const UnicodeString& ID);
176 
192  static StringEnumeration* U_EXPORT2 createTimeZoneIDEnumeration(
193  USystemTimeZoneType zoneType,
194  const char* region,
195  const int32_t* rawOffset,
196  UErrorCode& ec);
197 
205  static StringEnumeration* U_EXPORT2 createEnumeration();
206 
224  static StringEnumeration* U_EXPORT2 createEnumeration(int32_t rawOffset);
225 
236  static StringEnumeration* U_EXPORT2 createEnumeration(const char* country);
237 
252  static int32_t U_EXPORT2 countEquivalentIDs(const UnicodeString& id);
253 
273  static const UnicodeString U_EXPORT2 getEquivalentID(const UnicodeString& id,
274  int32_t index);
275 
288  static TimeZone* U_EXPORT2 createDefault(void);
289 
303  static void U_EXPORT2 adoptDefault(TimeZone* zone);
304 
305 #ifndef U_HIDE_SYSTEM_API
306 
316  static void U_EXPORT2 setDefault(const TimeZone& zone);
317 #endif /* U_HIDE_SYSTEM_API */
318 
325  static const char* U_EXPORT2 getTZDataVersion(UErrorCode& status);
326 
340  static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id,
341  UnicodeString& canonicalID, UErrorCode& status);
342 
358  static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id,
359  UnicodeString& canonicalID, UBool& isSystemID, UErrorCode& status);
360 
361 #ifndef U_HIDE_DRAFT_API
362 
384  static UnicodeString& U_EXPORT2 getWindowsID(const UnicodeString& id,
385  UnicodeString& winid, UErrorCode& status);
386 
413  static UnicodeString& U_EXPORT2 getIDForWindowsID(const UnicodeString& winid, const char* region,
414  UnicodeString& id, UErrorCode& status);
415 
416 #endif /* U_HIDE_DRAFT_API */
417 
427  virtual UBool operator==(const TimeZone& that) const;
428 
438  UBool operator!=(const TimeZone& that) const {return !operator==(that);}
439 
464  virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
465  uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const = 0;
466 
487  virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
488  uint8_t dayOfWeek, int32_t milliseconds,
489  int32_t monthLength, UErrorCode& status) const = 0;
490 
514  virtual void getOffset(UDate date, UBool local, int32_t& rawOffset,
515  int32_t& dstOffset, UErrorCode& ec) const;
516 
524  virtual void setRawOffset(int32_t offsetMillis) = 0;
525 
533  virtual int32_t getRawOffset(void) const = 0;
534 
542  UnicodeString& getID(UnicodeString& ID) const;
543 
557  void setID(const UnicodeString& ID);
558 
568  SHORT = 1,
607  GENERIC_LOCATION
608  };
609 
621  UnicodeString& getDisplayName(UnicodeString& result) const;
622 
636  UnicodeString& getDisplayName(const Locale& locale, UnicodeString& result) const;
637 
650  UnicodeString& getDisplayName(UBool daylight, EDisplayType style, UnicodeString& result) const;
651 
666  UnicodeString& getDisplayName(UBool daylight, EDisplayType style, const Locale& locale, UnicodeString& result) const;
667 
702  virtual UBool useDaylightTime(void) const = 0;
703 
717  virtual UBool inDaylightTime(UDate date, UErrorCode& status) const = 0;
718 
727  virtual UBool hasSameRules(const TimeZone& other) const;
728 
736  virtual TimeZone* clone(void) const = 0;
737 
744  static UClassID U_EXPORT2 getStaticClassID(void);
745 
757  virtual UClassID getDynamicClassID(void) const = 0;
758 
774  virtual int32_t getDSTSavings() const;
775 
793  static int32_t U_EXPORT2 getRegion(const UnicodeString& id,
794  char *region, int32_t capacity, UErrorCode& status);
795 
796 protected:
797 
802  TimeZone();
803 
809  TimeZone(const UnicodeString &id);
810 
816  TimeZone(const TimeZone& source);
817 
823  TimeZone& operator=(const TimeZone& right);
824 
825 #ifndef U_HIDE_INTERNAL_API
826 
835  static UResourceBundle* loadRule(const UResourceBundle* top, const UnicodeString& ruleid, UResourceBundle* oldbundle, UErrorCode&status);
836 #endif /* U_HIDE_INTERNAL_API */
837 
838 private:
839  friend class ZoneMeta;
840 
841 
842  static TimeZone* createCustomTimeZone(const UnicodeString&); // Creates a time zone based on the string.
843 
852  static const UChar* findID(const UnicodeString& id);
853 
862  static const UChar* dereferOlsonLink(const UnicodeString& id);
863 
870  static const UChar* getRegion(const UnicodeString& id);
871 
872  public:
873 #ifndef U_HIDE_INTERNAL_API
874 
882  static const UChar* getRegion(const UnicodeString& id, UErrorCode& status);
883 #endif /* U_HIDE_INTERNAL_API */
884 
885  private:
896  static UBool parseCustomID(const UnicodeString& id, int32_t& sign, int32_t& hour,
897  int32_t& minute, int32_t& second);
898 
909  static UnicodeString& getCustomID(const UnicodeString& id, UnicodeString& normalized,
910  UErrorCode& status);
911 
921  static UnicodeString& formatCustomID(int32_t hour, int32_t min, int32_t sec,
922  UBool negative, UnicodeString& id);
923 
924  UnicodeString fID; // this time zone's ID
925 
926  friend class TZEnumeration;
927 };
928 
929 
930 // -------------------------------------
931 
932 inline UnicodeString&
933 TimeZone::getID(UnicodeString& ID) const
934 {
935  ID = fID;
936  return ID;
937 }
938 
939 // -------------------------------------
940 
941 inline void
942 TimeZone::setID(const UnicodeString& ID)
943 {
944  fID = ID;
945 }
947 
948 #endif /* #if !UCONFIG_NO_FORMATTING */
949 
950 #endif //_TIMEZONE
951 //eof
C API: Calendar.
virtual UClassID getDynamicClassID() const
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
double UDate
Date and Time data type.
Definition: utypes.h:201
C++ API: Unicode String.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:91
Base class for 'pure' C++ implementations of uenum api.
Definition: strenum.h:55
EDisplayType
Enum for use with getDisplayName.
Definition: timezone.h:563
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition: timezone.h:129
#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
Selector for short display name derived from time zone offset.
Definition: timezone.h:589
Selector for short generic display name.
Definition: timezone.h:578
Selector for long generic display name.
Definition: timezone.h:583
Selector for long display name.
Definition: timezone.h:573
C++ API: Common ICU base class UObject.
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_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:130
Selector for short display name derived from the time zone's fallback name.
Definition: timezone.h:601
UBool operator!=(const TimeZone &that) const
Returns true if the two TimeZones are NOT equal; that is, if operator==() returns false...
Definition: timezone.h:438
USystemTimeZoneType
System time zone type constants used by filtering zones in ucal_openTimeZoneIDEnumeration.
Definition: ucal.h:530
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:476
Basic definitions for ICU, for both C and C++ APIs.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:245
struct UResourceBundle UResourceBundle
Definition: ures.h:57
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:221
Selector for long display name derived from time zone offset.
Definition: timezone.h:595
C API: Resource Bundle.
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:185