ICU 4.2.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-2009, 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 
44 
45 class StringEnumeration;
46 
122 class U_I18N_API TimeZone : public UObject {
123 public:
127  virtual ~TimeZone();
128 
135  static const TimeZone* U_EXPORT2 getGMT(void);
136 
147  static TimeZone* U_EXPORT2 createTimeZone(const UnicodeString& ID);
148 
156  static StringEnumeration* U_EXPORT2 createEnumeration();
157 
175  static StringEnumeration* U_EXPORT2 createEnumeration(int32_t rawOffset);
176 
187  static StringEnumeration* U_EXPORT2 createEnumeration(const char* country);
188 
189 #ifdef U_USE_TIMEZONE_OBSOLETE_2_8
190 
213  static const UnicodeString** createAvailableIDs(int32_t rawOffset, int32_t& numIDs);
214 
236  static const UnicodeString** createAvailableIDs(const char* country,
237  int32_t& numIDs);
238 
252  static const UnicodeString** createAvailableIDs(int32_t& numIDs);
253 #endif
254 
269  static int32_t U_EXPORT2 countEquivalentIDs(const UnicodeString& id);
270 
290  static const UnicodeString U_EXPORT2 getEquivalentID(const UnicodeString& id,
291  int32_t index);
292 
305  static TimeZone* U_EXPORT2 createDefault(void);
306 
316  static void U_EXPORT2 adoptDefault(TimeZone* zone);
317 
325  static void U_EXPORT2 setDefault(const TimeZone& zone);
326 
333  static const char* U_EXPORT2 getTZDataVersion(UErrorCode& status);
334 
348  static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id,
349  UnicodeString& canonicalID, UErrorCode& status);
350 
366  static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id,
367  UnicodeString& canonicalID, UBool& isSystemID, UErrorCode& status);
368 
378  virtual UBool operator==(const TimeZone& that) const;
379 
389  UBool operator!=(const TimeZone& that) const {return !operator==(that);}
390 
415  virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
416  uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const = 0;
417 
438  virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
439  uint8_t dayOfWeek, int32_t milliseconds,
440  int32_t monthLength, UErrorCode& status) const = 0;
441 
465  virtual void getOffset(UDate date, UBool local, int32_t& rawOffset,
466  int32_t& dstOffset, UErrorCode& ec) const;
467 
475  virtual void setRawOffset(int32_t offsetMillis) = 0;
476 
484  virtual int32_t getRawOffset(void) const = 0;
485 
493  UnicodeString& getID(UnicodeString& ID) const;
494 
508  void setID(const UnicodeString& ID);
509 
519  SHORT = 1,
524  LONG
525  };
526 
538  UnicodeString& getDisplayName(UnicodeString& result) const;
539 
553  UnicodeString& getDisplayName(const Locale& locale, UnicodeString& result) const;
554 
567  UnicodeString& getDisplayName(UBool daylight, EDisplayType style, UnicodeString& result) const;
568 
583  UnicodeString& getDisplayName(UBool daylight, EDisplayType style, const Locale& locale, UnicodeString& result) const;
584 
591  virtual UBool useDaylightTime(void) const = 0;
592 
606  virtual UBool inDaylightTime(UDate date, UErrorCode& status) const = 0;
607 
616  virtual UBool hasSameRules(const TimeZone& other) const;
617 
625  virtual TimeZone* clone(void) const = 0;
626 
633  static UClassID U_EXPORT2 getStaticClassID(void);
634 
646  virtual UClassID getDynamicClassID(void) const = 0;
647 
663  virtual int32_t getDSTSavings() const;
664 
665 protected:
666 
671  TimeZone();
672 
678  TimeZone(const UnicodeString &id);
679 
685  TimeZone(const TimeZone& source);
686 
692  TimeZone& operator=(const TimeZone& right);
693 
703  static UResourceBundle* loadRule(const UResourceBundle* top, const UnicodeString& ruleid, UResourceBundle* oldbundle, UErrorCode&status);
704 
705 private:
706  friend class ZoneMeta;
707 
708 
709  static TimeZone* createCustomTimeZone(const UnicodeString&); // Creates a time zone based on the string.
710 
720  static UnicodeString& dereferOlsonLink(const UnicodeString& linkTo, UnicodeString& linkFrom);
721 
732  static UBool parseCustomID(const UnicodeString& id, int32_t& sign, int32_t& hour,
733  int32_t& min, int32_t& sec);
734 
745  static UnicodeString& getCustomID(const UnicodeString& id, UnicodeString& normalized,
746  UErrorCode& status);
747 
757  static UnicodeString& formatCustomID(int32_t hour, int32_t min, int32_t sec,
758  UBool negative, UnicodeString& id);
759 
765  static void initDefault(void);
766 
767  // See source file for documentation
775  static TimeZone* createSystemTimeZone(const UnicodeString& name);
776 
777  UnicodeString fID; // this time zone's ID
778 };
779 
780 
781 // -------------------------------------
782 
783 inline UnicodeString&
785 {
786  ID = fID;
787  return ID;
788 }
789 
790 // -------------------------------------
791 
792 inline void
794 {
795  fID = ID;
796 }
798 
799 #endif /* #if !UCONFIG_NO_FORMATTING */
800 
801 #endif //_TIMEZONE
802 //eof
EDisplayType
Enum for use with getDisplayName.
Definition: timezone.h:514
double UDate
Date and Time data type.
Definition: utypes.h:281
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:389
unsigned char uint8_t
Define 64 bit limits.
Definition: pwin32.h:131
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:475
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:183
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:187
#define U_EXPORT2
Definition: platform.h:338
C++ API: Common ICU base class UObject.
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API If the compiler doesn't support namespaces...
Definition: uversion.h:184
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:212
void * UClassID
UClassID is used to identify classes without using RTTI, since RTTI is not yet supported by all C++ c...
Definition: utypes.h:339
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:593
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition: timezone.h:122
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:793
Basic definitions for ICU, for both C and C++ APIs.
struct UResourceBundle UResourceBundle
Definition: ures.h:56
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.
signed int int32_t
Define 64 bit limits.
Definition: pwin32.h:143
C API: Resource Bundle.
int8_t UBool
The ICU boolean type.
Definition: umachine.h:208
UnicodeString & getID(UnicodeString &ID) const
Fills in "ID" with the TimeZone's ID.
Definition: timezone.h:784