1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/i18n/unicode/timezone.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,951 @@ 1.4 +/************************************************************************* 1.5 +* Copyright (c) 1997-2013, International Business Machines Corporation 1.6 +* and others. All Rights Reserved. 1.7 +************************************************************************** 1.8 +* 1.9 +* File TIMEZONE.H 1.10 +* 1.11 +* Modification History: 1.12 +* 1.13 +* Date Name Description 1.14 +* 04/21/97 aliu Overhauled header. 1.15 +* 07/09/97 helena Changed createInstance to createDefault. 1.16 +* 08/06/97 aliu Removed dependency on internal header for Hashtable. 1.17 +* 08/10/98 stephen Changed getDisplayName() API conventions to match 1.18 +* 08/19/98 stephen Changed createTimeZone() to never return 0 1.19 +* 09/02/98 stephen Sync to JDK 1.2 8/31 1.20 +* - Added getOffset(... monthlen ...) 1.21 +* - Added hasSameRules() 1.22 +* 09/15/98 stephen Added getStaticClassID 1.23 +* 12/03/99 aliu Moved data out of static table into icudata.dll. 1.24 +* Hashtable replaced by new static data structures. 1.25 +* 12/14/99 aliu Made GMT public. 1.26 +* 08/15/01 grhoten Made GMT private and added the getGMT() function 1.27 +************************************************************************** 1.28 +*/ 1.29 + 1.30 +#ifndef TIMEZONE_H 1.31 +#define TIMEZONE_H 1.32 + 1.33 +#include "unicode/utypes.h" 1.34 + 1.35 +/** 1.36 + * \file 1.37 + * \brief C++ API: TimeZone object 1.38 + */ 1.39 + 1.40 +#if !UCONFIG_NO_FORMATTING 1.41 + 1.42 +#include "unicode/uobject.h" 1.43 +#include "unicode/unistr.h" 1.44 +#include "unicode/ures.h" 1.45 +#include "unicode/ucal.h" 1.46 + 1.47 +U_NAMESPACE_BEGIN 1.48 + 1.49 +class StringEnumeration; 1.50 + 1.51 +/** 1.52 + * 1.53 + * <code>TimeZone</code> represents a time zone offset, and also figures out daylight 1.54 + * savings. 1.55 + * 1.56 + * <p> 1.57 + * Typically, you get a <code>TimeZone</code> using <code>createDefault</code> 1.58 + * which creates a <code>TimeZone</code> based on the time zone where the program 1.59 + * is running. For example, for a program running in Japan, <code>createDefault</code> 1.60 + * creates a <code>TimeZone</code> object based on Japanese Standard Time. 1.61 + * 1.62 + * <p> 1.63 + * You can also get a <code>TimeZone</code> using <code>createTimeZone</code> along 1.64 + * with a time zone ID. For instance, the time zone ID for the US Pacific 1.65 + * Time zone is "America/Los_Angeles". So, you can get a Pacific Time <code>TimeZone</code> object 1.66 + * with: 1.67 + * \htmlonly<blockquote>\endhtmlonly 1.68 + * <pre> 1.69 + * TimeZone *tz = TimeZone::createTimeZone("America/Los_Angeles"); 1.70 + * </pre> 1.71 + * \htmlonly</blockquote>\endhtmlonly 1.72 + * You can use <code>getAvailableIDs</code> method to iterate through 1.73 + * all the supported time zone IDs, or getCanonicalID method to check 1.74 + * if a time zone ID is supported or not. You can then choose a 1.75 + * supported ID to get a <code>TimeZone</code>. 1.76 + * If the time zone you want is not represented by one of the 1.77 + * supported IDs, then you can create a custom time zone ID with 1.78 + * the following syntax: 1.79 + * 1.80 + * \htmlonly<blockquote>\endhtmlonly 1.81 + * <pre> 1.82 + * GMT[+|-]hh[[:]mm] 1.83 + * </pre> 1.84 + * \htmlonly</blockquote>\endhtmlonly 1.85 + * 1.86 + * For example, you might specify GMT+14:00 as a custom 1.87 + * time zone ID. The <code>TimeZone</code> that is returned 1.88 + * when you specify a custom time zone ID uses the specified 1.89 + * offset from GMT(=UTC) and does not observe daylight saving 1.90 + * time. For example, you might specify GMT+14:00 as a custom 1.91 + * time zone ID to create a TimeZone representing 14 hours ahead 1.92 + * of GMT (with no daylight saving time). In addition, 1.93 + * <code>getCanonicalID</code> can also be used to 1.94 + * normalize a custom time zone ID. 1.95 + * 1.96 + * TimeZone is an abstract class representing a time zone. A TimeZone is needed for 1.97 + * Calendar to produce local time for a particular time zone. A TimeZone comprises 1.98 + * three basic pieces of information: 1.99 + * <ul> 1.100 + * <li>A time zone offset; that, is the number of milliseconds to add or subtract 1.101 + * from a time expressed in terms of GMT to convert it to the same time in that 1.102 + * time zone (without taking daylight savings time into account).</li> 1.103 + * <li>Logic necessary to take daylight savings time into account if daylight savings 1.104 + * time is observed in that time zone (e.g., the days and hours on which daylight 1.105 + * savings time begins and ends).</li> 1.106 + * <li>An ID. This is a text string that uniquely identifies the time zone.</li> 1.107 + * </ul> 1.108 + * 1.109 + * (Only the ID is actually implemented in TimeZone; subclasses of TimeZone may handle 1.110 + * daylight savings time and GMT offset in different ways. Currently we have the following 1.111 + * TimeZone subclasses: RuleBasedTimeZone, SimpleTimeZone, and VTimeZone.) 1.112 + * <P> 1.113 + * The TimeZone class contains a static list containing a TimeZone object for every 1.114 + * combination of GMT offset and daylight-savings time rules currently in use in the 1.115 + * world, each with a unique ID. Each ID consists of a region (usually a continent or 1.116 + * ocean) and a city in that region, separated by a slash, (for example, US Pacific 1.117 + * Time is "America/Los_Angeles.") Because older versions of this class used 1.118 + * three- or four-letter abbreviations instead, there is also a table that maps the older 1.119 + * abbreviations to the newer ones (for example, "PST" maps to "America/Los_Angeles"). 1.120 + * Anywhere the API requires an ID, you can use either form. 1.121 + * <P> 1.122 + * To create a new TimeZone, you call the factory function TimeZone::createTimeZone() 1.123 + * and pass it a time zone ID. You can use the createEnumeration() function to 1.124 + * obtain a list of all the time zone IDs recognized by createTimeZone(). 1.125 + * <P> 1.126 + * You can also use TimeZone::createDefault() to create a TimeZone. This function uses 1.127 + * platform-specific APIs to produce a TimeZone for the time zone corresponding to 1.128 + * the client's computer's physical location. For example, if you're in Japan (assuming 1.129 + * your machine is set up correctly), TimeZone::createDefault() will return a TimeZone 1.130 + * for Japanese Standard Time ("Asia/Tokyo"). 1.131 + */ 1.132 +class U_I18N_API TimeZone : public UObject { 1.133 +public: 1.134 + /** 1.135 + * @stable ICU 2.0 1.136 + */ 1.137 + virtual ~TimeZone(); 1.138 + 1.139 + /** 1.140 + * Returns the "unknown" time zone. 1.141 + * It behaves like the GMT/UTC time zone but has the 1.142 + * <code>UCAL_UNKNOWN_ZONE_ID</code> = "Etc/Unknown". 1.143 + * createTimeZone() returns a mutable clone of this time zone if the input ID is not recognized. 1.144 + * 1.145 + * @return the "unknown" time zone. 1.146 + * @see UCAL_UNKNOWN_ZONE_ID 1.147 + * @see createTimeZone 1.148 + * @see getGMT 1.149 + * @stable ICU 49 1.150 + */ 1.151 + static const TimeZone& U_EXPORT2 getUnknown(); 1.152 + 1.153 + /** 1.154 + * The GMT (=UTC) time zone has a raw offset of zero and does not use daylight 1.155 + * savings time. This is a commonly used time zone. 1.156 + * 1.157 + * <p>Note: For backward compatibility reason, the ID used by the time 1.158 + * zone returned by this method is "GMT", although the ICU's canonical 1.159 + * ID for the GMT time zone is "Etc/GMT". 1.160 + * 1.161 + * @return the GMT/UTC time zone. 1.162 + * @see getUnknown 1.163 + * @stable ICU 2.0 1.164 + */ 1.165 + static const TimeZone* U_EXPORT2 getGMT(void); 1.166 + 1.167 + /** 1.168 + * Creates a <code>TimeZone</code> for the given ID. 1.169 + * @param ID the ID for a <code>TimeZone</code>, such as "America/Los_Angeles", 1.170 + * or a custom ID such as "GMT-8:00". 1.171 + * @return the specified <code>TimeZone</code>, or a mutable clone of getUnknown() 1.172 + * if the given ID cannot be understood or if the given ID is "Etc/Unknown". 1.173 + * The return result is guaranteed to be non-NULL. 1.174 + * If you require that the specific zone asked for be returned, 1.175 + * compare the result with getUnknown() or check the ID of the return result. 1.176 + * @stable ICU 2.0 1.177 + */ 1.178 + static TimeZone* U_EXPORT2 createTimeZone(const UnicodeString& ID); 1.179 + 1.180 + /** 1.181 + * Returns an enumeration over system time zone IDs with the given 1.182 + * filter conditions. 1.183 + * @param zoneType The system time zone type. 1.184 + * @param region The ISO 3166 two-letter country code or UN M.49 1.185 + * three-digit area code. When NULL, no filtering 1.186 + * done by region. 1.187 + * @param rawOffset An offset from GMT in milliseconds, ignoring 1.188 + * the effect of daylight savings time, if any. 1.189 + * When NULL, no filtering done by zone offset. 1.190 + * @param ec Output param to filled in with a success or 1.191 + * an error. 1.192 + * @return an enumeration object, owned by the caller. 1.193 + * @stable ICU 4.8 1.194 + */ 1.195 + static StringEnumeration* U_EXPORT2 createTimeZoneIDEnumeration( 1.196 + USystemTimeZoneType zoneType, 1.197 + const char* region, 1.198 + const int32_t* rawOffset, 1.199 + UErrorCode& ec); 1.200 + 1.201 + /** 1.202 + * Returns an enumeration over all recognized time zone IDs. (i.e., 1.203 + * all strings that createTimeZone() accepts) 1.204 + * 1.205 + * @return an enumeration object, owned by the caller. 1.206 + * @stable ICU 2.4 1.207 + */ 1.208 + static StringEnumeration* U_EXPORT2 createEnumeration(); 1.209 + 1.210 + /** 1.211 + * Returns an enumeration over time zone IDs with a given raw 1.212 + * offset from GMT. There may be several times zones with the 1.213 + * same GMT offset that differ in the way they handle daylight 1.214 + * savings time. For example, the state of Arizona doesn't 1.215 + * observe daylight savings time. If you ask for the time zone 1.216 + * IDs corresponding to GMT-7:00, you'll get back an enumeration 1.217 + * over two time zone IDs: "America/Denver," which corresponds to 1.218 + * Mountain Standard Time in the winter and Mountain Daylight Time 1.219 + * in the summer, and "America/Phoenix", which corresponds to 1.220 + * Mountain Standard Time year-round, even in the summer. 1.221 + * 1.222 + * @param rawOffset an offset from GMT in milliseconds, ignoring 1.223 + * the effect of daylight savings time, if any 1.224 + * @return an enumeration object, owned by the caller 1.225 + * @stable ICU 2.4 1.226 + */ 1.227 + static StringEnumeration* U_EXPORT2 createEnumeration(int32_t rawOffset); 1.228 + 1.229 + /** 1.230 + * Returns an enumeration over time zone IDs associated with the 1.231 + * given country. Some zones are affiliated with no country 1.232 + * (e.g., "UTC"); these may also be retrieved, as a group. 1.233 + * 1.234 + * @param country The ISO 3166 two-letter country code, or NULL to 1.235 + * retrieve zones not affiliated with any country. 1.236 + * @return an enumeration object, owned by the caller 1.237 + * @stable ICU 2.4 1.238 + */ 1.239 + static StringEnumeration* U_EXPORT2 createEnumeration(const char* country); 1.240 + 1.241 + /** 1.242 + * Returns the number of IDs in the equivalency group that 1.243 + * includes the given ID. An equivalency group contains zones 1.244 + * that have the same GMT offset and rules. 1.245 + * 1.246 + * <p>The returned count includes the given ID; it is always >= 1. 1.247 + * The given ID must be a system time zone. If it is not, returns 1.248 + * zero. 1.249 + * @param id a system time zone ID 1.250 + * @return the number of zones in the equivalency group containing 1.251 + * 'id', or zero if 'id' is not a valid system ID 1.252 + * @see #getEquivalentID 1.253 + * @stable ICU 2.0 1.254 + */ 1.255 + static int32_t U_EXPORT2 countEquivalentIDs(const UnicodeString& id); 1.256 + 1.257 + /** 1.258 + * Returns an ID in the equivalency group that 1.259 + * includes the given ID. An equivalency group contains zones 1.260 + * that have the same GMT offset and rules. 1.261 + * 1.262 + * <p>The given index must be in the range 0..n-1, where n is the 1.263 + * value returned by <code>countEquivalentIDs(id)</code>. For 1.264 + * some value of 'index', the returned value will be equal to the 1.265 + * given id. If the given id is not a valid system time zone, or 1.266 + * if 'index' is out of range, then returns an empty string. 1.267 + * @param id a system time zone ID 1.268 + * @param index a value from 0 to n-1, where n is the value 1.269 + * returned by <code>countEquivalentIDs(id)</code> 1.270 + * @return the ID of the index-th zone in the equivalency group 1.271 + * containing 'id', or an empty string if 'id' is not a valid 1.272 + * system ID or 'index' is out of range 1.273 + * @see #countEquivalentIDs 1.274 + * @stable ICU 2.0 1.275 + */ 1.276 + static const UnicodeString U_EXPORT2 getEquivalentID(const UnicodeString& id, 1.277 + int32_t index); 1.278 + 1.279 + /** 1.280 + * Creates a new copy of the default TimeZone for this host. Unless the default time 1.281 + * zone has already been set using adoptDefault() or setDefault(), the default is 1.282 + * determined by querying the system using methods in TPlatformUtilities. If the 1.283 + * system routines fail, or if they specify a TimeZone or TimeZone offset which is not 1.284 + * recognized, the TimeZone indicated by the ID kLastResortID is instantiated 1.285 + * and made the default. 1.286 + * 1.287 + * @return A default TimeZone. Clients are responsible for deleting the time zone 1.288 + * object returned. 1.289 + * @stable ICU 2.0 1.290 + */ 1.291 + static TimeZone* U_EXPORT2 createDefault(void); 1.292 + 1.293 + /** 1.294 + * Sets the default time zone (i.e., what's returned by createDefault()) to be the 1.295 + * specified time zone. If NULL is specified for the time zone, the default time 1.296 + * zone is set to the default host time zone. This call adopts the TimeZone object 1.297 + * passed in; the client is no longer responsible for deleting it. 1.298 + * 1.299 + * <p>This function is not thread safe. It is an error for multiple threads 1.300 + * to concurrently attempt to set the default time zone, or for any thread 1.301 + * to attempt to reference the default zone while another thread is setting it. 1.302 + * 1.303 + * @param zone A pointer to the new TimeZone object to use as the default. 1.304 + * @stable ICU 2.0 1.305 + */ 1.306 + static void U_EXPORT2 adoptDefault(TimeZone* zone); 1.307 + 1.308 +#ifndef U_HIDE_SYSTEM_API 1.309 + /** 1.310 + * Same as adoptDefault(), except that the TimeZone object passed in is NOT adopted; 1.311 + * the caller remains responsible for deleting it. 1.312 + * 1.313 + * <p>See the thread safety note under adoptDefault(). 1.314 + * 1.315 + * @param zone The given timezone. 1.316 + * @system 1.317 + * @stable ICU 2.0 1.318 + */ 1.319 + static void U_EXPORT2 setDefault(const TimeZone& zone); 1.320 +#endif /* U_HIDE_SYSTEM_API */ 1.321 + 1.322 + /** 1.323 + * Returns the timezone data version currently used by ICU. 1.324 + * @param status Output param to filled in with a success or an error. 1.325 + * @return the version string, such as "2007f" 1.326 + * @stable ICU 3.8 1.327 + */ 1.328 + static const char* U_EXPORT2 getTZDataVersion(UErrorCode& status); 1.329 + 1.330 + /** 1.331 + * Returns the canonical system timezone ID or the normalized 1.332 + * custom time zone ID for the given time zone ID. 1.333 + * @param id The input time zone ID to be canonicalized. 1.334 + * @param canonicalID Receives the canonical system time zone ID 1.335 + * or the custom time zone ID in normalized format. 1.336 + * @param status Recevies the status. When the given time zone ID 1.337 + * is neither a known system time zone ID nor a 1.338 + * valid custom time zone ID, U_ILLEGAL_ARGUMENT_ERROR 1.339 + * is set. 1.340 + * @return A reference to the result. 1.341 + * @stable ICU 4.0 1.342 + */ 1.343 + static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id, 1.344 + UnicodeString& canonicalID, UErrorCode& status); 1.345 + 1.346 + /** 1.347 + * Returns the canonical system time zone ID or the normalized 1.348 + * custom time zone ID for the given time zone ID. 1.349 + * @param id The input time zone ID to be canonicalized. 1.350 + * @param canonicalID Receives the canonical system time zone ID 1.351 + * or the custom time zone ID in normalized format. 1.352 + * @param isSystemID Receives if the given ID is a known system 1.353 + * time zone ID. 1.354 + * @param status Recevies the status. When the given time zone ID 1.355 + * is neither a known system time zone ID nor a 1.356 + * valid custom time zone ID, U_ILLEGAL_ARGUMENT_ERROR 1.357 + * is set. 1.358 + * @return A reference to the result. 1.359 + * @stable ICU 4.0 1.360 + */ 1.361 + static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id, 1.362 + UnicodeString& canonicalID, UBool& isSystemID, UErrorCode& status); 1.363 + 1.364 +#ifndef U_HIDE_DRAFT_API 1.365 + /** 1.366 + * Converts a system time zone ID to an equivalent Windows time zone ID. For example, 1.367 + * Windows time zone ID "Pacific Standard Time" is returned for input "America/Los_Angeles". 1.368 + * 1.369 + * <p>There are system time zones that cannot be mapped to Windows zones. When the input 1.370 + * system time zone ID is unknown or unmappable to a Windows time zone, then the result will be 1.371 + * empty, but the operation itself remains successful (no error status set on return). 1.372 + * 1.373 + * <p>This implementation utilizes <a href="http://unicode.org/cldr/charts/supplemental/zone_tzid.html"> 1.374 + * Zone-Tzid mapping data</a>. The mapping data is updated time to time. To get the latest changes, 1.375 + * please read the ICU user guide section <a href="http://userguide.icu-project.org/datetime/timezone#TOC-Updating-the-Time-Zone-Data"> 1.376 + * Updating the Time Zone Data</a>. 1.377 + * 1.378 + * @param id A system time zone ID. 1.379 + * @param winid Receives a Windows time zone ID. When the input system time zone ID is unknown 1.380 + * or unmappable to a Windows time zone ID, then an empty string is set on return. 1.381 + * @param status Receives the status. 1.382 + * @return A reference to the result (<code>winid</code>). 1.383 + * @see getIDForWindowsID 1.384 + * 1.385 + * @draft ICU 52 1.386 + */ 1.387 + static UnicodeString& U_EXPORT2 getWindowsID(const UnicodeString& id, 1.388 + UnicodeString& winid, UErrorCode& status); 1.389 + 1.390 + /** 1.391 + * Converts a Windows time zone ID to an equivalent system time zone ID 1.392 + * for a region. For example, system time zone ID "America/Los_Angeles" is returned 1.393 + * for input Windows ID "Pacific Standard Time" and region "US" (or <code>null</code>), 1.394 + * "America/Vancouver" is returned for the same Windows ID "Pacific Standard Time" and 1.395 + * region "CA". 1.396 + * 1.397 + * <p>Not all Windows time zones can be mapped to system time zones. When the input 1.398 + * Windows time zone ID is unknown or unmappable to a system time zone, then the result 1.399 + * will be empty, but the operation itself remains successful (no error status set on return). 1.400 + * 1.401 + * <p>This implementation utilizes <a href="http://unicode.org/cldr/charts/supplemental/zone_tzid.html"> 1.402 + * Zone-Tzid mapping data</a>. The mapping data is updated time to time. To get the latest changes, 1.403 + * please read the ICU user guide section <a href="http://userguide.icu-project.org/datetime/timezone#TOC-Updating-the-Time-Zone-Data"> 1.404 + * Updating the Time Zone Data</a>. 1.405 + * 1.406 + * @param winid A Windows time zone ID. 1.407 + * @param region A null-terminated region code, or <code>NULL</code> if no regional preference. 1.408 + * @param id Receives a system time zone ID. When the input Windows time zone ID is unknown 1.409 + * or unmappable to a system time zone ID, then an empty string is set on return. 1.410 + * @param status Receives the status. 1.411 + * @return A reference to the result (<code>id</code>). 1.412 + * @see getWindowsID 1.413 + * 1.414 + * @draft ICU 52 1.415 + */ 1.416 + static UnicodeString& U_EXPORT2 getIDForWindowsID(const UnicodeString& winid, const char* region, 1.417 + UnicodeString& id, UErrorCode& status); 1.418 + 1.419 +#endif /* U_HIDE_DRAFT_API */ 1.420 + 1.421 + /** 1.422 + * Returns true if the two TimeZones are equal. (The TimeZone version only compares 1.423 + * IDs, but subclasses are expected to also compare the fields they add.) 1.424 + * 1.425 + * @param that The TimeZone object to be compared with. 1.426 + * @return True if the given TimeZone is equal to this TimeZone; false 1.427 + * otherwise. 1.428 + * @stable ICU 2.0 1.429 + */ 1.430 + virtual UBool operator==(const TimeZone& that) const; 1.431 + 1.432 + /** 1.433 + * Returns true if the two TimeZones are NOT equal; that is, if operator==() returns 1.434 + * false. 1.435 + * 1.436 + * @param that The TimeZone object to be compared with. 1.437 + * @return True if the given TimeZone is not equal to this TimeZone; false 1.438 + * otherwise. 1.439 + * @stable ICU 2.0 1.440 + */ 1.441 + UBool operator!=(const TimeZone& that) const {return !operator==(that);} 1.442 + 1.443 + /** 1.444 + * Returns the TimeZone's adjusted GMT offset (i.e., the number of milliseconds to add 1.445 + * to GMT to get local time in this time zone, taking daylight savings time into 1.446 + * account) as of a particular reference date. The reference date is used to determine 1.447 + * whether daylight savings time is in effect and needs to be figured into the offset 1.448 + * that is returned (in other words, what is the adjusted GMT offset in this time zone 1.449 + * at this particular date and time?). For the time zones produced by createTimeZone(), 1.450 + * the reference data is specified according to the Gregorian calendar, and the date 1.451 + * and time fields are local standard time. 1.452 + * 1.453 + * <p>Note: Don't call this method. Instead, call the getOffset(UDate...) overload, 1.454 + * which returns both the raw and the DST offset for a given time. This method 1.455 + * is retained only for backward compatibility. 1.456 + * 1.457 + * @param era The reference date's era 1.458 + * @param year The reference date's year 1.459 + * @param month The reference date's month (0-based; 0 is January) 1.460 + * @param day The reference date's day-in-month (1-based) 1.461 + * @param dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday) 1.462 + * @param millis The reference date's milliseconds in day, local standard time 1.463 + * @param status Output param to filled in with a success or an error. 1.464 + * @return The offset in milliseconds to add to GMT to get local time. 1.465 + * @stable ICU 2.0 1.466 + */ 1.467 + virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day, 1.468 + uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const = 0; 1.469 + 1.470 + /** 1.471 + * Gets the time zone offset, for current date, modified in case of 1.472 + * daylight savings. This is the offset to add *to* UTC to get local time. 1.473 + * 1.474 + * <p>Note: Don't call this method. Instead, call the getOffset(UDate...) overload, 1.475 + * which returns both the raw and the DST offset for a given time. This method 1.476 + * is retained only for backward compatibility. 1.477 + * 1.478 + * @param era the era of the given date. 1.479 + * @param year the year in the given date. 1.480 + * @param month the month in the given date. 1.481 + * Month is 0-based. e.g., 0 for January. 1.482 + * @param day the day-in-month of the given date. 1.483 + * @param dayOfWeek the day-of-week of the given date. 1.484 + * @param milliseconds the millis in day in <em>standard</em> local time. 1.485 + * @param monthLength the length of the given month in days. 1.486 + * @param status Output param to filled in with a success or an error. 1.487 + * @return the offset to add *to* GMT to get local time. 1.488 + * @stable ICU 2.0 1.489 + */ 1.490 + virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day, 1.491 + uint8_t dayOfWeek, int32_t milliseconds, 1.492 + int32_t monthLength, UErrorCode& status) const = 0; 1.493 + 1.494 + /** 1.495 + * Returns the time zone raw and GMT offset for the given moment 1.496 + * in time. Upon return, local-millis = GMT-millis + rawOffset + 1.497 + * dstOffset. All computations are performed in the proleptic 1.498 + * Gregorian calendar. The default implementation in the TimeZone 1.499 + * class delegates to the 8-argument getOffset(). 1.500 + * 1.501 + * @param date moment in time for which to return offsets, in 1.502 + * units of milliseconds from January 1, 1970 0:00 GMT, either GMT 1.503 + * time or local wall time, depending on `local'. 1.504 + * @param local if true, `date' is local wall time; otherwise it 1.505 + * is in GMT time. 1.506 + * @param rawOffset output parameter to receive the raw offset, that 1.507 + * is, the offset not including DST adjustments 1.508 + * @param dstOffset output parameter to receive the DST offset, 1.509 + * that is, the offset to be added to `rawOffset' to obtain the 1.510 + * total offset between local and GMT time. If DST is not in 1.511 + * effect, this value is zero; otherwise it is a positive value, 1.512 + * typically one hour. 1.513 + * @param ec input-output error code 1.514 + * 1.515 + * @stable ICU 2.8 1.516 + */ 1.517 + virtual void getOffset(UDate date, UBool local, int32_t& rawOffset, 1.518 + int32_t& dstOffset, UErrorCode& ec) const; 1.519 + 1.520 + /** 1.521 + * Sets the TimeZone's raw GMT offset (i.e., the number of milliseconds to add 1.522 + * to GMT to get local time, before taking daylight savings time into account). 1.523 + * 1.524 + * @param offsetMillis The new raw GMT offset for this time zone. 1.525 + * @stable ICU 2.0 1.526 + */ 1.527 + virtual void setRawOffset(int32_t offsetMillis) = 0; 1.528 + 1.529 + /** 1.530 + * Returns the TimeZone's raw GMT offset (i.e., the number of milliseconds to add 1.531 + * to GMT to get local time, before taking daylight savings time into account). 1.532 + * 1.533 + * @return The TimeZone's raw GMT offset. 1.534 + * @stable ICU 2.0 1.535 + */ 1.536 + virtual int32_t getRawOffset(void) const = 0; 1.537 + 1.538 + /** 1.539 + * Fills in "ID" with the TimeZone's ID. 1.540 + * 1.541 + * @param ID Receives this TimeZone's ID. 1.542 + * @return A reference to 'ID' 1.543 + * @stable ICU 2.0 1.544 + */ 1.545 + UnicodeString& getID(UnicodeString& ID) const; 1.546 + 1.547 + /** 1.548 + * Sets the TimeZone's ID to the specified value. This doesn't affect any other 1.549 + * fields (for example, if you say< 1.550 + * blockquote><pre> 1.551 + * . TimeZone* foo = TimeZone::createTimeZone("America/New_York"); 1.552 + * . foo.setID("America/Los_Angeles"); 1.553 + * </pre>\htmlonly</blockquote>\endhtmlonly 1.554 + * the time zone's GMT offset and daylight-savings rules don't change to those for 1.555 + * Los Angeles. They're still those for New York. Only the ID has changed.) 1.556 + * 1.557 + * @param ID The new time zone ID. 1.558 + * @stable ICU 2.0 1.559 + */ 1.560 + void setID(const UnicodeString& ID); 1.561 + 1.562 + /** 1.563 + * Enum for use with getDisplayName 1.564 + * @stable ICU 2.4 1.565 + */ 1.566 + enum EDisplayType { 1.567 + /** 1.568 + * Selector for short display name 1.569 + * @stable ICU 2.4 1.570 + */ 1.571 + SHORT = 1, 1.572 + /** 1.573 + * Selector for long display name 1.574 + * @stable ICU 2.4 1.575 + */ 1.576 + LONG, 1.577 + /** 1.578 + * Selector for short generic display name 1.579 + * @stable ICU 4.4 1.580 + */ 1.581 + SHORT_GENERIC, 1.582 + /** 1.583 + * Selector for long generic display name 1.584 + * @stable ICU 4.4 1.585 + */ 1.586 + LONG_GENERIC, 1.587 + /** 1.588 + * Selector for short display name derived 1.589 + * from time zone offset 1.590 + * @stable ICU 4.4 1.591 + */ 1.592 + SHORT_GMT, 1.593 + /** 1.594 + * Selector for long display name derived 1.595 + * from time zone offset 1.596 + * @stable ICU 4.4 1.597 + */ 1.598 + LONG_GMT, 1.599 + /** 1.600 + * Selector for short display name derived 1.601 + * from the time zone's fallback name 1.602 + * @stable ICU 4.4 1.603 + */ 1.604 + SHORT_COMMONLY_USED, 1.605 + /** 1.606 + * Selector for long display name derived 1.607 + * from the time zone's fallback name 1.608 + * @stable ICU 4.4 1.609 + */ 1.610 + GENERIC_LOCATION 1.611 + }; 1.612 + 1.613 + /** 1.614 + * Returns a name of this time zone suitable for presentation to the user 1.615 + * in the default locale. 1.616 + * This method returns the long name, not including daylight savings. 1.617 + * If the display name is not available for the locale, 1.618 + * then this method returns a string in the format 1.619 + * <code>GMT[+-]hh:mm</code>. 1.620 + * @param result the human-readable name of this time zone in the default locale. 1.621 + * @return A reference to 'result'. 1.622 + * @stable ICU 2.0 1.623 + */ 1.624 + UnicodeString& getDisplayName(UnicodeString& result) const; 1.625 + 1.626 + /** 1.627 + * Returns a name of this time zone suitable for presentation to the user 1.628 + * in the specified locale. 1.629 + * This method returns the long name, not including daylight savings. 1.630 + * If the display name is not available for the locale, 1.631 + * then this method returns a string in the format 1.632 + * <code>GMT[+-]hh:mm</code>. 1.633 + * @param locale the locale in which to supply the display name. 1.634 + * @param result the human-readable name of this time zone in the given locale 1.635 + * or in the default locale if the given locale is not recognized. 1.636 + * @return A reference to 'result'. 1.637 + * @stable ICU 2.0 1.638 + */ 1.639 + UnicodeString& getDisplayName(const Locale& locale, UnicodeString& result) const; 1.640 + 1.641 + /** 1.642 + * Returns a name of this time zone suitable for presentation to the user 1.643 + * in the default locale. 1.644 + * If the display name is not available for the locale, 1.645 + * then this method returns a string in the format 1.646 + * <code>GMT[+-]hh:mm</code>. 1.647 + * @param daylight if true, return the daylight savings name. 1.648 + * @param style 1.649 + * @param result the human-readable name of this time zone in the default locale. 1.650 + * @return A reference to 'result'. 1.651 + * @stable ICU 2.0 1.652 + */ 1.653 + UnicodeString& getDisplayName(UBool daylight, EDisplayType style, UnicodeString& result) const; 1.654 + 1.655 + /** 1.656 + * Returns a name of this time zone suitable for presentation to the user 1.657 + * in the specified locale. 1.658 + * If the display name is not available for the locale, 1.659 + * then this method returns a string in the format 1.660 + * <code>GMT[+-]hh:mm</code>. 1.661 + * @param daylight if true, return the daylight savings name. 1.662 + * @param style 1.663 + * @param locale the locale in which to supply the display name. 1.664 + * @param result the human-readable name of this time zone in the given locale 1.665 + * or in the default locale if the given locale is not recognized. 1.666 + * @return A refence to 'result'. 1.667 + * @stable ICU 2.0 1.668 + */ 1.669 + UnicodeString& getDisplayName(UBool daylight, EDisplayType style, const Locale& locale, UnicodeString& result) const; 1.670 + 1.671 + /** 1.672 + * Queries if this time zone uses daylight savings time. 1.673 + * @return true if this time zone uses daylight savings time, 1.674 + * false, otherwise. 1.675 + * <p><strong>Note:</strong>The default implementation of 1.676 + * ICU TimeZone uses the tz database, which supports historic 1.677 + * rule changes, for system time zones. With the implementation, 1.678 + * there are time zones that used daylight savings time in the 1.679 + * past, but no longer used currently. For example, Asia/Tokyo has 1.680 + * never used daylight savings time since 1951. Most clients would 1.681 + * expect that this method to return <code>FALSE</code> for such case. 1.682 + * The default implementation of this method returns <code>TRUE</code> 1.683 + * when the time zone uses daylight savings time in the current 1.684 + * (Gregorian) calendar year. 1.685 + * <p>In Java 7, <code>observesDaylightTime()</code> was added in 1.686 + * addition to <code>useDaylightTime()</code>. In Java, <code>useDaylightTime()</code> 1.687 + * only checks if daylight saving time is observed by the last known 1.688 + * rule. This specification might not be what most users would expect 1.689 + * if daylight saving time is currently observed, but not scheduled 1.690 + * in future. In this case, Java's <code>userDaylightTime()</code> returns 1.691 + * <code>false</code>. To resolve the issue, Java 7 added <code>observesDaylightTime()</code>, 1.692 + * which takes the current rule into account. The method <code>observesDaylightTime()</code> 1.693 + * was added in ICU4J for supporting API signature compatibility with JDK. 1.694 + * In general, ICU4C also provides JDK compatible methods, but the current 1.695 + * implementation <code>userDaylightTime()</code> serves the purpose 1.696 + * (takes the current rule into account), <code>observesDaylightTime()</code> 1.697 + * is not added in ICU4C. In addition to <code>useDaylightTime()</code>, ICU4C 1.698 + * <code>BasicTimeZone</code> class (Note that <code>TimeZone::createTimeZone(const UnicodeString &ID)</code> 1.699 + * always returns a <code>BasicTimeZone</code>) provides a series of methods allowing 1.700 + * historic and future time zone rule iteration, so you can check if daylight saving 1.701 + * time is observed or not within a given period. 1.702 + * 1.703 + * @stable ICU 2.0 1.704 + */ 1.705 + virtual UBool useDaylightTime(void) const = 0; 1.706 + 1.707 + /** 1.708 + * Queries if the given date is in daylight savings time in 1.709 + * this time zone. 1.710 + * This method is wasteful since it creates a new GregorianCalendar and 1.711 + * deletes it each time it is called. This is a deprecated method 1.712 + * and provided only for Java compatibility. 1.713 + * 1.714 + * @param date the given UDate. 1.715 + * @param status Output param filled in with success/error code. 1.716 + * @return true if the given date is in daylight savings time, 1.717 + * false, otherwise. 1.718 + * @deprecated ICU 2.4. Use Calendar::inDaylightTime() instead. 1.719 + */ 1.720 + virtual UBool inDaylightTime(UDate date, UErrorCode& status) const = 0; 1.721 + 1.722 + /** 1.723 + * Returns true if this zone has the same rule and offset as another zone. 1.724 + * That is, if this zone differs only in ID, if at all. 1.725 + * @param other the <code>TimeZone</code> object to be compared with 1.726 + * @return true if the given zone is the same as this one, 1.727 + * with the possible exception of the ID 1.728 + * @stable ICU 2.0 1.729 + */ 1.730 + virtual UBool hasSameRules(const TimeZone& other) const; 1.731 + 1.732 + /** 1.733 + * Clones TimeZone objects polymorphically. Clients are responsible for deleting 1.734 + * the TimeZone object cloned. 1.735 + * 1.736 + * @return A new copy of this TimeZone object. 1.737 + * @stable ICU 2.0 1.738 + */ 1.739 + virtual TimeZone* clone(void) const = 0; 1.740 + 1.741 + /** 1.742 + * Return the class ID for this class. This is useful only for 1.743 + * comparing to a return value from getDynamicClassID(). 1.744 + * @return The class ID for all objects of this class. 1.745 + * @stable ICU 2.0 1.746 + */ 1.747 + static UClassID U_EXPORT2 getStaticClassID(void); 1.748 + 1.749 + /** 1.750 + * Returns a unique class ID POLYMORPHICALLY. This method is to 1.751 + * implement a simple version of RTTI, since not all C++ compilers support genuine 1.752 + * RTTI. Polymorphic operator==() and clone() methods call this method. 1.753 + * <P> 1.754 + * Concrete subclasses of TimeZone must use the UOBJECT_DEFINE_RTTI_IMPLEMENTATION 1.755 + * macro from uobject.h in their implementation to provide correct RTTI information. 1.756 + * @return The class ID for this object. All objects of a given class have the 1.757 + * same class ID. Objects of other classes have different class IDs. 1.758 + * @stable ICU 2.0 1.759 + */ 1.760 + virtual UClassID getDynamicClassID(void) const = 0; 1.761 + 1.762 + /** 1.763 + * Returns the amount of time to be added to local standard time 1.764 + * to get local wall clock time. 1.765 + * <p> 1.766 + * The default implementation always returns 3600000 milliseconds 1.767 + * (i.e., one hour) if this time zone observes Daylight Saving 1.768 + * Time. Otherwise, 0 (zero) is returned. 1.769 + * <p> 1.770 + * If an underlying TimeZone implementation subclass supports 1.771 + * historical Daylight Saving Time changes, this method returns 1.772 + * the known latest daylight saving value. 1.773 + * 1.774 + * @return the amount of saving time in milliseconds 1.775 + * @stable ICU 3.6 1.776 + */ 1.777 + virtual int32_t getDSTSavings() const; 1.778 + 1.779 + /** 1.780 + * Gets the region code associated with the given 1.781 + * system time zone ID. The region code is either ISO 3166 1.782 + * 2-letter country code or UN M.49 3-digit area code. 1.783 + * When the time zone is not associated with a specific location, 1.784 + * for example - "Etc/UTC", "EST5EDT", then this method returns 1.785 + * "001" (UN M.49 area code for World). 1.786 + * 1.787 + * @param id The system time zone ID. 1.788 + * @param region Output buffer for receiving the region code. 1.789 + * @param capacity The size of the output buffer. 1.790 + * @param status Receives the status. When the given time zone ID 1.791 + * is not a known system time zone ID, 1.792 + * U_ILLEGAL_ARGUMENT_ERROR is set. 1.793 + * @return The length of the output region code. 1.794 + * @stable ICU 4.8 1.795 + */ 1.796 + static int32_t U_EXPORT2 getRegion(const UnicodeString& id, 1.797 + char *region, int32_t capacity, UErrorCode& status); 1.798 + 1.799 +protected: 1.800 + 1.801 + /** 1.802 + * Default constructor. ID is initialized to the empty string. 1.803 + * @stable ICU 2.0 1.804 + */ 1.805 + TimeZone(); 1.806 + 1.807 + /** 1.808 + * Construct a TimeZone with a given ID. 1.809 + * @param id a system time zone ID 1.810 + * @stable ICU 2.0 1.811 + */ 1.812 + TimeZone(const UnicodeString &id); 1.813 + 1.814 + /** 1.815 + * Copy constructor. 1.816 + * @param source the object to be copied. 1.817 + * @stable ICU 2.0 1.818 + */ 1.819 + TimeZone(const TimeZone& source); 1.820 + 1.821 + /** 1.822 + * Default assignment operator. 1.823 + * @param right the object to be copied. 1.824 + * @stable ICU 2.0 1.825 + */ 1.826 + TimeZone& operator=(const TimeZone& right); 1.827 + 1.828 +#ifndef U_HIDE_INTERNAL_API 1.829 + /** 1.830 + * Utility function. For internally loading rule data. 1.831 + * @param top Top resource bundle for tz data 1.832 + * @param ruleid ID of rule to load 1.833 + * @param oldbundle Old bundle to reuse or NULL 1.834 + * @param status Status parameter 1.835 + * @return either a new bundle or *oldbundle 1.836 + * @internal 1.837 + */ 1.838 + static UResourceBundle* loadRule(const UResourceBundle* top, const UnicodeString& ruleid, UResourceBundle* oldbundle, UErrorCode&status); 1.839 +#endif /* U_HIDE_INTERNAL_API */ 1.840 + 1.841 +private: 1.842 + friend class ZoneMeta; 1.843 + 1.844 + 1.845 + static TimeZone* createCustomTimeZone(const UnicodeString&); // Creates a time zone based on the string. 1.846 + 1.847 + /** 1.848 + * Finds the given ID in the Olson tzdata. If the given ID is found in the tzdata, 1.849 + * returns the pointer to the ID resource. This method is exposed through ZoneMeta class 1.850 + * for ICU internal implementation and useful for building hashtable using a time zone 1.851 + * ID as a key. 1.852 + * @param id zone id string 1.853 + * @return the pointer of the ID resource, or NULL. 1.854 + */ 1.855 + static const UChar* findID(const UnicodeString& id); 1.856 + 1.857 + /** 1.858 + * Resolve a link in Olson tzdata. When the given id is known and it's not a link, 1.859 + * the id itself is returned. When the given id is known and it is a link, then 1.860 + * dereferenced zone id is returned. When the given id is unknown, then it returns 1.861 + * NULL. 1.862 + * @param id zone id string 1.863 + * @return the dereferenced zone or NULL 1.864 + */ 1.865 + static const UChar* dereferOlsonLink(const UnicodeString& id); 1.866 + 1.867 + /** 1.868 + * Returns the region code associated with the given zone, 1.869 + * or NULL if the zone is not known. 1.870 + * @param id zone id string 1.871 + * @return the region associated with the given zone 1.872 + */ 1.873 + static const UChar* getRegion(const UnicodeString& id); 1.874 + 1.875 + public: 1.876 +#ifndef U_HIDE_INTERNAL_API 1.877 + /** 1.878 + * Returns the region code associated with the given zone, 1.879 + * or NULL if the zone is not known. 1.880 + * @param id zone id string 1.881 + * @param status Status parameter 1.882 + * @return the region associated with the given zone 1.883 + * @internal 1.884 + */ 1.885 + static const UChar* getRegion(const UnicodeString& id, UErrorCode& status); 1.886 +#endif /* U_HIDE_INTERNAL_API */ 1.887 + 1.888 + private: 1.889 + /** 1.890 + * Parses the given custom time zone identifier 1.891 + * @param id id A string of the form GMT[+-]hh:mm, GMT[+-]hhmm, or 1.892 + * GMT[+-]hh. 1.893 + * @param sign Receves parsed sign, 1 for positive, -1 for negative. 1.894 + * @param hour Receives parsed hour field 1.895 + * @param minute Receives parsed minute field 1.896 + * @param second Receives parsed second field 1.897 + * @return Returns TRUE when the given custom id is valid. 1.898 + */ 1.899 + static UBool parseCustomID(const UnicodeString& id, int32_t& sign, int32_t& hour, 1.900 + int32_t& minute, int32_t& second); 1.901 + 1.902 + /** 1.903 + * Parse a custom time zone identifier and return the normalized 1.904 + * custom time zone identifier for the given custom id string. 1.905 + * @param id a string of the form GMT[+-]hh:mm, GMT[+-]hhmm, or 1.906 + * GMT[+-]hh. 1.907 + * @param normalized Receives the normalized custom ID 1.908 + * @param status Receives the status. When the input ID string is invalid, 1.909 + * U_ILLEGAL_ARGUMENT_ERROR is set. 1.910 + * @return The normalized custom id string. 1.911 + */ 1.912 + static UnicodeString& getCustomID(const UnicodeString& id, UnicodeString& normalized, 1.913 + UErrorCode& status); 1.914 + 1.915 + /** 1.916 + * Returns the normalized custome time zone ID for the given offset fields. 1.917 + * @param hour offset hours 1.918 + * @param min offset minutes 1.919 + * @param sec offset seconds 1.920 + * @param negative sign of the offset, TRUE for negative offset. 1.921 + * @param id Receves the format result (normalized custom ID) 1.922 + * @return The reference to id 1.923 + */ 1.924 + static UnicodeString& formatCustomID(int32_t hour, int32_t min, int32_t sec, 1.925 + UBool negative, UnicodeString& id); 1.926 + 1.927 + UnicodeString fID; // this time zone's ID 1.928 + 1.929 + friend class TZEnumeration; 1.930 +}; 1.931 + 1.932 + 1.933 +// ------------------------------------- 1.934 + 1.935 +inline UnicodeString& 1.936 +TimeZone::getID(UnicodeString& ID) const 1.937 +{ 1.938 + ID = fID; 1.939 + return ID; 1.940 +} 1.941 + 1.942 +// ------------------------------------- 1.943 + 1.944 +inline void 1.945 +TimeZone::setID(const UnicodeString& ID) 1.946 +{ 1.947 + fID = ID; 1.948 +} 1.949 +U_NAMESPACE_END 1.950 + 1.951 +#endif /* #if !UCONFIG_NO_FORMATTING */ 1.952 + 1.953 +#endif //_TIMEZONE 1.954 +//eof