ICU 50.1.2  50.1.2
timezone.h
Go to the documentation of this file.
1 /*************************************************************************
2 * Copyright (c) 1997-2012, 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 
136 #ifndef U_HIDE_DRAFT_API
137 
149  static const TimeZone& U_EXPORT2 getUnknown();
150 #endif /* U_HIDE_DRAFT_API */
151 
164  static const TimeZone* U_EXPORT2 getGMT(void);
165 
177  static TimeZone* U_EXPORT2 createTimeZone(const UnicodeString& ID);
178 
194  static StringEnumeration* U_EXPORT2 createTimeZoneIDEnumeration(
195  USystemTimeZoneType zoneType,
196  const char* region,
197  const int32_t* rawOffset,
198  UErrorCode& ec);
199 
207  static StringEnumeration* U_EXPORT2 createEnumeration();
208 
226  static StringEnumeration* U_EXPORT2 createEnumeration(int32_t rawOffset);
227 
238  static StringEnumeration* U_EXPORT2 createEnumeration(const char* country);
239 
254  static int32_t U_EXPORT2 countEquivalentIDs(const UnicodeString& id);
255 
275  static const UnicodeString U_EXPORT2 getEquivalentID(const UnicodeString& id,
276  int32_t index);
277 
290  static TimeZone* U_EXPORT2 createDefault(void);
291 
301  static void U_EXPORT2 adoptDefault(TimeZone* zone);
302 
303 #ifndef U_HIDE_SYSTEM_API
304 
312  static void U_EXPORT2 setDefault(const TimeZone& zone);
313 #endif /* U_HIDE_SYSTEM_API */
314 
321  static const char* U_EXPORT2 getTZDataVersion(UErrorCode& status);
322 
336  static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id,
337  UnicodeString& canonicalID, UErrorCode& status);
338 
354  static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id,
355  UnicodeString& canonicalID, UBool& isSystemID, UErrorCode& status);
356 
366  virtual UBool operator==(const TimeZone& that) const;
367 
377  UBool operator!=(const TimeZone& that) const {return !operator==(that);}
378 
403  virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
404  uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const = 0;
405 
426  virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
427  uint8_t dayOfWeek, int32_t milliseconds,
428  int32_t monthLength, UErrorCode& status) const = 0;
429 
453  virtual void getOffset(UDate date, UBool local, int32_t& rawOffset,
454  int32_t& dstOffset, UErrorCode& ec) const;
455 
463  virtual void setRawOffset(int32_t offsetMillis) = 0;
464 
472  virtual int32_t getRawOffset(void) const = 0;
473 
481  UnicodeString& getID(UnicodeString& ID) const;
482 
496  void setID(const UnicodeString& ID);
497 
507  SHORT = 1,
546  GENERIC_LOCATION
547  };
548 
560  UnicodeString& getDisplayName(UnicodeString& result) const;
561 
575  UnicodeString& getDisplayName(const Locale& locale, UnicodeString& result) const;
576 
589  UnicodeString& getDisplayName(UBool daylight, EDisplayType style, UnicodeString& result) const;
590 
605  UnicodeString& getDisplayName(UBool daylight, EDisplayType style, const Locale& locale, UnicodeString& result) const;
606 
641  virtual UBool useDaylightTime(void) const = 0;
642 
656  virtual UBool inDaylightTime(UDate date, UErrorCode& status) const = 0;
657 
666  virtual UBool hasSameRules(const TimeZone& other) const;
667 
675  virtual TimeZone* clone(void) const = 0;
676 
683  static UClassID U_EXPORT2 getStaticClassID(void);
684 
696  virtual UClassID getDynamicClassID(void) const = 0;
697 
713  virtual int32_t getDSTSavings() const;
714 
732  static int32_t U_EXPORT2 getRegion(const UnicodeString& id,
733  char *region, int32_t capacity, UErrorCode& status);
734 
735 protected:
736 
741  TimeZone();
742 
748  TimeZone(const UnicodeString &id);
749 
755  TimeZone(const TimeZone& source);
756 
762  TimeZone& operator=(const TimeZone& right);
763 
764 #ifndef U_HIDE_INTERNAL_API
765 
774  static UResourceBundle* loadRule(const UResourceBundle* top, const UnicodeString& ruleid, UResourceBundle* oldbundle, UErrorCode&status);
775 #endif /* U_HIDE_INTERNAL_API */
776 
777 private:
778  friend class ZoneMeta;
779 
780 
781  static TimeZone* createCustomTimeZone(const UnicodeString&); // Creates a time zone based on the string.
782 
791  static const UChar* findID(const UnicodeString& id);
792 
801  static const UChar* dereferOlsonLink(const UnicodeString& id);
802 
809  static const UChar* getRegion(const UnicodeString& id);
810 
818  static const UChar* getRegion(const UnicodeString& id, UErrorCode& status);
819 
830  static UBool parseCustomID(const UnicodeString& id, int32_t& sign, int32_t& hour,
831  int32_t& minute, int32_t& second);
832 
843  static UnicodeString& getCustomID(const UnicodeString& id, UnicodeString& normalized,
844  UErrorCode& status);
845 
855  static UnicodeString& formatCustomID(int32_t hour, int32_t min, int32_t sec,
856  UBool negative, UnicodeString& id);
857 
863  static void initDefault(void);
864 
865  // See source file for documentation
873  static TimeZone* createSystemTimeZone(const UnicodeString& name);
874  static TimeZone* createSystemTimeZone(const UnicodeString& name, UErrorCode& ec);
875 
876  UnicodeString fID; // this time zone's ID
877 
878  friend class TZEnumeration;
879 };
880 
881 
882 // -------------------------------------
883 
884 inline UnicodeString&
885 TimeZone::getID(UnicodeString& ID) const
886 {
887  ID = fID;
888  return ID;
889 }
890 
891 // -------------------------------------
892 
893 inline void
894 TimeZone::setID(const UnicodeString& ID)
895 {
896  fID = ID;
897 }
899 
900 #endif /* #if !UCONFIG_NO_FORMATTING */
901 
902 #endif //_TIMEZONE
903 //eof
C API: Calendar.
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.
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:96
Base class for 'pure' C++ implementations of uenum api.
Definition: strenum.h:55
EDisplayType
Enum for use with getDisplayName.
Definition: timezone.h:502
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:528
Selector for short generic display name.
Definition: timezone.h:517
Selector for long generic display name.
Definition: timezone.h:522
Selector for long display name.
Definition: timezone.h:512
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:540
UBool operator!=(const TimeZone &that) const
Returns true if the two TimeZones are NOT equal; that is, if operator==() returns false...
Definition: timezone.h:377
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:246
struct UResourceBundle UResourceBundle
Definition: ures.h:57
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:229
Selector for long display name derived from time zone offset.
Definition: timezone.h:534
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:182