Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-01 08:33:17

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();
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();
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     /**
0449      * Returns the preferred time zone ID in the IANA time zone database for the given time zone ID.
0450      * There are two types of preferred IDs. The first type is the one defined in zone.tab file,
0451      * such as "America/Los_Angeles". The second types is the one defined for zones not associated
0452      * with a specific region, but not defined with "Link" syntax such as "Etc/GMT+10".
0453      *
0454      * <p>Note: For most of valid time zone IDs, this method returns an ID same as getCanonicalID().
0455      * getCanonicalID() is based on canonical time zone IDs defined in Unicode CLDR.
0456      * These canonical time zone IDs in CLDR were based on very old version of the time zone database.
0457      * In the IANA time zone database, some IDs were updated since then. This API returns a newer
0458      * time zone ID. For example, CLDR defines "Asia/Calcutta" as the canonical time zone ID. This
0459      * method returns "Asia/Kolkata" instead.
0460      * <p> "Etc/Unknown" is a special time zone ID defined by CLDR. There are no corresponding zones
0461      * in the IANA time zone database. Therefore, this API returns U_ILLEGAL_ARGUMENT_ERROR when the
0462      * input ID is "Etc/Unknown".
0463      *
0464      * @param id        The input time zone ID.
0465      * @param ianaID    Receives the preferred time zone ID in the IANA time zone database. When
0466      *                  the given time zone ID is not a known time zone ID, this method sets an
0467      *                  invalid (bogus) string.
0468      * @param status    Receives the status.  When the given time zone ID is not a known time zone
0469      *                  ID, U_ILLEGAL_ARGUMENT_ERROR is set.
0470      * @return  A reference to the result.
0471      * @stable ICU 74
0472      */
0473     static UnicodeString& U_EXPORT2 getIanaID(const UnicodeString&id, UnicodeString& ianaID,
0474         UErrorCode& status);
0475 
0476     /**
0477     * Converts a system time zone ID to an equivalent Windows time zone ID. For example,
0478     * Windows time zone ID "Pacific Standard Time" is returned for input "America/Los_Angeles".
0479     *
0480     * <p>There are system time zones that cannot be mapped to Windows zones. When the input
0481     * system time zone ID is unknown or unmappable to a Windows time zone, then the result will be
0482     * empty, but the operation itself remains successful (no error status set on return).
0483     *
0484     * <p>This implementation utilizes <a href="http://unicode.org/cldr/charts/supplemental/zone_tzid.html">
0485     * Zone-Tzid mapping data</a>. The mapping data is updated time to time. To get the latest changes,
0486     * please read the ICU user guide section <a href="https://unicode-org.github.io/icu/userguide/datetime/timezone#updating-the-time-zone-data">
0487     * Updating the Time Zone Data</a>.
0488     *
0489     * @param id        A system time zone ID.
0490     * @param winid     Receives a Windows time zone ID. When the input system time zone ID is unknown
0491     *                  or unmappable to a Windows time zone ID, then an empty string is set on return.
0492     * @param status    Receives the status.
0493     * @return          A reference to the result (<code>winid</code>).
0494     * @see getIDForWindowsID
0495     *
0496     * @stable ICU 52
0497     */
0498     static UnicodeString& U_EXPORT2 getWindowsID(const UnicodeString& id,
0499         UnicodeString& winid, UErrorCode& status);
0500 
0501     /**
0502     * Converts a Windows time zone ID to an equivalent system time zone ID
0503     * for a region. For example, system time zone ID "America/Los_Angeles" is returned
0504     * for input Windows ID "Pacific Standard Time" and region "US" (or <code>null</code>),
0505     * "America/Vancouver" is returned for the same Windows ID "Pacific Standard Time" and
0506     * region "CA".
0507     *
0508     * <p>Not all Windows time zones can be mapped to system time zones. When the input
0509     * Windows time zone ID is unknown or unmappable to a system time zone, then the result
0510     * will be empty, but the operation itself remains successful (no error status set on return).
0511     *
0512     * <p>This implementation utilizes <a href="http://unicode.org/cldr/charts/supplemental/zone_tzid.html">
0513     * Zone-Tzid mapping data</a>. The mapping data is updated time to time. To get the latest changes,
0514     * please read the ICU user guide section <a href="https://unicode-org.github.io/icu/userguide/datetime/timezone#updating-the-time-zone-data">
0515     * Updating the Time Zone Data</a>.
0516     *
0517     * @param winid     A Windows time zone ID.
0518     * @param region    A NUL-terminated region code, or <code>nullptr</code> if no regional preference.
0519     * @param id        Receives a system time zone ID. When the input Windows time zone ID is unknown
0520     *                  or unmappable to a system time zone ID, then an empty string is set on return.
0521     * @param status    Receives the status.
0522     * @return          A reference to the result (<code>id</code>).
0523     * @see getWindowsID
0524     *
0525     * @stable ICU 52
0526     */
0527     static UnicodeString& U_EXPORT2 getIDForWindowsID(const UnicodeString& winid, const char* region,
0528         UnicodeString& id, UErrorCode& status);
0529 
0530     /**
0531      * Returns true if the two TimeZones are equal.  (The TimeZone version only compares
0532      * IDs, but subclasses are expected to also compare the fields they add.)
0533      *
0534      * @param that  The TimeZone object to be compared with.
0535      * @return      true if the given TimeZone is equal to this TimeZone; false
0536      *              otherwise.
0537      * @stable ICU 2.0
0538      */
0539     virtual bool operator==(const TimeZone& that) const;
0540 
0541     /**
0542      * Returns true if the two TimeZones are NOT equal; that is, if operator==() returns
0543      * false.
0544      *
0545      * @param that  The TimeZone object to be compared with.
0546      * @return      true if the given TimeZone is not equal to this TimeZone; false
0547      *              otherwise.
0548      * @stable ICU 2.0
0549      */
0550     bool operator!=(const TimeZone& that) const {return !operator==(that);}
0551 
0552     /**
0553      * Returns the TimeZone's adjusted GMT offset (i.e., the number of milliseconds to add
0554      * to GMT to get local time in this time zone, taking daylight savings time into
0555      * account) as of a particular reference date.  The reference date is used to determine
0556      * whether daylight savings time is in effect and needs to be figured into the offset
0557      * that is returned (in other words, what is the adjusted GMT offset in this time zone
0558      * at this particular date and time?).  For the time zones produced by createTimeZone(),
0559      * the reference data is specified according to the Gregorian calendar, and the date
0560      * and time fields are local standard time.
0561      *
0562      * <p>Note: Don't call this method. Instead, call the getOffset(UDate...) overload,
0563      * which returns both the raw and the DST offset for a given time. This method
0564      * is retained only for backward compatibility.
0565      *
0566      * @param era        The reference date's era
0567      * @param year       The reference date's year
0568      * @param month      The reference date's month (0-based; 0 is January)
0569      * @param day        The reference date's day-in-month (1-based)
0570      * @param dayOfWeek  The reference date's day-of-week (1-based; 1 is Sunday)
0571      * @param millis     The reference date's milliseconds in day, local standard time
0572      * @param status     Output param to filled in with a success or an error.
0573      * @return           The offset in milliseconds to add to GMT to get local time.
0574      * @stable ICU 2.0
0575      */
0576     virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
0577                               uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const = 0;
0578 
0579     /**
0580      * Gets the time zone offset, for current date, modified in case of
0581      * daylight savings. This is the offset to add *to* UTC to get local time.
0582      *
0583      * <p>Note: Don't call this method. Instead, call the getOffset(UDate...) overload,
0584      * which returns both the raw and the DST offset for a given time. This method
0585      * is retained only for backward compatibility.
0586      *
0587      * @param era the era of the given date.
0588      * @param year the year in the given date.
0589      * @param month the month in the given date.
0590      * Month is 0-based. e.g., 0 for January.
0591      * @param day the day-in-month of the given date.
0592      * @param dayOfWeek the day-of-week of the given date.
0593      * @param milliseconds the millis in day in <em>standard</em> local time.
0594      * @param monthLength the length of the given month in days.
0595      * @param status     Output param to filled in with a success or an error.
0596      * @return the offset to add *to* GMT to get local time.
0597      * @stable ICU 2.0
0598      */
0599     virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
0600                            uint8_t dayOfWeek, int32_t milliseconds,
0601                            int32_t monthLength, UErrorCode& status) const = 0;
0602 
0603     /**
0604      * Returns the time zone raw and GMT offset for the given moment
0605      * in time.  Upon return, local-millis = GMT-millis + rawOffset +
0606      * dstOffset.  All computations are performed in the proleptic
0607      * Gregorian calendar.  The default implementation in the TimeZone
0608      * class delegates to the 8-argument getOffset().
0609      *
0610      * @param date moment in time for which to return offsets, in
0611      * units of milliseconds from January 1, 1970 0:00 GMT, either GMT
0612      * time or local wall time, depending on `local'.
0613      * @param local if true, `date' is local wall time; otherwise it
0614      * is in GMT time.
0615      * @param rawOffset output parameter to receive the raw offset, that
0616      * is, the offset not including DST adjustments
0617      * @param dstOffset output parameter to receive the DST offset,
0618      * that is, the offset to be added to `rawOffset' to obtain the
0619      * total offset between local and GMT time. If DST is not in
0620      * effect, this value is zero; otherwise it is a positive value,
0621      * typically one hour.
0622      * @param ec input-output error code
0623      *
0624      * @stable ICU 2.8
0625      */
0626     virtual void getOffset(UDate date, UBool local, int32_t& rawOffset,
0627                            int32_t& dstOffset, UErrorCode& ec) const;
0628 
0629     /**
0630      * Sets the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
0631      * to GMT to get local time, before taking daylight savings time into account).
0632      *
0633      * @param offsetMillis  The new raw GMT offset for this time zone.
0634      * @stable ICU 2.0
0635      */
0636     virtual void setRawOffset(int32_t offsetMillis) = 0;
0637 
0638     /**
0639      * Returns the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
0640      * to GMT to get local time, before taking daylight savings time into account).
0641      *
0642      * @return   The TimeZone's raw GMT offset.
0643      * @stable ICU 2.0
0644      */
0645     virtual int32_t getRawOffset() const = 0;
0646 
0647     /**
0648      * Fills in "ID" with the TimeZone's ID.
0649      *
0650      * @param ID  Receives this TimeZone's ID.
0651      * @return    A reference to 'ID'
0652      * @stable ICU 2.0
0653      */
0654     UnicodeString& getID(UnicodeString& ID) const;
0655 
0656     /**
0657      * Sets the TimeZone's ID to the specified value.  This doesn't affect any other
0658      * fields (for example, if you say<
0659      * blockquote><pre>
0660      * .     TimeZone* foo = TimeZone::createTimeZone("America/New_York");
0661      * .     foo.setID("America/Los_Angeles");
0662      * </pre>\htmlonly</blockquote>\endhtmlonly
0663      * the time zone's GMT offset and daylight-savings rules don't change to those for
0664      * Los Angeles.  They're still those for New York.  Only the ID has changed.)
0665      *
0666      * @param ID  The new time zone ID.
0667      * @stable ICU 2.0
0668      */
0669     void setID(const UnicodeString& ID);
0670 
0671     /**
0672      * Enum for use with getDisplayName
0673      * @stable ICU 2.4
0674      */
0675     enum EDisplayType {
0676         /**
0677          * Selector for short display name
0678          * @stable ICU 2.4
0679          */
0680         SHORT = 1,
0681         /**
0682          * Selector for long display name
0683          * @stable ICU 2.4
0684          */
0685         LONG,
0686         /**
0687          * Selector for short generic display name
0688          * @stable ICU 4.4
0689          */
0690         SHORT_GENERIC,
0691         /**
0692          * Selector for long generic display name
0693          * @stable ICU 4.4
0694          */
0695         LONG_GENERIC,
0696         /**
0697          * Selector for short display name derived
0698          * from time zone offset
0699          * @stable ICU 4.4
0700          */
0701         SHORT_GMT,
0702         /**
0703          * Selector for long display name derived
0704          * from time zone offset
0705          * @stable ICU 4.4
0706          */
0707         LONG_GMT,
0708         /**
0709          * Selector for short display name derived
0710          * from the time zone's fallback name
0711          * @stable ICU 4.4
0712          */
0713         SHORT_COMMONLY_USED,
0714         /**
0715          * Selector for long display name derived
0716          * from the time zone's fallback name
0717          * @stable ICU 4.4
0718          */
0719         GENERIC_LOCATION
0720     };
0721 
0722     /**
0723      * Returns a name of this time zone suitable for presentation to the user
0724      * in the default locale.
0725      * This method returns the long name, not including daylight savings.
0726      * If the display name is not available for the locale,
0727      * then this method returns a string in the localized GMT offset format
0728      * such as <code>GMT[+-]HH:mm</code>.
0729      * @param result the human-readable name of this time zone in the default locale.
0730      * @return       A reference to 'result'.
0731      * @stable ICU 2.0
0732      */
0733     UnicodeString& getDisplayName(UnicodeString& result) const;
0734 
0735     /**
0736      * Returns a name of this time zone suitable for presentation to the user
0737      * in the specified locale.
0738      * This method returns the long name, not including daylight savings.
0739      * If the display name is not available for the locale,
0740      * then this method returns a string in the localized GMT offset format
0741      * such as <code>GMT[+-]HH:mm</code>.
0742      * @param locale the locale in which to supply the display name.
0743      * @param result the human-readable name of this time zone in the given locale
0744      *               or in the default locale if the given locale is not recognized.
0745      * @return       A reference to 'result'.
0746      * @stable ICU 2.0
0747      */
0748     UnicodeString& getDisplayName(const Locale& locale, UnicodeString& result) const;
0749 
0750     /**
0751      * Returns a name of this time zone suitable for presentation to the user
0752      * in the default locale.
0753      * If the display name is not available for the locale,
0754      * then this method returns a string in the localized GMT offset format
0755      * such as <code>GMT[+-]HH:mm</code>.
0756      * @param inDaylight if true, return the daylight savings name.
0757      * @param style
0758      * @param result the human-readable name of this time zone in the default locale.
0759      * @return       A reference to 'result'.
0760      * @stable ICU 2.0
0761      */
0762     UnicodeString& getDisplayName(UBool inDaylight, EDisplayType style, UnicodeString& result) const;
0763 
0764     /**
0765      * Returns a name of this time zone suitable for presentation to the user
0766      * in the specified locale.
0767      * If the display name is not available for the locale,
0768      * then this method returns a string in the localized GMT offset format
0769      * such as <code>GMT[+-]HH:mm</code>.
0770      * @param inDaylight if true, return the daylight savings name.
0771      * @param style
0772      * @param locale the locale in which to supply the display name.
0773      * @param result the human-readable name of this time zone in the given locale
0774      *               or in the default locale if the given locale is not recognized.
0775      * @return       A reference to 'result'.
0776      * @stable ICU 2.0
0777      */
0778     UnicodeString& getDisplayName(UBool inDaylight, EDisplayType style, const Locale& locale, UnicodeString& result) const;
0779     
0780     /**
0781      * Queries if this time zone uses daylight savings time.
0782      * @return true if this time zone uses daylight savings time,
0783      * false, otherwise.
0784      * <p><strong>Note:</strong>The default implementation of
0785      * ICU TimeZone uses the tz database, which supports historic
0786      * rule changes, for system time zones. With the implementation,
0787      * there are time zones that used daylight savings time in the
0788      * past, but no longer used currently. For example, Asia/Tokyo has
0789      * never used daylight savings time since 1951. Most clients would
0790      * expect that this method to return <code>false</code> for such case.
0791      * The default implementation of this method returns <code>true</code>
0792      * when the time zone uses daylight savings time in the current
0793      * (Gregorian) calendar year.
0794      * <p>In Java 7, <code>observesDaylightTime()</code> was added in
0795      * addition to <code>useDaylightTime()</code>. In Java, <code>useDaylightTime()</code>
0796      * only checks if daylight saving time is observed by the last known
0797      * rule. This specification might not be what most users would expect
0798      * if daylight saving time is currently observed, but not scheduled
0799      * in future. In this case, Java's <code>userDaylightTime()</code> returns
0800      * <code>false</code>. To resolve the issue, Java 7 added <code>observesDaylightTime()</code>,
0801      * which takes the current rule into account. The method <code>observesDaylightTime()</code>
0802      * was added in ICU4J for supporting API signature compatibility with JDK.
0803      * In general, ICU4C also provides JDK compatible methods, but the current
0804      * implementation <code>userDaylightTime()</code> serves the purpose
0805      * (takes the current rule into account), <code>observesDaylightTime()</code>
0806      * is not added in ICU4C. In addition to <code>useDaylightTime()</code>, ICU4C
0807      * <code>BasicTimeZone</code> class (Note that <code>TimeZone::createTimeZone(const UnicodeString &ID)</code>
0808      * always returns a <code>BasicTimeZone</code>) provides a series of methods allowing
0809      * historic and future time zone rule iteration, so you can check if daylight saving
0810      * time is observed or not within a given period.
0811      * 
0812      * @stable ICU 2.0
0813      */
0814     virtual UBool useDaylightTime() const = 0;
0815 
0816 #ifndef U_FORCE_HIDE_DEPRECATED_API
0817     /**
0818      * Queries if the given date is in daylight savings time in
0819      * this time zone.
0820      * This method is wasteful since it creates a new GregorianCalendar and
0821      * deletes it each time it is called. This is a deprecated method
0822      * and provided only for Java compatibility.
0823      *
0824      * @param date the given UDate.
0825      * @param status Output param filled in with success/error code.
0826      * @return true if the given date is in daylight savings time,
0827      * false, otherwise.
0828      * @deprecated ICU 2.4. Use Calendar::inDaylightTime() instead.
0829      */
0830     virtual UBool inDaylightTime(UDate date, UErrorCode& status) const = 0;
0831 #endif  // U_FORCE_HIDE_DEPRECATED_API
0832 
0833     /**
0834      * Returns true if this zone has the same rule and offset as another zone.
0835      * That is, if this zone differs only in ID, if at all.
0836      * @param other the <code>TimeZone</code> object to be compared with
0837      * @return true if the given zone is the same as this one,
0838      * with the possible exception of the ID
0839      * @stable ICU 2.0
0840      */
0841     virtual UBool hasSameRules(const TimeZone& other) const;
0842 
0843     /**
0844      * Clones TimeZone objects polymorphically. Clients are responsible for deleting
0845      * the TimeZone object cloned.
0846      *
0847      * @return   A new copy of this TimeZone object.
0848      * @stable ICU 2.0
0849      */
0850     virtual TimeZone* clone() const = 0;
0851 
0852     /**
0853      * Return the class ID for this class.  This is useful only for
0854      * comparing to a return value from getDynamicClassID().
0855      * @return The class ID for all objects of this class.
0856      * @stable ICU 2.0
0857      */
0858     static UClassID U_EXPORT2 getStaticClassID();
0859 
0860     /**
0861      * Returns a unique class ID POLYMORPHICALLY. This method is to
0862      * implement a simple version of RTTI, since not all C++ compilers support genuine
0863      * RTTI. Polymorphic operator==() and clone() methods call this method.
0864      * <P>
0865      * Concrete subclasses of TimeZone must use the UOBJECT_DEFINE_RTTI_IMPLEMENTATION
0866      *  macro from uobject.h in their implementation to provide correct RTTI information.
0867      * @return   The class ID for this object. All objects of a given class have the
0868      *           same class ID. Objects of other classes have different class IDs.
0869      * @stable ICU 2.0
0870      */
0871     virtual UClassID getDynamicClassID() const override = 0;
0872 
0873     /**
0874      * Returns the amount of time to be added to local standard time
0875      * to get local wall clock time.
0876      * <p>
0877      * The default implementation always returns 3600000 milliseconds
0878      * (i.e., one hour) if this time zone observes Daylight Saving
0879      * Time. Otherwise, 0 (zero) is returned.
0880      * <p>
0881      * If an underlying TimeZone implementation subclass supports
0882      * historical Daylight Saving Time changes, this method returns
0883      * the known latest daylight saving value.
0884      *
0885      * @return the amount of saving time in milliseconds
0886      * @stable ICU 3.6
0887      */
0888     virtual int32_t getDSTSavings() const;
0889 
0890     /**
0891      * Gets the region code associated with the given
0892      * system time zone ID. The region code is either ISO 3166
0893      * 2-letter country code or UN M.49 3-digit area code.
0894      * When the time zone is not associated with a specific location,
0895      * for example - "Etc/UTC", "EST5EDT", then this method returns
0896      * "001" (UN M.49 area code for World).
0897      * 
0898      * @param id            The system time zone ID.
0899      * @param region        Output buffer for receiving the region code.
0900      * @param capacity      The size of the output buffer.
0901      * @param status        Receives the status.  When the given time zone ID
0902      *                      is not a known system time zone ID,
0903      *                      U_ILLEGAL_ARGUMENT_ERROR is set.
0904      * @return The length of the output region code.
0905      * @stable ICU 4.8 
0906      */ 
0907     static int32_t U_EXPORT2 getRegion(const UnicodeString& id, 
0908         char *region, int32_t capacity, UErrorCode& status); 
0909 
0910 protected:
0911 
0912     /**
0913      * Default constructor.  ID is initialized to the empty string.
0914      * @stable ICU 2.0
0915      */
0916     TimeZone();
0917 
0918     /**
0919      * Construct a TimeZone with a given ID.
0920      * @param id a system time zone ID
0921      * @stable ICU 2.0
0922      */
0923     TimeZone(const UnicodeString &id);
0924 
0925     /**
0926      * Copy constructor.
0927      * @param source the object to be copied.
0928      * @stable ICU 2.0
0929      */
0930     TimeZone(const TimeZone& source);
0931 
0932     /**
0933      * Default assignment operator.
0934      * @param right the object to be copied.
0935      * @stable ICU 2.0
0936      */
0937     TimeZone& operator=(const TimeZone& right);
0938 
0939 #ifndef U_HIDE_INTERNAL_API
0940     /**
0941      * Utility function. For internally loading rule data.
0942      * @param top Top resource bundle for tz data
0943      * @param ruleid ID of rule to load
0944      * @param oldbundle Old bundle to reuse or nullptr
0945      * @param status Status parameter
0946      * @return either a new bundle or *oldbundle
0947      * @internal
0948      */
0949     static UResourceBundle* loadRule(const UResourceBundle* top, const UnicodeString& ruleid, UResourceBundle* oldbundle, UErrorCode&status);
0950 #endif  /* U_HIDE_INTERNAL_API */
0951 
0952 private:
0953     friend class ZoneMeta;
0954 
0955 
0956     static TimeZone*        createCustomTimeZone(const UnicodeString&); // Creates a time zone based on the string.
0957 
0958     /**
0959      * Finds the given ID in the Olson tzdata. If the given ID is found in the tzdata,
0960      * returns the pointer to the ID resource. This method is exposed through ZoneMeta class
0961      * for ICU internal implementation and useful for building hashtable using a time zone
0962      * ID as a key.
0963      * @param id zone id string
0964      * @return the pointer of the ID resource, or nullptr.
0965      */
0966     static const char16_t* findID(const UnicodeString& id);
0967 
0968     /**
0969      * Resolve a link in Olson tzdata.  When the given id is known and it's not a link,
0970      * the id itself is returned.  When the given id is known and it is a link, then
0971      * dereferenced zone id is returned.  When the given id is unknown, then it returns
0972      * nullptr.
0973      * @param id zone id string
0974      * @return the dereferenced zone or nullptr
0975      */
0976     static const char16_t* dereferOlsonLink(const UnicodeString& id);
0977 
0978     /**
0979      * Returns the region code associated with the given zone,
0980      * or nullptr if the zone is not known.
0981      * @param id zone id string
0982      * @return the region associated with the given zone
0983      */
0984     static const char16_t* getRegion(const UnicodeString& id);
0985 
0986   public:
0987 #ifndef U_HIDE_INTERNAL_API
0988     /**
0989      * Returns the region code associated with the given zone,
0990      * or nullptr if the zone is not known.
0991      * @param id zone id string
0992      * @param status Status parameter
0993      * @return the region associated with the given zone
0994      * @internal
0995      */
0996     static const char16_t* getRegion(const UnicodeString& id, UErrorCode& status);
0997 #endif  /* U_HIDE_INTERNAL_API */
0998 
0999   private:
1000     /**
1001      * Parses the given custom time zone identifier
1002      * @param id id A string of the form GMT[+-]hh:mm, GMT[+-]hhmm, or
1003      * GMT[+-]hh.
1004      * @param sign Receives parsed sign, 1 for positive, -1 for negative.
1005      * @param hour Receives parsed hour field
1006      * @param minute Receives parsed minute field
1007      * @param second Receives parsed second field
1008      * @return Returns true when the given custom id is valid.
1009      */
1010     static UBool parseCustomID(const UnicodeString& id, int32_t& sign, int32_t& hour,
1011         int32_t& minute, int32_t& second);
1012 
1013     /**
1014      * Parse a custom time zone identifier and return the normalized
1015      * custom time zone identifier for the given custom id string.
1016      * @param id a string of the form GMT[+-]hh:mm, GMT[+-]hhmm, or
1017      * GMT[+-]hh.
1018      * @param normalized Receives the normalized custom ID
1019      * @param status Receives the status.  When the input ID string is invalid,
1020      * U_ILLEGAL_ARGUMENT_ERROR is set.
1021      * @return The normalized custom id string.
1022     */
1023     static UnicodeString& getCustomID(const UnicodeString& id, UnicodeString& normalized,
1024         UErrorCode& status);
1025 
1026     /**
1027      * Returns the normalized custom time zone ID for the given offset fields.
1028      * @param hour offset hours
1029      * @param min offset minutes
1030      * @param sec offset seconds
1031      * @param negative sign of the offset, true for negative offset.
1032      * @param id Receives the format result (normalized custom ID)
1033      * @return The reference to id
1034      */
1035     static UnicodeString& formatCustomID(int32_t hour, int32_t min, int32_t sec,
1036         UBool negative, UnicodeString& id);
1037 
1038     UnicodeString           fID;    // this time zone's ID
1039 
1040     friend class TZEnumeration;
1041 };
1042 
1043 
1044 // -------------------------------------
1045 
1046 inline UnicodeString&
1047 TimeZone::getID(UnicodeString& ID) const
1048 {
1049     ID = fID;
1050     return ID;
1051 }
1052 
1053 // -------------------------------------
1054 
1055 inline void
1056 TimeZone::setID(const UnicodeString& ID)
1057 {
1058     fID = ID;
1059 }
1060 U_NAMESPACE_END
1061 
1062 #endif /* #if !UCONFIG_NO_FORMATTING */
1063 
1064 #endif /* U_SHOW_CPLUSPLUS_API */
1065 
1066 #endif //_TIMEZONE
1067 //eof