ICU 4.8.1.1  4.8.1.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
timezone.h
Go to the documentation of this file.
1 /*************************************************************************
2 * Copyright (c) 1997-2011, 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 
123 class U_I18N_API TimeZone : public UObject {
124 public:
128  virtual ~TimeZone();
129 
136  static const TimeZone* U_EXPORT2 getGMT(void);
137 
148  static TimeZone* U_EXPORT2 createTimeZone(const UnicodeString& ID);
149 
150 
166  static StringEnumeration* U_EXPORT2 createTimeZoneIDEnumeration(
167  USystemTimeZoneType zoneType,
168  const char* region,
169  const int32_t* rawOffset,
170  UErrorCode& ec);
171 
179  static StringEnumeration* U_EXPORT2 createEnumeration();
180 
198  static StringEnumeration* U_EXPORT2 createEnumeration(int32_t rawOffset);
199 
210  static StringEnumeration* U_EXPORT2 createEnumeration(const char* country);
211 
226  static int32_t U_EXPORT2 countEquivalentIDs(const UnicodeString& id);
227 
247  static const UnicodeString U_EXPORT2 getEquivalentID(const UnicodeString& id,
248  int32_t index);
249 
262  static TimeZone* U_EXPORT2 createDefault(void);
263 
273  static void U_EXPORT2 adoptDefault(TimeZone* zone);
274 
282  static void U_EXPORT2 setDefault(const TimeZone& zone);
283 
290  static const char* U_EXPORT2 getTZDataVersion(UErrorCode& status);
291 
305  static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id,
306  UnicodeString& canonicalID, UErrorCode& status);
307 
323  static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id,
324  UnicodeString& canonicalID, UBool& isSystemID, UErrorCode& status);
325 
335  virtual UBool operator==(const TimeZone& that) const;
336 
346  UBool operator!=(const TimeZone& that) const {return !operator==(that);}
347 
372  virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
373  uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const = 0;
374 
395  virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
396  uint8_t dayOfWeek, int32_t milliseconds,
397  int32_t monthLength, UErrorCode& status) const = 0;
398 
422  virtual void getOffset(UDate date, UBool local, int32_t& rawOffset,
423  int32_t& dstOffset, UErrorCode& ec) const;
424 
432  virtual void setRawOffset(int32_t offsetMillis) = 0;
433 
441  virtual int32_t getRawOffset(void) const = 0;
442 
450  UnicodeString& getID(UnicodeString& ID) const;
451 
465  void setID(const UnicodeString& ID);
466 
476  SHORT = 1,
515  GENERIC_LOCATION
516  };
517 
529  UnicodeString& getDisplayName(UnicodeString& result) const;
530 
544  UnicodeString& getDisplayName(const Locale& locale, UnicodeString& result) const;
545 
558  UnicodeString& getDisplayName(UBool daylight, EDisplayType style, UnicodeString& result) const;
559 
574  UnicodeString& getDisplayName(UBool daylight, EDisplayType style, const Locale& locale, UnicodeString& result) const;
575 
592  virtual UBool useDaylightTime(void) const = 0;
593 
607  virtual UBool inDaylightTime(UDate date, UErrorCode& status) const = 0;
608 
617  virtual UBool hasSameRules(const TimeZone& other) const;
618 
626  virtual TimeZone* clone(void) const = 0;
627 
634  static UClassID U_EXPORT2 getStaticClassID(void);
635 
647  virtual UClassID getDynamicClassID(void) const = 0;
648 
664  virtual int32_t getDSTSavings() const;
665 
683  static int32_t U_EXPORT2 getRegion(const UnicodeString& id,
684  char *region, int32_t capacity, UErrorCode& status);
685 
686 protected:
687 
692  TimeZone();
693 
699  TimeZone(const UnicodeString &id);
700 
706  TimeZone(const TimeZone& source);
707 
713  TimeZone& operator=(const TimeZone& right);
714 
724  static UResourceBundle* loadRule(const UResourceBundle* top, const UnicodeString& ruleid, UResourceBundle* oldbundle, UErrorCode&status);
725 
726 
727 private:
728  friend class ZoneMeta;
729 
730 
731  static TimeZone* createCustomTimeZone(const UnicodeString&); // Creates a time zone based on the string.
732 
741  static const UChar* findID(const UnicodeString& id);
742 
751  static const UChar* dereferOlsonLink(const UnicodeString& id);
752 
759  static const UChar* getRegion(const UnicodeString& id);
760 
768  static const UChar* getRegion(const UnicodeString& id, UErrorCode& status);
769 
780  static UBool parseCustomID(const UnicodeString& id, int32_t& sign, int32_t& hour,
781  int32_t& minute, int32_t& second);
782 
793  static UnicodeString& getCustomID(const UnicodeString& id, UnicodeString& normalized,
794  UErrorCode& status);
795 
805  static UnicodeString& formatCustomID(int32_t hour, int32_t min, int32_t sec,
806  UBool negative, UnicodeString& id);
807 
813  static void initDefault(void);
814 
815  // See source file for documentation
823  static TimeZone* createSystemTimeZone(const UnicodeString& name);
824  static TimeZone* createSystemTimeZone(const UnicodeString& name, UErrorCode& ec);
825 
826  UnicodeString fID; // this time zone's ID
827 
828  friend class TZEnumeration;
829 };
830 
831 
832 // -------------------------------------
833 
834 inline UnicodeString&
836 {
837  ID = fID;
838  return ID;
839 }
840 
841 // -------------------------------------
842 
843 inline void
845 {
846  fID = ID;
847 }
849 
850 #endif /* #if !UCONFIG_NO_FORMATTING */
851 
852 #endif //_TIMEZONE
853 //eof
EDisplayType
Enum for use with getDisplayName.
Definition: timezone.h:471
C API: Calendar.
double UDate
Date and Time data type.
Definition: utypes.h:314
Selector for short display name derived from time zone offset.
Definition: timezone.h:497
C++ API: Unicode String.
UBool operator!=(const TimeZone &that) const
Returns true if the two TimeZones are NOT equal; that is, if operator==() returns false...
Definition: timezone.h:346
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:521
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:131
Selector for long display name derived from time zone offset.
Definition: timezone.h:503
Selector for short display name derived from the time zone's fallback name.
Definition: timezone.h:509
Selector for long display name.
Definition: timezone.h:481
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:188
#define U_EXPORT2
Definition: platform.h:314
C++ API: Common ICU base class UObject.
uint16_t UChar
Define UChar to be wchar_t if that is 16 bits wide; always assumed to be unsigned.
Definition: umachine.h:325
Selector for short generic display name.
Definition: timezone.h:486
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:132
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:215
Selector for long generic display name.
Definition: timezone.h:491
void * UClassID
UClassID is used to identify classes without using RTTI, since RTTI is not yet supported by all C++ c...
Definition: utypes.h:385
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:639
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition: timezone.h:123
Base class for 'pure' C++ implementations of uenum api.
Definition: strenum.h:55
void setID(const UnicodeString &ID)
Sets the TimeZone's ID to the specified value.
Definition: timezone.h:844
Basic definitions for ICU, for both C and C++ APIs.
struct UResourceBundle UResourceBundle
Definition: ures.h:57
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:181
virtual UClassID getDynamicClassID() const =0
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
C API: Resource Bundle.
int8_t UBool
The ICU boolean type.
Definition: umachine.h:228
UnicodeString & getID(UnicodeString &ID) const
Fills in "ID" with the TimeZone's ID.
Definition: timezone.h:835