|
||||
Warning, file /include/unicode/timezone.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 // © 2016 and later: Unicode, Inc. and others. 0002 // License & terms of use: http://www.unicode.org/copyright.html 0003 /************************************************************************* 0004 * Copyright (c) 1997-2016, International Business Machines Corporation 0005 * and others. All Rights Reserved. 0006 ************************************************************************** 0007 * 0008 * File TIMEZONE.H 0009 * 0010 * Modification History: 0011 * 0012 * Date Name Description 0013 * 04/21/97 aliu Overhauled header. 0014 * 07/09/97 helena Changed createInstance to createDefault. 0015 * 08/06/97 aliu Removed dependency on internal header for Hashtable. 0016 * 08/10/98 stephen Changed getDisplayName() API conventions to match 0017 * 08/19/98 stephen Changed createTimeZone() to never return 0 0018 * 09/02/98 stephen Sync to JDK 1.2 8/31 0019 * - Added getOffset(... monthlen ...) 0020 * - Added hasSameRules() 0021 * 09/15/98 stephen Added getStaticClassID 0022 * 12/03/99 aliu Moved data out of static table into icudata.dll. 0023 * Hashtable replaced by new static data structures. 0024 * 12/14/99 aliu Made GMT public. 0025 * 08/15/01 grhoten Made GMT private and added the getGMT() function 0026 ************************************************************************** 0027 */ 0028 0029 #ifndef TIMEZONE_H 0030 #define TIMEZONE_H 0031 0032 #include "unicode/utypes.h" 0033 0034 #if U_SHOW_CPLUSPLUS_API 0035 0036 /** 0037 * \file 0038 * \brief C++ API: TimeZone object 0039 */ 0040 0041 #if !UCONFIG_NO_FORMATTING 0042 0043 #include "unicode/uobject.h" 0044 #include "unicode/unistr.h" 0045 #include "unicode/ures.h" 0046 #include "unicode/ucal.h" 0047 0048 U_NAMESPACE_BEGIN 0049 0050 class StringEnumeration; 0051 0052 /** 0053 * 0054 * <code>TimeZone</code> represents a time zone offset, and also figures out daylight 0055 * savings. 0056 * 0057 * <p> 0058 * Typically, you get a <code>TimeZone</code> using <code>createDefault</code> 0059 * which creates a <code>TimeZone</code> based on the time zone where the program 0060 * is running. For example, for a program running in Japan, <code>createDefault</code> 0061 * creates a <code>TimeZone</code> object based on Japanese Standard Time. 0062 * 0063 * <p> 0064 * You can also get a <code>TimeZone</code> using <code>createTimeZone</code> along 0065 * with a time zone ID. For instance, the time zone ID for the US Pacific 0066 * Time zone is "America/Los_Angeles". So, you can get a Pacific Time <code>TimeZone</code> object 0067 * with: 0068 * \htmlonly<blockquote>\endhtmlonly 0069 * <pre> 0070 * TimeZone *tz = TimeZone::createTimeZone("America/Los_Angeles"); 0071 * </pre> 0072 * \htmlonly</blockquote>\endhtmlonly 0073 * You can use the <code>createEnumeration</code> method to iterate through 0074 * all the supported time zone IDs, or the <code>getCanonicalID</code> method to check 0075 * if a time zone ID is supported or not. You can then choose a 0076 * supported ID to get a <code>TimeZone</code>. 0077 * If the time zone you want is not represented by one of the 0078 * supported IDs, then you can create a custom time zone ID with 0079 * the following syntax: 0080 * 0081 * \htmlonly<blockquote>\endhtmlonly 0082 * <pre> 0083 * GMT[+|-]hh[[:]mm] 0084 * </pre> 0085 * \htmlonly</blockquote>\endhtmlonly 0086 * 0087 * For example, you might specify GMT+14:00 as a custom 0088 * time zone ID. The <code>TimeZone</code> that is returned 0089 * when you specify a custom time zone ID uses the specified 0090 * offset from GMT(=UTC) and does not observe daylight saving 0091 * time. For example, you might specify GMT+14:00 as a custom 0092 * time zone ID to create a TimeZone representing 14 hours ahead 0093 * of GMT (with no daylight saving time). In addition, 0094 * <code>getCanonicalID</code> can also be used to 0095 * normalize a custom time zone ID. 0096 * 0097 * TimeZone is an abstract class representing a time zone. A TimeZone is needed for 0098 * Calendar to produce local time for a particular time zone. A TimeZone comprises 0099 * three basic pieces of information: 0100 * <ul> 0101 * <li>A time zone offset; that, is the number of milliseconds to add or subtract 0102 * from a time expressed in terms of GMT to convert it to the same time in that 0103 * time zone (without taking daylight savings time into account).</li> 0104 * <li>Logic necessary to take daylight savings time into account if daylight savings 0105 * time is observed in that time zone (e.g., the days and hours on which daylight 0106 * savings time begins and ends).</li> 0107 * <li>An ID. This is a text string that uniquely identifies the time zone.</li> 0108 * </ul> 0109 * 0110 * (Only the ID is actually implemented in TimeZone; subclasses of TimeZone may handle 0111 * daylight savings time and GMT offset in different ways. Currently we have the following 0112 * TimeZone subclasses: RuleBasedTimeZone, SimpleTimeZone, and VTimeZone.) 0113 * <P> 0114 * The TimeZone class contains a static list containing a TimeZone object for every 0115 * combination of GMT offset and daylight-savings time rules currently in use in the 0116 * world, each with a unique ID. Each ID consists of a region (usually a continent or 0117 * ocean) and a city in that region, separated by a slash, (for example, US Pacific 0118 * Time is "America/Los_Angeles.") Because older versions of this class used 0119 * three- or four-letter abbreviations instead, there is also a table that maps the older 0120 * abbreviations to the newer ones (for example, "PST" maps to "America/Los_Angeles"). 0121 * Anywhere the API requires an ID, you can use either form. 0122 * <P> 0123 * To create a new TimeZone, you call the factory function TimeZone::createTimeZone() 0124 * and pass it a time zone ID. You can use the createEnumeration() function to 0125 * obtain a list of all the time zone IDs recognized by createTimeZone(). 0126 * <P> 0127 * You can also use TimeZone::createDefault() to create a TimeZone. This function uses 0128 * platform-specific APIs to produce a TimeZone for the time zone corresponding to 0129 * the client's computer's physical location. For example, if you're in Japan (assuming 0130 * your machine is set up correctly), TimeZone::createDefault() will return a TimeZone 0131 * for Japanese Standard Time ("Asia/Tokyo"). 0132 */ 0133 class U_I18N_API TimeZone : public UObject { 0134 public: 0135 /** 0136 * @stable ICU 2.0 0137 */ 0138 virtual ~TimeZone(); 0139 0140 /** 0141 * Returns the "unknown" time zone. 0142 * It behaves like the GMT/UTC time zone but has the 0143 * <code>UCAL_UNKNOWN_ZONE_ID</code> = "Etc/Unknown". 0144 * createTimeZone() returns a mutable clone of this time zone if the input ID is not recognized. 0145 * 0146 * @return the "unknown" time zone. 0147 * @see UCAL_UNKNOWN_ZONE_ID 0148 * @see createTimeZone 0149 * @see getGMT 0150 * @stable ICU 49 0151 */ 0152 static const TimeZone& U_EXPORT2 getUnknown(); 0153 0154 /** 0155 * The GMT (=UTC) time zone has a raw offset of zero and does not use daylight 0156 * savings time. This is a commonly used time zone. 0157 * 0158 * <p>Note: For backward compatibility reason, the ID used by the time 0159 * zone returned by this method is "GMT", although the ICU's canonical 0160 * ID for the GMT time zone is "Etc/GMT". 0161 * 0162 * @return the GMT/UTC time zone. 0163 * @see getUnknown 0164 * @stable ICU 2.0 0165 */ 0166 static const TimeZone* U_EXPORT2 getGMT(void); 0167 0168 /** 0169 * Creates a <code>TimeZone</code> for the given ID. 0170 * @param ID the ID for a <code>TimeZone</code>, such as "America/Los_Angeles", 0171 * or a custom ID such as "GMT-8:00". 0172 * @return the specified <code>TimeZone</code>, or a mutable clone of getUnknown() 0173 * if the given ID cannot be understood or if the given ID is "Etc/Unknown". 0174 * The return result is guaranteed to be non-nullptr. 0175 * If you require that the specific zone asked for be returned, 0176 * compare the result with getUnknown() or check the ID of the return result. 0177 * @stable ICU 2.0 0178 */ 0179 static TimeZone* U_EXPORT2 createTimeZone(const UnicodeString& ID); 0180 0181 /** 0182 * Returns an enumeration over system time zone IDs with the given 0183 * filter conditions. 0184 * @param zoneType The system time zone type. 0185 * @param region The ISO 3166 two-letter country code or UN M.49 0186 * three-digit area code. When nullptr, no filtering 0187 * done by region. 0188 * @param rawOffset An offset from GMT in milliseconds, ignoring 0189 * the effect of daylight savings time, if any. 0190 * When nullptr, no filtering done by zone offset. 0191 * @param ec Output param to filled in with a success or 0192 * an error. 0193 * @return an enumeration object, owned by the caller. 0194 * @stable ICU 4.8 0195 */ 0196 static StringEnumeration* U_EXPORT2 createTimeZoneIDEnumeration( 0197 USystemTimeZoneType zoneType, 0198 const char* region, 0199 const int32_t* rawOffset, 0200 UErrorCode& ec); 0201 0202 #ifndef U_HIDE_DEPRECATED_API 0203 /** 0204 * Returns an enumeration over all recognized time zone IDs. (i.e., 0205 * all strings that createTimeZone() accepts) 0206 * 0207 * @return an enumeration object, owned by the caller. 0208 * @deprecated ICU 70 Use createEnumeration(UErrorCode&) instead. 0209 */ 0210 static StringEnumeration* U_EXPORT2 createEnumeration(); 0211 #endif // U_HIDE_DEPRECATED_API 0212 0213 /** 0214 * Returns an enumeration over all recognized time zone IDs. (i.e., 0215 * all strings that createTimeZone() accepts) 0216 * 0217 * @param status Receives the status. 0218 * @return an enumeration object, owned by the caller. 0219 * @stable ICU 70 0220 */ 0221 static StringEnumeration* U_EXPORT2 createEnumeration(UErrorCode& status); 0222 0223 #ifndef U_HIDE_DEPRECATED_API 0224 /** 0225 * Returns an enumeration over time zone IDs with a given raw 0226 * offset from GMT. There may be several times zones with the 0227 * same GMT offset that differ in the way they handle daylight 0228 * savings time. For example, the state of Arizona doesn't 0229 * observe daylight savings time. If you ask for the time zone 0230 * IDs corresponding to GMT-7:00, you'll get back an enumeration 0231 * over two time zone IDs: "America/Denver," which corresponds to 0232 * Mountain Standard Time in the winter and Mountain Daylight Time 0233 * in the summer, and "America/Phoenix", which corresponds to 0234 * Mountain Standard Time year-round, even in the summer. 0235 * 0236 * @param rawOffset an offset from GMT in milliseconds, ignoring 0237 * the effect of daylight savings time, if any 0238 * @return an enumeration object, owned by the caller 0239 * @deprecated ICU 70 Use createEnumerationForRawOffset(int32_t,UErrorCode&) instead. 0240 */ 0241 static StringEnumeration* U_EXPORT2 createEnumeration(int32_t rawOffset); 0242 #endif // U_HIDE_DEPRECATED_API 0243 0244 /** 0245 * Returns an enumeration over time zone IDs with a given raw 0246 * offset from GMT. There may be several times zones with the 0247 * same GMT offset that differ in the way they handle daylight 0248 * savings time. For example, the state of Arizona doesn't 0249 * observe daylight savings time. If you ask for the time zone 0250 * IDs corresponding to GMT-7:00, you'll get back an enumeration 0251 * over two time zone IDs: "America/Denver," which corresponds to 0252 * Mountain Standard Time in the winter and Mountain Daylight Time 0253 * in the summer, and "America/Phoenix", which corresponds to 0254 * Mountain Standard Time year-round, even in the summer. 0255 * 0256 * @param rawOffset an offset from GMT in milliseconds, ignoring 0257 * the effect of daylight savings time, if any 0258 * @param status Receives the status. 0259 * @return an enumeration object, owned by the caller 0260 * @stable ICU 70 0261 */ 0262 static StringEnumeration* U_EXPORT2 createEnumerationForRawOffset(int32_t rawOffset, UErrorCode& status); 0263 0264 #ifndef U_HIDE_DEPRECATED_API 0265 /** 0266 * Returns an enumeration over time zone IDs associated with the 0267 * given region. Some zones are affiliated with no region 0268 * (e.g., "UTC"); these may also be retrieved, as a group. 0269 * 0270 * @param region The ISO 3166 two-letter country code, or nullptr to 0271 * retrieve zones not affiliated with any region. 0272 * @return an enumeration object, owned by the caller 0273 * @deprecated ICU 70 Use createEnumerationForRegion(const char*,UErrorCode&) instead. 0274 */ 0275 static StringEnumeration* U_EXPORT2 createEnumeration(const char* region); 0276 #endif // U_HIDE_DEPRECATED_API 0277 0278 /** 0279 * Returns an enumeration over time zone IDs associated with the 0280 * given region. Some zones are affiliated with no region 0281 * (e.g., "UTC"); these may also be retrieved, as a group. 0282 * 0283 * @param region The ISO 3166 two-letter country code, or nullptr to 0284 * retrieve zones not affiliated with any region. 0285 * @param status Receives the status. 0286 * @return an enumeration object, owned by the caller 0287 * @stable ICU 70 0288 */ 0289 static StringEnumeration* U_EXPORT2 createEnumerationForRegion(const char* region, UErrorCode& status); 0290 0291 /** 0292 * Returns the number of IDs in the equivalency group that 0293 * includes the given ID. An equivalency group contains zones 0294 * that have the same GMT offset and rules. 0295 * 0296 * <p>The returned count includes the given ID; it is always >= 1. 0297 * The given ID must be a system time zone. If it is not, returns 0298 * zero. 0299 * @param id a system time zone ID 0300 * @return the number of zones in the equivalency group containing 0301 * 'id', or zero if 'id' is not a valid system ID 0302 * @see #getEquivalentID 0303 * @stable ICU 2.0 0304 */ 0305 static int32_t U_EXPORT2 countEquivalentIDs(const UnicodeString& id); 0306 0307 /** 0308 * Returns an ID in the equivalency group that 0309 * includes the given ID. An equivalency group contains zones 0310 * that have the same GMT offset and rules. 0311 * 0312 * <p>The given index must be in the range 0..n-1, where n is the 0313 * value returned by <code>countEquivalentIDs(id)</code>. For 0314 * some value of 'index', the returned value will be equal to the 0315 * given id. If the given id is not a valid system time zone, or 0316 * if 'index' is out of range, then returns an empty string. 0317 * @param id a system time zone ID 0318 * @param index a value from 0 to n-1, where n is the value 0319 * returned by <code>countEquivalentIDs(id)</code> 0320 * @return the ID of the index-th zone in the equivalency group 0321 * containing 'id', or an empty string if 'id' is not a valid 0322 * system ID or 'index' is out of range 0323 * @see #countEquivalentIDs 0324 * @stable ICU 2.0 0325 */ 0326 static const UnicodeString U_EXPORT2 getEquivalentID(const UnicodeString& id, 0327 int32_t index); 0328 0329 /** 0330 * Creates an instance of TimeZone detected from the current host 0331 * system configuration. If the host system detection routines fail, 0332 * or if they specify a TimeZone or TimeZone offset which is not 0333 * recognized, then the special TimeZone "Etc/Unknown" is returned. 0334 * 0335 * Note that ICU4C does not change the default time zone unless 0336 * `TimeZone::adoptDefault(TimeZone*)` or 0337 * `TimeZone::setDefault(const TimeZone&)` is explicitly called by a 0338 * user. This method does not update the current ICU's default, 0339 * and may return a different TimeZone from the one returned by 0340 * `TimeZone::createDefault()`. 0341 * 0342 * <p>This function is not thread safe.</p> 0343 * 0344 * @return A new instance of TimeZone detected from the current host system 0345 * configuration. 0346 * @see adoptDefault 0347 * @see setDefault 0348 * @see createDefault 0349 * @see getUnknown 0350 * @stable ICU 55 0351 */ 0352 static TimeZone* U_EXPORT2 detectHostTimeZone(); 0353 0354 /** 0355 * Creates a new copy of the default TimeZone for this host. Unless the default time 0356 * zone has already been set using adoptDefault() or setDefault(), the default is 0357 * determined by querying the host system configuration. If the host system detection 0358 * routines fail, or if they specify a TimeZone or TimeZone offset which is not 0359 * recognized, then the special TimeZone "Etc/Unknown" is instantiated and made the 0360 * default. 0361 * 0362 * @return A default TimeZone. Clients are responsible for deleting the time zone 0363 * object returned. 0364 * @see getUnknown 0365 * @stable ICU 2.0 0366 */ 0367 static TimeZone* U_EXPORT2 createDefault(void); 0368 0369 #ifndef U_HIDE_INTERNAL_API 0370 /** 0371 * If the locale contains the timezone keyword, creates a copy of that TimeZone. 0372 * Otherwise, create the default timezone. 0373 * 0374 * @param locale a locale which may contains 'timezone' keyword/value. 0375 * @return A TimeZone. Clients are responsible for deleting the time zone 0376 * object returned. 0377 * @internal 0378 */ 0379 static TimeZone* U_EXPORT2 forLocaleOrDefault(const Locale& locale); 0380 #endif /* U_HIDE_INTERNAL_API */ 0381 0382 /** 0383 * Sets the default time zone (i.e., what's returned by createDefault()) to be the 0384 * specified time zone. If nullptr is specified for the time zone, the default time 0385 * zone is set to the default host time zone. This call adopts the TimeZone object 0386 * passed in; the client is no longer responsible for deleting it. 0387 * 0388 * @param zone A pointer to the new TimeZone object to use as the default. 0389 * @stable ICU 2.0 0390 */ 0391 static void U_EXPORT2 adoptDefault(TimeZone* zone); 0392 0393 #ifndef U_HIDE_SYSTEM_API 0394 /** 0395 * Same as adoptDefault(), except that the TimeZone object passed in is NOT adopted; 0396 * the caller remains responsible for deleting it. 0397 * 0398 * @param zone The given timezone. 0399 * @system 0400 * @stable ICU 2.0 0401 */ 0402 static void U_EXPORT2 setDefault(const TimeZone& zone); 0403 #endif /* U_HIDE_SYSTEM_API */ 0404 0405 /** 0406 * Returns the timezone data version currently used by ICU. 0407 * @param status Output param to filled in with a success or an error. 0408 * @return the version string, such as "2007f" 0409 * @stable ICU 3.8 0410 */ 0411 static const char* U_EXPORT2 getTZDataVersion(UErrorCode& status); 0412 0413 /** 0414 * Returns the canonical system timezone ID or the normalized 0415 * custom time zone ID for the given time zone ID. 0416 * @param id The input time zone ID to be canonicalized. 0417 * @param canonicalID Receives the canonical system time zone ID 0418 * or the custom time zone ID in normalized format. 0419 * @param status Receives the status. When the given time zone ID 0420 * is neither a known system time zone ID nor a 0421 * valid custom time zone ID, U_ILLEGAL_ARGUMENT_ERROR 0422 * is set. 0423 * @return A reference to the result. 0424 * @stable ICU 4.0 0425 */ 0426 static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id, 0427 UnicodeString& canonicalID, UErrorCode& status); 0428 0429 /** 0430 * Returns the canonical system time zone ID or the normalized 0431 * custom time zone ID for the given time zone ID. 0432 * @param id The input time zone ID to be canonicalized. 0433 * @param canonicalID Receives the canonical system time zone ID 0434 * or the custom time zone ID in normalized format. 0435 * @param isSystemID Receives if the given ID is a known system 0436 * time zone ID. 0437 * @param status Receives the status. When the given time zone ID 0438 * is neither a known system time zone ID nor a 0439 * valid custom time zone ID, U_ILLEGAL_ARGUMENT_ERROR 0440 * is set. 0441 * @return A reference to the result. 0442 * @stable ICU 4.0 0443 */ 0444 static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id, 0445 UnicodeString& canonicalID, UBool& isSystemID, UErrorCode& status); 0446 0447 0448 #ifndef U_HIDE_DRAFT_API 0449 /** 0450 * Returns the preferred time zone ID in the IANA time zone database for the given time zone ID. 0451 * There are two types of preferred IDs. The first type is the one defined in zone.tab file, 0452 * such as "America/Los_Angeles". The second types is the one defined for zones not associated 0453 * with a specific region, but not defined with "Link" syntax such as "Etc/GMT+10". 0454 * 0455 * <p>Note: For most of valid time zone IDs, this method returns an ID same as getCanonicalID(). 0456 * getCanonicalID() is based on canonical time zone IDs defined in Unicode CLDR. 0457 * These canonical time zone IDs in CLDR were based on very old version of the time zone database. 0458 * In the IANA time zone database, some IDs were updated since then. This API returns a newer 0459 * time zone ID. For example, CLDR defines "Asia/Calcutta" as the canonical time zone ID. This 0460 * method returns "Asia/Kolkata" instead. 0461 * <p> "Etc/Unknown" is a special time zone ID defined by CLDR. There are no corresponding zones 0462 * in the IANA time zone database. Therefore, this API returns U_ILLEGAL_ARGUMENT_ERROR when the 0463 * input ID is "Etc/Unknown". 0464 * 0465 * @param id The input time zone ID. 0466 * @param ianaID Receives the preferred time zone ID in the IANA time zone database. When 0467 * the given time zone ID is not a known time zone ID, this method sets an 0468 * invalid (bogus) string. 0469 * @param status Receives the status. When the given time zone ID is not a known time zone 0470 * ID, U_ILLEGAL_ARGUMENT_ERROR is set. 0471 * @return A reference to the result. 0472 * @draft ICU 74 0473 */ 0474 static UnicodeString& U_EXPORT2 getIanaID(const UnicodeString&id, UnicodeString& ianaID, 0475 UErrorCode& status); 0476 #endif // U_HIDE_DRAFT_API 0477 0478 /** 0479 * Converts a system time zone ID to an equivalent Windows time zone ID. For example, 0480 * Windows time zone ID "Pacific Standard Time" is returned for input "America/Los_Angeles". 0481 * 0482 * <p>There are system time zones that cannot be mapped to Windows zones. When the input 0483 * system time zone ID is unknown or unmappable to a Windows time zone, then the result will be 0484 * empty, but the operation itself remains successful (no error status set on return). 0485 * 0486 * <p>This implementation utilizes <a href="http://unicode.org/cldr/charts/supplemental/zone_tzid.html"> 0487 * Zone-Tzid mapping data</a>. The mapping data is updated time to time. To get the latest changes, 0488 * please read the ICU user guide section <a href="https://unicode-org.github.io/icu/userguide/datetime/timezone#updating-the-time-zone-data"> 0489 * Updating the Time Zone Data</a>. 0490 * 0491 * @param id A system time zone ID. 0492 * @param winid Receives a Windows time zone ID. When the input system time zone ID is unknown 0493 * or unmappable to a Windows time zone ID, then an empty string is set on return. 0494 * @param status Receives the status. 0495 * @return A reference to the result (<code>winid</code>). 0496 * @see getIDForWindowsID 0497 * 0498 * @stable ICU 52 0499 */ 0500 static UnicodeString& U_EXPORT2 getWindowsID(const UnicodeString& id, 0501 UnicodeString& winid, UErrorCode& status); 0502 0503 /** 0504 * Converts a Windows time zone ID to an equivalent system time zone ID 0505 * for a region. For example, system time zone ID "America/Los_Angeles" is returned 0506 * for input Windows ID "Pacific Standard Time" and region "US" (or <code>null</code>), 0507 * "America/Vancouver" is returned for the same Windows ID "Pacific Standard Time" and 0508 * region "CA". 0509 * 0510 * <p>Not all Windows time zones can be mapped to system time zones. When the input 0511 * Windows time zone ID is unknown or unmappable to a system time zone, then the result 0512 * will be empty, but the operation itself remains successful (no error status set on return). 0513 * 0514 * <p>This implementation utilizes <a href="http://unicode.org/cldr/charts/supplemental/zone_tzid.html"> 0515 * Zone-Tzid mapping data</a>. The mapping data is updated time to time. To get the latest changes, 0516 * please read the ICU user guide section <a href="https://unicode-org.github.io/icu/userguide/datetime/timezone#updating-the-time-zone-data"> 0517 * Updating the Time Zone Data</a>. 0518 * 0519 * @param winid A Windows time zone ID. 0520 * @param region A NUL-terminated region code, or <code>nullptr</code> if no regional preference. 0521 * @param id Receives a system time zone ID. When the input Windows time zone ID is unknown 0522 * or unmappable to a system time zone ID, then an empty string is set on return. 0523 * @param status Receives the status. 0524 * @return A reference to the result (<code>id</code>). 0525 * @see getWindowsID 0526 * 0527 * @stable ICU 52 0528 */ 0529 static UnicodeString& U_EXPORT2 getIDForWindowsID(const UnicodeString& winid, const char* region, 0530 UnicodeString& id, UErrorCode& status); 0531 0532 /** 0533 * Returns true if the two TimeZones are equal. (The TimeZone version only compares 0534 * IDs, but subclasses are expected to also compare the fields they add.) 0535 * 0536 * @param that The TimeZone object to be compared with. 0537 * @return true if the given TimeZone is equal to this TimeZone; false 0538 * otherwise. 0539 * @stable ICU 2.0 0540 */ 0541 virtual bool operator==(const TimeZone& that) const; 0542 0543 /** 0544 * Returns true if the two TimeZones are NOT equal; that is, if operator==() returns 0545 * false. 0546 * 0547 * @param that The TimeZone object to be compared with. 0548 * @return true if the given TimeZone is not equal to this TimeZone; false 0549 * otherwise. 0550 * @stable ICU 2.0 0551 */ 0552 bool operator!=(const TimeZone& that) const {return !operator==(that);} 0553 0554 /** 0555 * Returns the TimeZone's adjusted GMT offset (i.e., the number of milliseconds to add 0556 * to GMT to get local time in this time zone, taking daylight savings time into 0557 * account) as of a particular reference date. The reference date is used to determine 0558 * whether daylight savings time is in effect and needs to be figured into the offset 0559 * that is returned (in other words, what is the adjusted GMT offset in this time zone 0560 * at this particular date and time?). For the time zones produced by createTimeZone(), 0561 * the reference data is specified according to the Gregorian calendar, and the date 0562 * and time fields are local standard time. 0563 * 0564 * <p>Note: Don't call this method. Instead, call the getOffset(UDate...) overload, 0565 * which returns both the raw and the DST offset for a given time. This method 0566 * is retained only for backward compatibility. 0567 * 0568 * @param era The reference date's era 0569 * @param year The reference date's year 0570 * @param month The reference date's month (0-based; 0 is January) 0571 * @param day The reference date's day-in-month (1-based) 0572 * @param dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday) 0573 * @param millis The reference date's milliseconds in day, local standard time 0574 * @param status Output param to filled in with a success or an error. 0575 * @return The offset in milliseconds to add to GMT to get local time. 0576 * @stable ICU 2.0 0577 */ 0578 virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day, 0579 uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const = 0; 0580 0581 /** 0582 * Gets the time zone offset, for current date, modified in case of 0583 * daylight savings. This is the offset to add *to* UTC to get local time. 0584 * 0585 * <p>Note: Don't call this method. Instead, call the getOffset(UDate...) overload, 0586 * which returns both the raw and the DST offset for a given time. This method 0587 * is retained only for backward compatibility. 0588 * 0589 * @param era the era of the given date. 0590 * @param year the year in the given date. 0591 * @param month the month in the given date. 0592 * Month is 0-based. e.g., 0 for January. 0593 * @param day the day-in-month of the given date. 0594 * @param dayOfWeek the day-of-week of the given date. 0595 * @param milliseconds the millis in day in <em>standard</em> local time. 0596 * @param monthLength the length of the given month in days. 0597 * @param status Output param to filled in with a success or an error. 0598 * @return the offset to add *to* GMT to get local time. 0599 * @stable ICU 2.0 0600 */ 0601 virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day, 0602 uint8_t dayOfWeek, int32_t milliseconds, 0603 int32_t monthLength, UErrorCode& status) const = 0; 0604 0605 /** 0606 * Returns the time zone raw and GMT offset for the given moment 0607 * in time. Upon return, local-millis = GMT-millis + rawOffset + 0608 * dstOffset. All computations are performed in the proleptic 0609 * Gregorian calendar. The default implementation in the TimeZone 0610 * class delegates to the 8-argument getOffset(). 0611 * 0612 * @param date moment in time for which to return offsets, in 0613 * units of milliseconds from January 1, 1970 0:00 GMT, either GMT 0614 * time or local wall time, depending on `local'. 0615 * @param local if true, `date' is local wall time; otherwise it 0616 * is in GMT time. 0617 * @param rawOffset output parameter to receive the raw offset, that 0618 * is, the offset not including DST adjustments 0619 * @param dstOffset output parameter to receive the DST offset, 0620 * that is, the offset to be added to `rawOffset' to obtain the 0621 * total offset between local and GMT time. If DST is not in 0622 * effect, this value is zero; otherwise it is a positive value, 0623 * typically one hour. 0624 * @param ec input-output error code 0625 * 0626 * @stable ICU 2.8 0627 */ 0628 virtual void getOffset(UDate date, UBool local, int32_t& rawOffset, 0629 int32_t& dstOffset, UErrorCode& ec) const; 0630 0631 /** 0632 * Sets the TimeZone's raw GMT offset (i.e., the number of milliseconds to add 0633 * to GMT to get local time, before taking daylight savings time into account). 0634 * 0635 * @param offsetMillis The new raw GMT offset for this time zone. 0636 * @stable ICU 2.0 0637 */ 0638 virtual void setRawOffset(int32_t offsetMillis) = 0; 0639 0640 /** 0641 * Returns the TimeZone's raw GMT offset (i.e., the number of milliseconds to add 0642 * to GMT to get local time, before taking daylight savings time into account). 0643 * 0644 * @return The TimeZone's raw GMT offset. 0645 * @stable ICU 2.0 0646 */ 0647 virtual int32_t getRawOffset(void) const = 0; 0648 0649 /** 0650 * Fills in "ID" with the TimeZone's ID. 0651 * 0652 * @param ID Receives this TimeZone's ID. 0653 * @return A reference to 'ID' 0654 * @stable ICU 2.0 0655 */ 0656 UnicodeString& getID(UnicodeString& ID) const; 0657 0658 /** 0659 * Sets the TimeZone's ID to the specified value. This doesn't affect any other 0660 * fields (for example, if you say< 0661 * blockquote><pre> 0662 * . TimeZone* foo = TimeZone::createTimeZone("America/New_York"); 0663 * . foo.setID("America/Los_Angeles"); 0664 * </pre>\htmlonly</blockquote>\endhtmlonly 0665 * the time zone's GMT offset and daylight-savings rules don't change to those for 0666 * Los Angeles. They're still those for New York. Only the ID has changed.) 0667 * 0668 * @param ID The new time zone ID. 0669 * @stable ICU 2.0 0670 */ 0671 void setID(const UnicodeString& ID); 0672 0673 /** 0674 * Enum for use with getDisplayName 0675 * @stable ICU 2.4 0676 */ 0677 enum EDisplayType { 0678 /** 0679 * Selector for short display name 0680 * @stable ICU 2.4 0681 */ 0682 SHORT = 1, 0683 /** 0684 * Selector for long display name 0685 * @stable ICU 2.4 0686 */ 0687 LONG, 0688 /** 0689 * Selector for short generic display name 0690 * @stable ICU 4.4 0691 */ 0692 SHORT_GENERIC, 0693 /** 0694 * Selector for long generic display name 0695 * @stable ICU 4.4 0696 */ 0697 LONG_GENERIC, 0698 /** 0699 * Selector for short display name derived 0700 * from time zone offset 0701 * @stable ICU 4.4 0702 */ 0703 SHORT_GMT, 0704 /** 0705 * Selector for long display name derived 0706 * from time zone offset 0707 * @stable ICU 4.4 0708 */ 0709 LONG_GMT, 0710 /** 0711 * Selector for short display name derived 0712 * from the time zone's fallback name 0713 * @stable ICU 4.4 0714 */ 0715 SHORT_COMMONLY_USED, 0716 /** 0717 * Selector for long display name derived 0718 * from the time zone's fallback name 0719 * @stable ICU 4.4 0720 */ 0721 GENERIC_LOCATION 0722 }; 0723 0724 /** 0725 * Returns a name of this time zone suitable for presentation to the user 0726 * in the default locale. 0727 * This method returns the long name, not including daylight savings. 0728 * If the display name is not available for the locale, 0729 * then this method returns a string in the localized GMT offset format 0730 * such as <code>GMT[+-]HH:mm</code>. 0731 * @param result the human-readable name of this time zone in the default locale. 0732 * @return A reference to 'result'. 0733 * @stable ICU 2.0 0734 */ 0735 UnicodeString& getDisplayName(UnicodeString& result) const; 0736 0737 /** 0738 * Returns a name of this time zone suitable for presentation to the user 0739 * in the specified locale. 0740 * This method returns the long name, not including daylight savings. 0741 * If the display name is not available for the locale, 0742 * then this method returns a string in the localized GMT offset format 0743 * such as <code>GMT[+-]HH:mm</code>. 0744 * @param locale the locale in which to supply the display name. 0745 * @param result the human-readable name of this time zone in the given locale 0746 * or in the default locale if the given locale is not recognized. 0747 * @return A reference to 'result'. 0748 * @stable ICU 2.0 0749 */ 0750 UnicodeString& getDisplayName(const Locale& locale, UnicodeString& result) const; 0751 0752 /** 0753 * Returns a name of this time zone suitable for presentation to the user 0754 * in the default locale. 0755 * If the display name is not available for the locale, 0756 * then this method returns a string in the localized GMT offset format 0757 * such as <code>GMT[+-]HH:mm</code>. 0758 * @param inDaylight if true, return the daylight savings name. 0759 * @param style 0760 * @param result the human-readable name of this time zone in the default locale. 0761 * @return A reference to 'result'. 0762 * @stable ICU 2.0 0763 */ 0764 UnicodeString& getDisplayName(UBool inDaylight, EDisplayType style, UnicodeString& result) const; 0765 0766 /** 0767 * Returns a name of this time zone suitable for presentation to the user 0768 * in the specified locale. 0769 * If the display name is not available for the locale, 0770 * then this method returns a string in the localized GMT offset format 0771 * such as <code>GMT[+-]HH:mm</code>. 0772 * @param inDaylight if true, return the daylight savings name. 0773 * @param style 0774 * @param locale the locale in which to supply the display name. 0775 * @param result the human-readable name of this time zone in the given locale 0776 * or in the default locale if the given locale is not recognized. 0777 * @return A reference to 'result'. 0778 * @stable ICU 2.0 0779 */ 0780 UnicodeString& getDisplayName(UBool inDaylight, EDisplayType style, const Locale& locale, UnicodeString& result) const; 0781 0782 /** 0783 * Queries if this time zone uses daylight savings time. 0784 * @return true if this time zone uses daylight savings time, 0785 * false, otherwise. 0786 * <p><strong>Note:</strong>The default implementation of 0787 * ICU TimeZone uses the tz database, which supports historic 0788 * rule changes, for system time zones. With the implementation, 0789 * there are time zones that used daylight savings time in the 0790 * past, but no longer used currently. For example, Asia/Tokyo has 0791 * never used daylight savings time since 1951. Most clients would 0792 * expect that this method to return <code>false</code> for such case. 0793 * The default implementation of this method returns <code>true</code> 0794 * when the time zone uses daylight savings time in the current 0795 * (Gregorian) calendar year. 0796 * <p>In Java 7, <code>observesDaylightTime()</code> was added in 0797 * addition to <code>useDaylightTime()</code>. In Java, <code>useDaylightTime()</code> 0798 * only checks if daylight saving time is observed by the last known 0799 * rule. This specification might not be what most users would expect 0800 * if daylight saving time is currently observed, but not scheduled 0801 * in future. In this case, Java's <code>userDaylightTime()</code> returns 0802 * <code>false</code>. To resolve the issue, Java 7 added <code>observesDaylightTime()</code>, 0803 * which takes the current rule into account. The method <code>observesDaylightTime()</code> 0804 * was added in ICU4J for supporting API signature compatibility with JDK. 0805 * In general, ICU4C also provides JDK compatible methods, but the current 0806 * implementation <code>userDaylightTime()</code> serves the purpose 0807 * (takes the current rule into account), <code>observesDaylightTime()</code> 0808 * is not added in ICU4C. In addition to <code>useDaylightTime()</code>, ICU4C 0809 * <code>BasicTimeZone</code> class (Note that <code>TimeZone::createTimeZone(const UnicodeString &ID)</code> 0810 * always returns a <code>BasicTimeZone</code>) provides a series of methods allowing 0811 * historic and future time zone rule iteration, so you can check if daylight saving 0812 * time is observed or not within a given period. 0813 * 0814 * @stable ICU 2.0 0815 */ 0816 virtual UBool useDaylightTime(void) const = 0; 0817 0818 #ifndef U_FORCE_HIDE_DEPRECATED_API 0819 /** 0820 * Queries if the given date is in daylight savings time in 0821 * this time zone. 0822 * This method is wasteful since it creates a new GregorianCalendar and 0823 * deletes it each time it is called. This is a deprecated method 0824 * and provided only for Java compatibility. 0825 * 0826 * @param date the given UDate. 0827 * @param status Output param filled in with success/error code. 0828 * @return true if the given date is in daylight savings time, 0829 * false, otherwise. 0830 * @deprecated ICU 2.4. Use Calendar::inDaylightTime() instead. 0831 */ 0832 virtual UBool inDaylightTime(UDate date, UErrorCode& status) const = 0; 0833 #endif // U_FORCE_HIDE_DEPRECATED_API 0834 0835 /** 0836 * Returns true if this zone has the same rule and offset as another zone. 0837 * That is, if this zone differs only in ID, if at all. 0838 * @param other the <code>TimeZone</code> object to be compared with 0839 * @return true if the given zone is the same as this one, 0840 * with the possible exception of the ID 0841 * @stable ICU 2.0 0842 */ 0843 virtual UBool hasSameRules(const TimeZone& other) const; 0844 0845 /** 0846 * Clones TimeZone objects polymorphically. Clients are responsible for deleting 0847 * the TimeZone object cloned. 0848 * 0849 * @return A new copy of this TimeZone object. 0850 * @stable ICU 2.0 0851 */ 0852 virtual TimeZone* clone() const = 0; 0853 0854 /** 0855 * Return the class ID for this class. This is useful only for 0856 * comparing to a return value from getDynamicClassID(). 0857 * @return The class ID for all objects of this class. 0858 * @stable ICU 2.0 0859 */ 0860 static UClassID U_EXPORT2 getStaticClassID(void); 0861 0862 /** 0863 * Returns a unique class ID POLYMORPHICALLY. This method is to 0864 * implement a simple version of RTTI, since not all C++ compilers support genuine 0865 * RTTI. Polymorphic operator==() and clone() methods call this method. 0866 * <P> 0867 * Concrete subclasses of TimeZone must use the UOBJECT_DEFINE_RTTI_IMPLEMENTATION 0868 * macro from uobject.h in their implementation to provide correct RTTI information. 0869 * @return The class ID for this object. All objects of a given class have the 0870 * same class ID. Objects of other classes have different class IDs. 0871 * @stable ICU 2.0 0872 */ 0873 virtual UClassID getDynamicClassID(void) const override = 0; 0874 0875 /** 0876 * Returns the amount of time to be added to local standard time 0877 * to get local wall clock time. 0878 * <p> 0879 * The default implementation always returns 3600000 milliseconds 0880 * (i.e., one hour) if this time zone observes Daylight Saving 0881 * Time. Otherwise, 0 (zero) is returned. 0882 * <p> 0883 * If an underlying TimeZone implementation subclass supports 0884 * historical Daylight Saving Time changes, this method returns 0885 * the known latest daylight saving value. 0886 * 0887 * @return the amount of saving time in milliseconds 0888 * @stable ICU 3.6 0889 */ 0890 virtual int32_t getDSTSavings() const; 0891 0892 /** 0893 * Gets the region code associated with the given 0894 * system time zone ID. The region code is either ISO 3166 0895 * 2-letter country code or UN M.49 3-digit area code. 0896 * When the time zone is not associated with a specific location, 0897 * for example - "Etc/UTC", "EST5EDT", then this method returns 0898 * "001" (UN M.49 area code for World). 0899 * 0900 * @param id The system time zone ID. 0901 * @param region Output buffer for receiving the region code. 0902 * @param capacity The size of the output buffer. 0903 * @param status Receives the status. When the given time zone ID 0904 * is not a known system time zone ID, 0905 * U_ILLEGAL_ARGUMENT_ERROR is set. 0906 * @return The length of the output region code. 0907 * @stable ICU 4.8 0908 */ 0909 static int32_t U_EXPORT2 getRegion(const UnicodeString& id, 0910 char *region, int32_t capacity, UErrorCode& status); 0911 0912 protected: 0913 0914 /** 0915 * Default constructor. ID is initialized to the empty string. 0916 * @stable ICU 2.0 0917 */ 0918 TimeZone(); 0919 0920 /** 0921 * Construct a TimeZone with a given ID. 0922 * @param id a system time zone ID 0923 * @stable ICU 2.0 0924 */ 0925 TimeZone(const UnicodeString &id); 0926 0927 /** 0928 * Copy constructor. 0929 * @param source the object to be copied. 0930 * @stable ICU 2.0 0931 */ 0932 TimeZone(const TimeZone& source); 0933 0934 /** 0935 * Default assignment operator. 0936 * @param right the object to be copied. 0937 * @stable ICU 2.0 0938 */ 0939 TimeZone& operator=(const TimeZone& right); 0940 0941 #ifndef U_HIDE_INTERNAL_API 0942 /** 0943 * Utility function. For internally loading rule data. 0944 * @param top Top resource bundle for tz data 0945 * @param ruleid ID of rule to load 0946 * @param oldbundle Old bundle to reuse or nullptr 0947 * @param status Status parameter 0948 * @return either a new bundle or *oldbundle 0949 * @internal 0950 */ 0951 static UResourceBundle* loadRule(const UResourceBundle* top, const UnicodeString& ruleid, UResourceBundle* oldbundle, UErrorCode&status); 0952 #endif /* U_HIDE_INTERNAL_API */ 0953 0954 private: 0955 friend class ZoneMeta; 0956 0957 0958 static TimeZone* createCustomTimeZone(const UnicodeString&); // Creates a time zone based on the string. 0959 0960 /** 0961 * Finds the given ID in the Olson tzdata. If the given ID is found in the tzdata, 0962 * returns the pointer to the ID resource. This method is exposed through ZoneMeta class 0963 * for ICU internal implementation and useful for building hashtable using a time zone 0964 * ID as a key. 0965 * @param id zone id string 0966 * @return the pointer of the ID resource, or nullptr. 0967 */ 0968 static const char16_t* findID(const UnicodeString& id); 0969 0970 /** 0971 * Resolve a link in Olson tzdata. When the given id is known and it's not a link, 0972 * the id itself is returned. When the given id is known and it is a link, then 0973 * dereferenced zone id is returned. When the given id is unknown, then it returns 0974 * nullptr. 0975 * @param id zone id string 0976 * @return the dereferenced zone or nullptr 0977 */ 0978 static const char16_t* dereferOlsonLink(const UnicodeString& id); 0979 0980 /** 0981 * Returns the region code associated with the given zone, 0982 * or nullptr if the zone is not known. 0983 * @param id zone id string 0984 * @return the region associated with the given zone 0985 */ 0986 static const char16_t* getRegion(const UnicodeString& id); 0987 0988 public: 0989 #ifndef U_HIDE_INTERNAL_API 0990 /** 0991 * Returns the region code associated with the given zone, 0992 * or nullptr if the zone is not known. 0993 * @param id zone id string 0994 * @param status Status parameter 0995 * @return the region associated with the given zone 0996 * @internal 0997 */ 0998 static const char16_t* getRegion(const UnicodeString& id, UErrorCode& status); 0999 #endif /* U_HIDE_INTERNAL_API */ 1000 1001 private: 1002 /** 1003 * Parses the given custom time zone identifier 1004 * @param id id A string of the form GMT[+-]hh:mm, GMT[+-]hhmm, or 1005 * GMT[+-]hh. 1006 * @param sign Receives parsed sign, 1 for positive, -1 for negative. 1007 * @param hour Receives parsed hour field 1008 * @param minute Receives parsed minute field 1009 * @param second Receives parsed second field 1010 * @return Returns true when the given custom id is valid. 1011 */ 1012 static UBool parseCustomID(const UnicodeString& id, int32_t& sign, int32_t& hour, 1013 int32_t& minute, int32_t& second); 1014 1015 /** 1016 * Parse a custom time zone identifier and return the normalized 1017 * custom time zone identifier for the given custom id string. 1018 * @param id a string of the form GMT[+-]hh:mm, GMT[+-]hhmm, or 1019 * GMT[+-]hh. 1020 * @param normalized Receives the normalized custom ID 1021 * @param status Receives the status. When the input ID string is invalid, 1022 * U_ILLEGAL_ARGUMENT_ERROR is set. 1023 * @return The normalized custom id string. 1024 */ 1025 static UnicodeString& getCustomID(const UnicodeString& id, UnicodeString& normalized, 1026 UErrorCode& status); 1027 1028 /** 1029 * Returns the normalized custom time zone ID for the given offset fields. 1030 * @param hour offset hours 1031 * @param min offset minutes 1032 * @param sec offset seconds 1033 * @param negative sign of the offset, true for negative offset. 1034 * @param id Receives the format result (normalized custom ID) 1035 * @return The reference to id 1036 */ 1037 static UnicodeString& formatCustomID(int32_t hour, int32_t min, int32_t sec, 1038 UBool negative, UnicodeString& id); 1039 1040 UnicodeString fID; // this time zone's ID 1041 1042 friend class TZEnumeration; 1043 }; 1044 1045 1046 // ------------------------------------- 1047 1048 inline UnicodeString& 1049 TimeZone::getID(UnicodeString& ID) const 1050 { 1051 ID = fID; 1052 return ID; 1053 } 1054 1055 // ------------------------------------- 1056 1057 inline void 1058 TimeZone::setID(const UnicodeString& ID) 1059 { 1060 fID = ID; 1061 } 1062 U_NAMESPACE_END 1063 1064 #endif /* #if !UCONFIG_NO_FORMATTING */ 1065 1066 #endif /* U_SHOW_CPLUSPLUS_API */ 1067 1068 #endif //_TIMEZONE 1069 //eof
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |