michael@0: /************************************************************************* michael@0: * Copyright (c) 1997-2013, International Business Machines Corporation michael@0: * and others. All Rights Reserved. michael@0: ************************************************************************** michael@0: * michael@0: * File TIMEZONE.H michael@0: * michael@0: * Modification History: michael@0: * michael@0: * Date Name Description michael@0: * 04/21/97 aliu Overhauled header. michael@0: * 07/09/97 helena Changed createInstance to createDefault. michael@0: * 08/06/97 aliu Removed dependency on internal header for Hashtable. michael@0: * 08/10/98 stephen Changed getDisplayName() API conventions to match michael@0: * 08/19/98 stephen Changed createTimeZone() to never return 0 michael@0: * 09/02/98 stephen Sync to JDK 1.2 8/31 michael@0: * - Added getOffset(... monthlen ...) michael@0: * - Added hasSameRules() michael@0: * 09/15/98 stephen Added getStaticClassID michael@0: * 12/03/99 aliu Moved data out of static table into icudata.dll. michael@0: * Hashtable replaced by new static data structures. michael@0: * 12/14/99 aliu Made GMT public. michael@0: * 08/15/01 grhoten Made GMT private and added the getGMT() function michael@0: ************************************************************************** michael@0: */ michael@0: michael@0: #ifndef TIMEZONE_H michael@0: #define TIMEZONE_H michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: /** michael@0: * \file michael@0: * \brief C++ API: TimeZone object michael@0: */ michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: michael@0: #include "unicode/uobject.h" michael@0: #include "unicode/unistr.h" michael@0: #include "unicode/ures.h" michael@0: #include "unicode/ucal.h" michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: class StringEnumeration; michael@0: michael@0: /** michael@0: * michael@0: * TimeZone represents a time zone offset, and also figures out daylight michael@0: * savings. michael@0: * michael@0: *

michael@0: * Typically, you get a TimeZone using createDefault michael@0: * which creates a TimeZone based on the time zone where the program michael@0: * is running. For example, for a program running in Japan, createDefault michael@0: * creates a TimeZone object based on Japanese Standard Time. michael@0: * michael@0: *

michael@0: * You can also get a TimeZone using createTimeZone along michael@0: * with a time zone ID. For instance, the time zone ID for the US Pacific michael@0: * Time zone is "America/Los_Angeles". So, you can get a Pacific Time TimeZone object michael@0: * with: michael@0: * \htmlonly

\endhtmlonly michael@0: *
michael@0:  * TimeZone *tz = TimeZone::createTimeZone("America/Los_Angeles");
michael@0:  * 
michael@0: * \htmlonly
\endhtmlonly michael@0: * You can use getAvailableIDs method to iterate through michael@0: * all the supported time zone IDs, or getCanonicalID method to check michael@0: * if a time zone ID is supported or not. You can then choose a michael@0: * supported ID to get a TimeZone. michael@0: * If the time zone you want is not represented by one of the michael@0: * supported IDs, then you can create a custom time zone ID with michael@0: * the following syntax: michael@0: * michael@0: * \htmlonly
\endhtmlonly michael@0: *
michael@0:  * GMT[+|-]hh[[:]mm]
michael@0:  * 
michael@0: * \htmlonly
\endhtmlonly michael@0: * michael@0: * For example, you might specify GMT+14:00 as a custom michael@0: * time zone ID. The TimeZone that is returned michael@0: * when you specify a custom time zone ID uses the specified michael@0: * offset from GMT(=UTC) and does not observe daylight saving michael@0: * time. For example, you might specify GMT+14:00 as a custom michael@0: * time zone ID to create a TimeZone representing 14 hours ahead michael@0: * of GMT (with no daylight saving time). In addition, michael@0: * getCanonicalID can also be used to michael@0: * normalize a custom time zone ID. michael@0: * michael@0: * TimeZone is an abstract class representing a time zone. A TimeZone is needed for michael@0: * Calendar to produce local time for a particular time zone. A TimeZone comprises michael@0: * three basic pieces of information: michael@0: * michael@0: * michael@0: * (Only the ID is actually implemented in TimeZone; subclasses of TimeZone may handle michael@0: * daylight savings time and GMT offset in different ways. Currently we have the following michael@0: * TimeZone subclasses: RuleBasedTimeZone, SimpleTimeZone, and VTimeZone.) michael@0: *

michael@0: * The TimeZone class contains a static list containing a TimeZone object for every michael@0: * combination of GMT offset and daylight-savings time rules currently in use in the michael@0: * world, each with a unique ID. Each ID consists of a region (usually a continent or michael@0: * ocean) and a city in that region, separated by a slash, (for example, US Pacific michael@0: * Time is "America/Los_Angeles.") Because older versions of this class used michael@0: * three- or four-letter abbreviations instead, there is also a table that maps the older michael@0: * abbreviations to the newer ones (for example, "PST" maps to "America/Los_Angeles"). michael@0: * Anywhere the API requires an ID, you can use either form. michael@0: *

michael@0: * To create a new TimeZone, you call the factory function TimeZone::createTimeZone() michael@0: * and pass it a time zone ID. You can use the createEnumeration() function to michael@0: * obtain a list of all the time zone IDs recognized by createTimeZone(). michael@0: *

michael@0: * You can also use TimeZone::createDefault() to create a TimeZone. This function uses michael@0: * platform-specific APIs to produce a TimeZone for the time zone corresponding to michael@0: * the client's computer's physical location. For example, if you're in Japan (assuming michael@0: * your machine is set up correctly), TimeZone::createDefault() will return a TimeZone michael@0: * for Japanese Standard Time ("Asia/Tokyo"). michael@0: */ michael@0: class U_I18N_API TimeZone : public UObject { michael@0: public: michael@0: /** michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual ~TimeZone(); michael@0: michael@0: /** michael@0: * Returns the "unknown" time zone. michael@0: * It behaves like the GMT/UTC time zone but has the michael@0: * UCAL_UNKNOWN_ZONE_ID = "Etc/Unknown". michael@0: * createTimeZone() returns a mutable clone of this time zone if the input ID is not recognized. michael@0: * michael@0: * @return the "unknown" time zone. michael@0: * @see UCAL_UNKNOWN_ZONE_ID michael@0: * @see createTimeZone michael@0: * @see getGMT michael@0: * @stable ICU 49 michael@0: */ michael@0: static const TimeZone& U_EXPORT2 getUnknown(); michael@0: michael@0: /** michael@0: * The GMT (=UTC) time zone has a raw offset of zero and does not use daylight michael@0: * savings time. This is a commonly used time zone. michael@0: * michael@0: *

Note: For backward compatibility reason, the ID used by the time michael@0: * zone returned by this method is "GMT", although the ICU's canonical michael@0: * ID for the GMT time zone is "Etc/GMT". michael@0: * michael@0: * @return the GMT/UTC time zone. michael@0: * @see getUnknown michael@0: * @stable ICU 2.0 michael@0: */ michael@0: static const TimeZone* U_EXPORT2 getGMT(void); michael@0: michael@0: /** michael@0: * Creates a TimeZone for the given ID. michael@0: * @param ID the ID for a TimeZone, such as "America/Los_Angeles", michael@0: * or a custom ID such as "GMT-8:00". michael@0: * @return the specified TimeZone, or a mutable clone of getUnknown() michael@0: * if the given ID cannot be understood or if the given ID is "Etc/Unknown". michael@0: * The return result is guaranteed to be non-NULL. michael@0: * If you require that the specific zone asked for be returned, michael@0: * compare the result with getUnknown() or check the ID of the return result. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: static TimeZone* U_EXPORT2 createTimeZone(const UnicodeString& ID); michael@0: michael@0: /** michael@0: * Returns an enumeration over system time zone IDs with the given michael@0: * filter conditions. michael@0: * @param zoneType The system time zone type. michael@0: * @param region The ISO 3166 two-letter country code or UN M.49 michael@0: * three-digit area code. When NULL, no filtering michael@0: * done by region. michael@0: * @param rawOffset An offset from GMT in milliseconds, ignoring michael@0: * the effect of daylight savings time, if any. michael@0: * When NULL, no filtering done by zone offset. michael@0: * @param ec Output param to filled in with a success or michael@0: * an error. michael@0: * @return an enumeration object, owned by the caller. michael@0: * @stable ICU 4.8 michael@0: */ michael@0: static StringEnumeration* U_EXPORT2 createTimeZoneIDEnumeration( michael@0: USystemTimeZoneType zoneType, michael@0: const char* region, michael@0: const int32_t* rawOffset, michael@0: UErrorCode& ec); michael@0: michael@0: /** michael@0: * Returns an enumeration over all recognized time zone IDs. (i.e., michael@0: * all strings that createTimeZone() accepts) michael@0: * michael@0: * @return an enumeration object, owned by the caller. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: static StringEnumeration* U_EXPORT2 createEnumeration(); michael@0: michael@0: /** michael@0: * Returns an enumeration over time zone IDs with a given raw michael@0: * offset from GMT. There may be several times zones with the michael@0: * same GMT offset that differ in the way they handle daylight michael@0: * savings time. For example, the state of Arizona doesn't michael@0: * observe daylight savings time. If you ask for the time zone michael@0: * IDs corresponding to GMT-7:00, you'll get back an enumeration michael@0: * over two time zone IDs: "America/Denver," which corresponds to michael@0: * Mountain Standard Time in the winter and Mountain Daylight Time michael@0: * in the summer, and "America/Phoenix", which corresponds to michael@0: * Mountain Standard Time year-round, even in the summer. michael@0: * michael@0: * @param rawOffset an offset from GMT in milliseconds, ignoring michael@0: * the effect of daylight savings time, if any michael@0: * @return an enumeration object, owned by the caller michael@0: * @stable ICU 2.4 michael@0: */ michael@0: static StringEnumeration* U_EXPORT2 createEnumeration(int32_t rawOffset); michael@0: michael@0: /** michael@0: * Returns an enumeration over time zone IDs associated with the michael@0: * given country. Some zones are affiliated with no country michael@0: * (e.g., "UTC"); these may also be retrieved, as a group. michael@0: * michael@0: * @param country The ISO 3166 two-letter country code, or NULL to michael@0: * retrieve zones not affiliated with any country. michael@0: * @return an enumeration object, owned by the caller michael@0: * @stable ICU 2.4 michael@0: */ michael@0: static StringEnumeration* U_EXPORT2 createEnumeration(const char* country); michael@0: michael@0: /** michael@0: * Returns the number of IDs in the equivalency group that michael@0: * includes the given ID. An equivalency group contains zones michael@0: * that have the same GMT offset and rules. michael@0: * michael@0: *

The returned count includes the given ID; it is always >= 1. michael@0: * The given ID must be a system time zone. If it is not, returns michael@0: * zero. michael@0: * @param id a system time zone ID michael@0: * @return the number of zones in the equivalency group containing michael@0: * 'id', or zero if 'id' is not a valid system ID michael@0: * @see #getEquivalentID michael@0: * @stable ICU 2.0 michael@0: */ michael@0: static int32_t U_EXPORT2 countEquivalentIDs(const UnicodeString& id); michael@0: michael@0: /** michael@0: * Returns an ID in the equivalency group that michael@0: * includes the given ID. An equivalency group contains zones michael@0: * that have the same GMT offset and rules. michael@0: * michael@0: *

The given index must be in the range 0..n-1, where n is the michael@0: * value returned by countEquivalentIDs(id). For michael@0: * some value of 'index', the returned value will be equal to the michael@0: * given id. If the given id is not a valid system time zone, or michael@0: * if 'index' is out of range, then returns an empty string. michael@0: * @param id a system time zone ID michael@0: * @param index a value from 0 to n-1, where n is the value michael@0: * returned by countEquivalentIDs(id) michael@0: * @return the ID of the index-th zone in the equivalency group michael@0: * containing 'id', or an empty string if 'id' is not a valid michael@0: * system ID or 'index' is out of range michael@0: * @see #countEquivalentIDs michael@0: * @stable ICU 2.0 michael@0: */ michael@0: static const UnicodeString U_EXPORT2 getEquivalentID(const UnicodeString& id, michael@0: int32_t index); michael@0: michael@0: /** michael@0: * Creates a new copy of the default TimeZone for this host. Unless the default time michael@0: * zone has already been set using adoptDefault() or setDefault(), the default is michael@0: * determined by querying the system using methods in TPlatformUtilities. If the michael@0: * system routines fail, or if they specify a TimeZone or TimeZone offset which is not michael@0: * recognized, the TimeZone indicated by the ID kLastResortID is instantiated michael@0: * and made the default. michael@0: * michael@0: * @return A default TimeZone. Clients are responsible for deleting the time zone michael@0: * object returned. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: static TimeZone* U_EXPORT2 createDefault(void); michael@0: michael@0: /** michael@0: * Sets the default time zone (i.e., what's returned by createDefault()) to be the michael@0: * specified time zone. If NULL is specified for the time zone, the default time michael@0: * zone is set to the default host time zone. This call adopts the TimeZone object michael@0: * passed in; the client is no longer responsible for deleting it. michael@0: * michael@0: *

This function is not thread safe. It is an error for multiple threads michael@0: * to concurrently attempt to set the default time zone, or for any thread michael@0: * to attempt to reference the default zone while another thread is setting it. michael@0: * michael@0: * @param zone A pointer to the new TimeZone object to use as the default. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: static void U_EXPORT2 adoptDefault(TimeZone* zone); michael@0: michael@0: #ifndef U_HIDE_SYSTEM_API michael@0: /** michael@0: * Same as adoptDefault(), except that the TimeZone object passed in is NOT adopted; michael@0: * the caller remains responsible for deleting it. michael@0: * michael@0: *

See the thread safety note under adoptDefault(). michael@0: * michael@0: * @param zone The given timezone. michael@0: * @system michael@0: * @stable ICU 2.0 michael@0: */ michael@0: static void U_EXPORT2 setDefault(const TimeZone& zone); michael@0: #endif /* U_HIDE_SYSTEM_API */ michael@0: michael@0: /** michael@0: * Returns the timezone data version currently used by ICU. michael@0: * @param status Output param to filled in with a success or an error. michael@0: * @return the version string, such as "2007f" michael@0: * @stable ICU 3.8 michael@0: */ michael@0: static const char* U_EXPORT2 getTZDataVersion(UErrorCode& status); michael@0: michael@0: /** michael@0: * Returns the canonical system timezone ID or the normalized michael@0: * custom time zone ID for the given time zone ID. michael@0: * @param id The input time zone ID to be canonicalized. michael@0: * @param canonicalID Receives the canonical system time zone ID michael@0: * or the custom time zone ID in normalized format. michael@0: * @param status Recevies the status. When the given time zone ID michael@0: * is neither a known system time zone ID nor a michael@0: * valid custom time zone ID, U_ILLEGAL_ARGUMENT_ERROR michael@0: * is set. michael@0: * @return A reference to the result. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id, michael@0: UnicodeString& canonicalID, UErrorCode& status); michael@0: michael@0: /** michael@0: * Returns the canonical system time zone ID or the normalized michael@0: * custom time zone ID for the given time zone ID. michael@0: * @param id The input time zone ID to be canonicalized. michael@0: * @param canonicalID Receives the canonical system time zone ID michael@0: * or the custom time zone ID in normalized format. michael@0: * @param isSystemID Receives if the given ID is a known system michael@0: * time zone ID. michael@0: * @param status Recevies the status. When the given time zone ID michael@0: * is neither a known system time zone ID nor a michael@0: * valid custom time zone ID, U_ILLEGAL_ARGUMENT_ERROR michael@0: * is set. michael@0: * @return A reference to the result. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id, michael@0: UnicodeString& canonicalID, UBool& isSystemID, UErrorCode& status); michael@0: michael@0: #ifndef U_HIDE_DRAFT_API michael@0: /** michael@0: * Converts a system time zone ID to an equivalent Windows time zone ID. For example, michael@0: * Windows time zone ID "Pacific Standard Time" is returned for input "America/Los_Angeles". michael@0: * michael@0: *

There are system time zones that cannot be mapped to Windows zones. When the input michael@0: * system time zone ID is unknown or unmappable to a Windows time zone, then the result will be michael@0: * empty, but the operation itself remains successful (no error status set on return). michael@0: * michael@0: *

This implementation utilizes michael@0: * Zone-Tzid mapping data. The mapping data is updated time to time. To get the latest changes, michael@0: * please read the ICU user guide section michael@0: * Updating the Time Zone Data. michael@0: * michael@0: * @param id A system time zone ID. michael@0: * @param winid Receives a Windows time zone ID. When the input system time zone ID is unknown michael@0: * or unmappable to a Windows time zone ID, then an empty string is set on return. michael@0: * @param status Receives the status. michael@0: * @return A reference to the result (winid). michael@0: * @see getIDForWindowsID michael@0: * michael@0: * @draft ICU 52 michael@0: */ michael@0: static UnicodeString& U_EXPORT2 getWindowsID(const UnicodeString& id, michael@0: UnicodeString& winid, UErrorCode& status); michael@0: michael@0: /** michael@0: * Converts a Windows time zone ID to an equivalent system time zone ID michael@0: * for a region. For example, system time zone ID "America/Los_Angeles" is returned michael@0: * for input Windows ID "Pacific Standard Time" and region "US" (or null), michael@0: * "America/Vancouver" is returned for the same Windows ID "Pacific Standard Time" and michael@0: * region "CA". michael@0: * michael@0: *

Not all Windows time zones can be mapped to system time zones. When the input michael@0: * Windows time zone ID is unknown or unmappable to a system time zone, then the result michael@0: * will be empty, but the operation itself remains successful (no error status set on return). michael@0: * michael@0: *

This implementation utilizes michael@0: * Zone-Tzid mapping data. The mapping data is updated time to time. To get the latest changes, michael@0: * please read the ICU user guide section michael@0: * Updating the Time Zone Data. michael@0: * michael@0: * @param winid A Windows time zone ID. michael@0: * @param region A null-terminated region code, or NULL if no regional preference. michael@0: * @param id Receives a system time zone ID. When the input Windows time zone ID is unknown michael@0: * or unmappable to a system time zone ID, then an empty string is set on return. michael@0: * @param status Receives the status. michael@0: * @return A reference to the result (id). michael@0: * @see getWindowsID michael@0: * michael@0: * @draft ICU 52 michael@0: */ michael@0: static UnicodeString& U_EXPORT2 getIDForWindowsID(const UnicodeString& winid, const char* region, michael@0: UnicodeString& id, UErrorCode& status); michael@0: michael@0: #endif /* U_HIDE_DRAFT_API */ michael@0: michael@0: /** michael@0: * Returns true if the two TimeZones are equal. (The TimeZone version only compares michael@0: * IDs, but subclasses are expected to also compare the fields they add.) michael@0: * michael@0: * @param that The TimeZone object to be compared with. michael@0: * @return True if the given TimeZone is equal to this TimeZone; false michael@0: * otherwise. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual UBool operator==(const TimeZone& that) const; michael@0: michael@0: /** michael@0: * Returns true if the two TimeZones are NOT equal; that is, if operator==() returns michael@0: * false. michael@0: * michael@0: * @param that The TimeZone object to be compared with. michael@0: * @return True if the given TimeZone is not equal to this TimeZone; false michael@0: * otherwise. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UBool operator!=(const TimeZone& that) const {return !operator==(that);} michael@0: michael@0: /** michael@0: * Returns the TimeZone's adjusted GMT offset (i.e., the number of milliseconds to add michael@0: * to GMT to get local time in this time zone, taking daylight savings time into michael@0: * account) as of a particular reference date. The reference date is used to determine michael@0: * whether daylight savings time is in effect and needs to be figured into the offset michael@0: * that is returned (in other words, what is the adjusted GMT offset in this time zone michael@0: * at this particular date and time?). For the time zones produced by createTimeZone(), michael@0: * the reference data is specified according to the Gregorian calendar, and the date michael@0: * and time fields are local standard time. michael@0: * michael@0: *

Note: Don't call this method. Instead, call the getOffset(UDate...) overload, michael@0: * which returns both the raw and the DST offset for a given time. This method michael@0: * is retained only for backward compatibility. michael@0: * michael@0: * @param era The reference date's era michael@0: * @param year The reference date's year michael@0: * @param month The reference date's month (0-based; 0 is January) michael@0: * @param day The reference date's day-in-month (1-based) michael@0: * @param dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday) michael@0: * @param millis The reference date's milliseconds in day, local standard time michael@0: * @param status Output param to filled in with a success or an error. michael@0: * @return The offset in milliseconds to add to GMT to get local time. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day, michael@0: uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const = 0; michael@0: michael@0: /** michael@0: * Gets the time zone offset, for current date, modified in case of michael@0: * daylight savings. This is the offset to add *to* UTC to get local time. michael@0: * michael@0: *

Note: Don't call this method. Instead, call the getOffset(UDate...) overload, michael@0: * which returns both the raw and the DST offset for a given time. This method michael@0: * is retained only for backward compatibility. michael@0: * michael@0: * @param era the era of the given date. michael@0: * @param year the year in the given date. michael@0: * @param month the month in the given date. michael@0: * Month is 0-based. e.g., 0 for January. michael@0: * @param day the day-in-month of the given date. michael@0: * @param dayOfWeek the day-of-week of the given date. michael@0: * @param milliseconds the millis in day in standard local time. michael@0: * @param monthLength the length of the given month in days. michael@0: * @param status Output param to filled in with a success or an error. michael@0: * @return the offset to add *to* GMT to get local time. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day, michael@0: uint8_t dayOfWeek, int32_t milliseconds, michael@0: int32_t monthLength, UErrorCode& status) const = 0; michael@0: michael@0: /** michael@0: * Returns the time zone raw and GMT offset for the given moment michael@0: * in time. Upon return, local-millis = GMT-millis + rawOffset + michael@0: * dstOffset. All computations are performed in the proleptic michael@0: * Gregorian calendar. The default implementation in the TimeZone michael@0: * class delegates to the 8-argument getOffset(). michael@0: * michael@0: * @param date moment in time for which to return offsets, in michael@0: * units of milliseconds from January 1, 1970 0:00 GMT, either GMT michael@0: * time or local wall time, depending on `local'. michael@0: * @param local if true, `date' is local wall time; otherwise it michael@0: * is in GMT time. michael@0: * @param rawOffset output parameter to receive the raw offset, that michael@0: * is, the offset not including DST adjustments michael@0: * @param dstOffset output parameter to receive the DST offset, michael@0: * that is, the offset to be added to `rawOffset' to obtain the michael@0: * total offset between local and GMT time. If DST is not in michael@0: * effect, this value is zero; otherwise it is a positive value, michael@0: * typically one hour. michael@0: * @param ec input-output error code michael@0: * michael@0: * @stable ICU 2.8 michael@0: */ michael@0: virtual void getOffset(UDate date, UBool local, int32_t& rawOffset, michael@0: int32_t& dstOffset, UErrorCode& ec) const; michael@0: michael@0: /** michael@0: * Sets the TimeZone's raw GMT offset (i.e., the number of milliseconds to add michael@0: * to GMT to get local time, before taking daylight savings time into account). michael@0: * michael@0: * @param offsetMillis The new raw GMT offset for this time zone. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual void setRawOffset(int32_t offsetMillis) = 0; michael@0: michael@0: /** michael@0: * Returns the TimeZone's raw GMT offset (i.e., the number of milliseconds to add michael@0: * to GMT to get local time, before taking daylight savings time into account). michael@0: * michael@0: * @return The TimeZone's raw GMT offset. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual int32_t getRawOffset(void) const = 0; michael@0: michael@0: /** michael@0: * Fills in "ID" with the TimeZone's ID. michael@0: * michael@0: * @param ID Receives this TimeZone's ID. michael@0: * @return A reference to 'ID' michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString& getID(UnicodeString& ID) const; michael@0: michael@0: /** michael@0: * Sets the TimeZone's ID to the specified value. This doesn't affect any other michael@0: * fields (for example, if you say< michael@0: * blockquote>

michael@0:      * .     TimeZone* foo = TimeZone::createTimeZone("America/New_York");
michael@0:      * .     foo.setID("America/Los_Angeles");
michael@0:      * 
\htmlonly\endhtmlonly michael@0: * the time zone's GMT offset and daylight-savings rules don't change to those for michael@0: * Los Angeles. They're still those for New York. Only the ID has changed.) michael@0: * michael@0: * @param ID The new time zone ID. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: void setID(const UnicodeString& ID); michael@0: michael@0: /** michael@0: * Enum for use with getDisplayName michael@0: * @stable ICU 2.4 michael@0: */ michael@0: enum EDisplayType { michael@0: /** michael@0: * Selector for short display name michael@0: * @stable ICU 2.4 michael@0: */ michael@0: SHORT = 1, michael@0: /** michael@0: * Selector for long display name michael@0: * @stable ICU 2.4 michael@0: */ michael@0: LONG, michael@0: /** michael@0: * Selector for short generic display name michael@0: * @stable ICU 4.4 michael@0: */ michael@0: SHORT_GENERIC, michael@0: /** michael@0: * Selector for long generic display name michael@0: * @stable ICU 4.4 michael@0: */ michael@0: LONG_GENERIC, michael@0: /** michael@0: * Selector for short display name derived michael@0: * from time zone offset michael@0: * @stable ICU 4.4 michael@0: */ michael@0: SHORT_GMT, michael@0: /** michael@0: * Selector for long display name derived michael@0: * from time zone offset michael@0: * @stable ICU 4.4 michael@0: */ michael@0: LONG_GMT, michael@0: /** michael@0: * Selector for short display name derived michael@0: * from the time zone's fallback name michael@0: * @stable ICU 4.4 michael@0: */ michael@0: SHORT_COMMONLY_USED, michael@0: /** michael@0: * Selector for long display name derived michael@0: * from the time zone's fallback name michael@0: * @stable ICU 4.4 michael@0: */ michael@0: GENERIC_LOCATION michael@0: }; michael@0: michael@0: /** michael@0: * Returns a name of this time zone suitable for presentation to the user michael@0: * in the default locale. michael@0: * This method returns the long name, not including daylight savings. michael@0: * If the display name is not available for the locale, michael@0: * then this method returns a string in the format michael@0: * GMT[+-]hh:mm. michael@0: * @param result the human-readable name of this time zone in the default locale. michael@0: * @return A reference to 'result'. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString& getDisplayName(UnicodeString& result) const; michael@0: michael@0: /** michael@0: * Returns a name of this time zone suitable for presentation to the user michael@0: * in the specified locale. michael@0: * This method returns the long name, not including daylight savings. michael@0: * If the display name is not available for the locale, michael@0: * then this method returns a string in the format michael@0: * GMT[+-]hh:mm. michael@0: * @param locale the locale in which to supply the display name. michael@0: * @param result the human-readable name of this time zone in the given locale michael@0: * or in the default locale if the given locale is not recognized. michael@0: * @return A reference to 'result'. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString& getDisplayName(const Locale& locale, UnicodeString& result) const; michael@0: michael@0: /** michael@0: * Returns a name of this time zone suitable for presentation to the user michael@0: * in the default locale. michael@0: * If the display name is not available for the locale, michael@0: * then this method returns a string in the format michael@0: * GMT[+-]hh:mm. michael@0: * @param daylight if true, return the daylight savings name. michael@0: * @param style michael@0: * @param result the human-readable name of this time zone in the default locale. michael@0: * @return A reference to 'result'. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString& getDisplayName(UBool daylight, EDisplayType style, UnicodeString& result) const; michael@0: michael@0: /** michael@0: * Returns a name of this time zone suitable for presentation to the user michael@0: * in the specified locale. michael@0: * If the display name is not available for the locale, michael@0: * then this method returns a string in the format michael@0: * GMT[+-]hh:mm. michael@0: * @param daylight if true, return the daylight savings name. michael@0: * @param style michael@0: * @param locale the locale in which to supply the display name. michael@0: * @param result the human-readable name of this time zone in the given locale michael@0: * or in the default locale if the given locale is not recognized. michael@0: * @return A refence to 'result'. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString& getDisplayName(UBool daylight, EDisplayType style, const Locale& locale, UnicodeString& result) const; michael@0: michael@0: /** michael@0: * Queries if this time zone uses daylight savings time. michael@0: * @return true if this time zone uses daylight savings time, michael@0: * false, otherwise. michael@0: *

Note:The default implementation of michael@0: * ICU TimeZone uses the tz database, which supports historic michael@0: * rule changes, for system time zones. With the implementation, michael@0: * there are time zones that used daylight savings time in the michael@0: * past, but no longer used currently. For example, Asia/Tokyo has michael@0: * never used daylight savings time since 1951. Most clients would michael@0: * expect that this method to return FALSE for such case. michael@0: * The default implementation of this method returns TRUE michael@0: * when the time zone uses daylight savings time in the current michael@0: * (Gregorian) calendar year. michael@0: *

In Java 7, observesDaylightTime() was added in michael@0: * addition to useDaylightTime(). In Java, useDaylightTime() michael@0: * only checks if daylight saving time is observed by the last known michael@0: * rule. This specification might not be what most users would expect michael@0: * if daylight saving time is currently observed, but not scheduled michael@0: * in future. In this case, Java's userDaylightTime() returns michael@0: * false. To resolve the issue, Java 7 added observesDaylightTime(), michael@0: * which takes the current rule into account. The method observesDaylightTime() michael@0: * was added in ICU4J for supporting API signature compatibility with JDK. michael@0: * In general, ICU4C also provides JDK compatible methods, but the current michael@0: * implementation userDaylightTime() serves the purpose michael@0: * (takes the current rule into account), observesDaylightTime() michael@0: * is not added in ICU4C. In addition to useDaylightTime(), ICU4C michael@0: * BasicTimeZone class (Note that TimeZone::createTimeZone(const UnicodeString &ID) michael@0: * always returns a BasicTimeZone) provides a series of methods allowing michael@0: * historic and future time zone rule iteration, so you can check if daylight saving michael@0: * time is observed or not within a given period. michael@0: * michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual UBool useDaylightTime(void) const = 0; michael@0: michael@0: /** michael@0: * Queries if the given date is in daylight savings time in michael@0: * this time zone. michael@0: * This method is wasteful since it creates a new GregorianCalendar and michael@0: * deletes it each time it is called. This is a deprecated method michael@0: * and provided only for Java compatibility. michael@0: * michael@0: * @param date the given UDate. michael@0: * @param status Output param filled in with success/error code. michael@0: * @return true if the given date is in daylight savings time, michael@0: * false, otherwise. michael@0: * @deprecated ICU 2.4. Use Calendar::inDaylightTime() instead. michael@0: */ michael@0: virtual UBool inDaylightTime(UDate date, UErrorCode& status) const = 0; michael@0: michael@0: /** michael@0: * Returns true if this zone has the same rule and offset as another zone. michael@0: * That is, if this zone differs only in ID, if at all. michael@0: * @param other the TimeZone object to be compared with michael@0: * @return true if the given zone is the same as this one, michael@0: * with the possible exception of the ID michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual UBool hasSameRules(const TimeZone& other) const; michael@0: michael@0: /** michael@0: * Clones TimeZone objects polymorphically. Clients are responsible for deleting michael@0: * the TimeZone object cloned. michael@0: * michael@0: * @return A new copy of this TimeZone object. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual TimeZone* clone(void) const = 0; michael@0: michael@0: /** michael@0: * Return the class ID for this class. This is useful only for michael@0: * comparing to a return value from getDynamicClassID(). michael@0: * @return The class ID for all objects of this class. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: static UClassID U_EXPORT2 getStaticClassID(void); michael@0: michael@0: /** michael@0: * Returns a unique class ID POLYMORPHICALLY. This method is to michael@0: * implement a simple version of RTTI, since not all C++ compilers support genuine michael@0: * RTTI. Polymorphic operator==() and clone() methods call this method. michael@0: *

michael@0: * Concrete subclasses of TimeZone must use the UOBJECT_DEFINE_RTTI_IMPLEMENTATION michael@0: * macro from uobject.h in their implementation to provide correct RTTI information. michael@0: * @return The class ID for this object. All objects of a given class have the michael@0: * same class ID. Objects of other classes have different class IDs. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual UClassID getDynamicClassID(void) const = 0; michael@0: michael@0: /** michael@0: * Returns the amount of time to be added to local standard time michael@0: * to get local wall clock time. michael@0: *

michael@0: * The default implementation always returns 3600000 milliseconds michael@0: * (i.e., one hour) if this time zone observes Daylight Saving michael@0: * Time. Otherwise, 0 (zero) is returned. michael@0: *

michael@0: * If an underlying TimeZone implementation subclass supports michael@0: * historical Daylight Saving Time changes, this method returns michael@0: * the known latest daylight saving value. michael@0: * michael@0: * @return the amount of saving time in milliseconds michael@0: * @stable ICU 3.6 michael@0: */ michael@0: virtual int32_t getDSTSavings() const; michael@0: michael@0: /** michael@0: * Gets the region code associated with the given michael@0: * system time zone ID. The region code is either ISO 3166 michael@0: * 2-letter country code or UN M.49 3-digit area code. michael@0: * When the time zone is not associated with a specific location, michael@0: * for example - "Etc/UTC", "EST5EDT", then this method returns michael@0: * "001" (UN M.49 area code for World). michael@0: * michael@0: * @param id The system time zone ID. michael@0: * @param region Output buffer for receiving the region code. michael@0: * @param capacity The size of the output buffer. michael@0: * @param status Receives the status. When the given time zone ID michael@0: * is not a known system time zone ID, michael@0: * U_ILLEGAL_ARGUMENT_ERROR is set. michael@0: * @return The length of the output region code. michael@0: * @stable ICU 4.8 michael@0: */ michael@0: static int32_t U_EXPORT2 getRegion(const UnicodeString& id, michael@0: char *region, int32_t capacity, UErrorCode& status); michael@0: michael@0: protected: michael@0: michael@0: /** michael@0: * Default constructor. ID is initialized to the empty string. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: TimeZone(); michael@0: michael@0: /** michael@0: * Construct a TimeZone with a given ID. michael@0: * @param id a system time zone ID michael@0: * @stable ICU 2.0 michael@0: */ michael@0: TimeZone(const UnicodeString &id); michael@0: michael@0: /** michael@0: * Copy constructor. michael@0: * @param source the object to be copied. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: TimeZone(const TimeZone& source); michael@0: michael@0: /** michael@0: * Default assignment operator. michael@0: * @param right the object to be copied. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: TimeZone& operator=(const TimeZone& right); michael@0: michael@0: #ifndef U_HIDE_INTERNAL_API michael@0: /** michael@0: * Utility function. For internally loading rule data. michael@0: * @param top Top resource bundle for tz data michael@0: * @param ruleid ID of rule to load michael@0: * @param oldbundle Old bundle to reuse or NULL michael@0: * @param status Status parameter michael@0: * @return either a new bundle or *oldbundle michael@0: * @internal michael@0: */ michael@0: static UResourceBundle* loadRule(const UResourceBundle* top, const UnicodeString& ruleid, UResourceBundle* oldbundle, UErrorCode&status); michael@0: #endif /* U_HIDE_INTERNAL_API */ michael@0: michael@0: private: michael@0: friend class ZoneMeta; michael@0: michael@0: michael@0: static TimeZone* createCustomTimeZone(const UnicodeString&); // Creates a time zone based on the string. michael@0: michael@0: /** michael@0: * Finds the given ID in the Olson tzdata. If the given ID is found in the tzdata, michael@0: * returns the pointer to the ID resource. This method is exposed through ZoneMeta class michael@0: * for ICU internal implementation and useful for building hashtable using a time zone michael@0: * ID as a key. michael@0: * @param id zone id string michael@0: * @return the pointer of the ID resource, or NULL. michael@0: */ michael@0: static const UChar* findID(const UnicodeString& id); michael@0: michael@0: /** michael@0: * Resolve a link in Olson tzdata. When the given id is known and it's not a link, michael@0: * the id itself is returned. When the given id is known and it is a link, then michael@0: * dereferenced zone id is returned. When the given id is unknown, then it returns michael@0: * NULL. michael@0: * @param id zone id string michael@0: * @return the dereferenced zone or NULL michael@0: */ michael@0: static const UChar* dereferOlsonLink(const UnicodeString& id); michael@0: michael@0: /** michael@0: * Returns the region code associated with the given zone, michael@0: * or NULL if the zone is not known. michael@0: * @param id zone id string michael@0: * @return the region associated with the given zone michael@0: */ michael@0: static const UChar* getRegion(const UnicodeString& id); michael@0: michael@0: public: michael@0: #ifndef U_HIDE_INTERNAL_API michael@0: /** michael@0: * Returns the region code associated with the given zone, michael@0: * or NULL if the zone is not known. michael@0: * @param id zone id string michael@0: * @param status Status parameter michael@0: * @return the region associated with the given zone michael@0: * @internal michael@0: */ michael@0: static const UChar* getRegion(const UnicodeString& id, UErrorCode& status); michael@0: #endif /* U_HIDE_INTERNAL_API */ michael@0: michael@0: private: michael@0: /** michael@0: * Parses the given custom time zone identifier michael@0: * @param id id A string of the form GMT[+-]hh:mm, GMT[+-]hhmm, or michael@0: * GMT[+-]hh. michael@0: * @param sign Receves parsed sign, 1 for positive, -1 for negative. michael@0: * @param hour Receives parsed hour field michael@0: * @param minute Receives parsed minute field michael@0: * @param second Receives parsed second field michael@0: * @return Returns TRUE when the given custom id is valid. michael@0: */ michael@0: static UBool parseCustomID(const UnicodeString& id, int32_t& sign, int32_t& hour, michael@0: int32_t& minute, int32_t& second); michael@0: michael@0: /** michael@0: * Parse a custom time zone identifier and return the normalized michael@0: * custom time zone identifier for the given custom id string. michael@0: * @param id a string of the form GMT[+-]hh:mm, GMT[+-]hhmm, or michael@0: * GMT[+-]hh. michael@0: * @param normalized Receives the normalized custom ID michael@0: * @param status Receives the status. When the input ID string is invalid, michael@0: * U_ILLEGAL_ARGUMENT_ERROR is set. michael@0: * @return The normalized custom id string. michael@0: */ michael@0: static UnicodeString& getCustomID(const UnicodeString& id, UnicodeString& normalized, michael@0: UErrorCode& status); michael@0: michael@0: /** michael@0: * Returns the normalized custome time zone ID for the given offset fields. michael@0: * @param hour offset hours michael@0: * @param min offset minutes michael@0: * @param sec offset seconds michael@0: * @param negative sign of the offset, TRUE for negative offset. michael@0: * @param id Receves the format result (normalized custom ID) michael@0: * @return The reference to id michael@0: */ michael@0: static UnicodeString& formatCustomID(int32_t hour, int32_t min, int32_t sec, michael@0: UBool negative, UnicodeString& id); michael@0: michael@0: UnicodeString fID; // this time zone's ID michael@0: michael@0: friend class TZEnumeration; michael@0: }; michael@0: michael@0: michael@0: // ------------------------------------- michael@0: michael@0: inline UnicodeString& michael@0: TimeZone::getID(UnicodeString& ID) const michael@0: { michael@0: ID = fID; michael@0: return ID; michael@0: } michael@0: michael@0: // ------------------------------------- michael@0: michael@0: inline void michael@0: TimeZone::setID(const UnicodeString& ID) michael@0: { michael@0: fID = ID; michael@0: } michael@0: U_NAMESPACE_END michael@0: michael@0: #endif /* #if !UCONFIG_NO_FORMATTING */ michael@0: michael@0: #endif //_TIMEZONE michael@0: //eof