1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others.
2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html
3*0e209d39SAndroid Build Coastguard Worker /*************************************************************************
4*0e209d39SAndroid Build Coastguard Worker * Copyright (c) 1997-2016, International Business Machines Corporation
5*0e209d39SAndroid Build Coastguard Worker * and others. All Rights Reserved.
6*0e209d39SAndroid Build Coastguard Worker **************************************************************************
7*0e209d39SAndroid Build Coastguard Worker *
8*0e209d39SAndroid Build Coastguard Worker * File TIMEZONE.H
9*0e209d39SAndroid Build Coastguard Worker *
10*0e209d39SAndroid Build Coastguard Worker * Modification History:
11*0e209d39SAndroid Build Coastguard Worker *
12*0e209d39SAndroid Build Coastguard Worker * Date Name Description
13*0e209d39SAndroid Build Coastguard Worker * 04/21/97 aliu Overhauled header.
14*0e209d39SAndroid Build Coastguard Worker * 07/09/97 helena Changed createInstance to createDefault.
15*0e209d39SAndroid Build Coastguard Worker * 08/06/97 aliu Removed dependency on internal header for Hashtable.
16*0e209d39SAndroid Build Coastguard Worker * 08/10/98 stephen Changed getDisplayName() API conventions to match
17*0e209d39SAndroid Build Coastguard Worker * 08/19/98 stephen Changed createTimeZone() to never return 0
18*0e209d39SAndroid Build Coastguard Worker * 09/02/98 stephen Sync to JDK 1.2 8/31
19*0e209d39SAndroid Build Coastguard Worker * - Added getOffset(... monthlen ...)
20*0e209d39SAndroid Build Coastguard Worker * - Added hasSameRules()
21*0e209d39SAndroid Build Coastguard Worker * 09/15/98 stephen Added getStaticClassID
22*0e209d39SAndroid Build Coastguard Worker * 12/03/99 aliu Moved data out of static table into icudata.dll.
23*0e209d39SAndroid Build Coastguard Worker * Hashtable replaced by new static data structures.
24*0e209d39SAndroid Build Coastguard Worker * 12/14/99 aliu Made GMT public.
25*0e209d39SAndroid Build Coastguard Worker * 08/15/01 grhoten Made GMT private and added the getGMT() function
26*0e209d39SAndroid Build Coastguard Worker **************************************************************************
27*0e209d39SAndroid Build Coastguard Worker */
28*0e209d39SAndroid Build Coastguard Worker
29*0e209d39SAndroid Build Coastguard Worker #ifndef TIMEZONE_H
30*0e209d39SAndroid Build Coastguard Worker #define TIMEZONE_H
31*0e209d39SAndroid Build Coastguard Worker
32*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h"
33*0e209d39SAndroid Build Coastguard Worker
34*0e209d39SAndroid Build Coastguard Worker #if U_SHOW_CPLUSPLUS_API
35*0e209d39SAndroid Build Coastguard Worker
36*0e209d39SAndroid Build Coastguard Worker /**
37*0e209d39SAndroid Build Coastguard Worker * \file
38*0e209d39SAndroid Build Coastguard Worker * \brief C++ API: TimeZone object
39*0e209d39SAndroid Build Coastguard Worker */
40*0e209d39SAndroid Build Coastguard Worker
41*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_FORMATTING
42*0e209d39SAndroid Build Coastguard Worker
43*0e209d39SAndroid Build Coastguard Worker #include "unicode/uobject.h"
44*0e209d39SAndroid Build Coastguard Worker #include "unicode/unistr.h"
45*0e209d39SAndroid Build Coastguard Worker #include "unicode/ures.h"
46*0e209d39SAndroid Build Coastguard Worker #include "unicode/ucal.h"
47*0e209d39SAndroid Build Coastguard Worker
48*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN
49*0e209d39SAndroid Build Coastguard Worker
50*0e209d39SAndroid Build Coastguard Worker class StringEnumeration;
51*0e209d39SAndroid Build Coastguard Worker
52*0e209d39SAndroid Build Coastguard Worker /**
53*0e209d39SAndroid Build Coastguard Worker *
54*0e209d39SAndroid Build Coastguard Worker * <code>TimeZone</code> represents a time zone offset, and also figures out daylight
55*0e209d39SAndroid Build Coastguard Worker * savings.
56*0e209d39SAndroid Build Coastguard Worker *
57*0e209d39SAndroid Build Coastguard Worker * <p>
58*0e209d39SAndroid Build Coastguard Worker * Typically, you get a <code>TimeZone</code> using <code>createDefault</code>
59*0e209d39SAndroid Build Coastguard Worker * which creates a <code>TimeZone</code> based on the time zone where the program
60*0e209d39SAndroid Build Coastguard Worker * is running. For example, for a program running in Japan, <code>createDefault</code>
61*0e209d39SAndroid Build Coastguard Worker * creates a <code>TimeZone</code> object based on Japanese Standard Time.
62*0e209d39SAndroid Build Coastguard Worker *
63*0e209d39SAndroid Build Coastguard Worker * <p>
64*0e209d39SAndroid Build Coastguard Worker * You can also get a <code>TimeZone</code> using <code>createTimeZone</code> along
65*0e209d39SAndroid Build Coastguard Worker * with a time zone ID. For instance, the time zone ID for the US Pacific
66*0e209d39SAndroid Build Coastguard Worker * Time zone is "America/Los_Angeles". So, you can get a Pacific Time <code>TimeZone</code> object
67*0e209d39SAndroid Build Coastguard Worker * with:
68*0e209d39SAndroid Build Coastguard Worker * \htmlonly<blockquote>\endhtmlonly
69*0e209d39SAndroid Build Coastguard Worker * <pre>
70*0e209d39SAndroid Build Coastguard Worker * TimeZone *tz = TimeZone::createTimeZone("America/Los_Angeles");
71*0e209d39SAndroid Build Coastguard Worker * </pre>
72*0e209d39SAndroid Build Coastguard Worker * \htmlonly</blockquote>\endhtmlonly
73*0e209d39SAndroid Build Coastguard Worker * You can use the <code>createEnumeration</code> method to iterate through
74*0e209d39SAndroid Build Coastguard Worker * all the supported time zone IDs, or the <code>getCanonicalID</code> method to check
75*0e209d39SAndroid Build Coastguard Worker * if a time zone ID is supported or not. You can then choose a
76*0e209d39SAndroid Build Coastguard Worker * supported ID to get a <code>TimeZone</code>.
77*0e209d39SAndroid Build Coastguard Worker * If the time zone you want is not represented by one of the
78*0e209d39SAndroid Build Coastguard Worker * supported IDs, then you can create a custom time zone ID with
79*0e209d39SAndroid Build Coastguard Worker * the following syntax:
80*0e209d39SAndroid Build Coastguard Worker *
81*0e209d39SAndroid Build Coastguard Worker * \htmlonly<blockquote>\endhtmlonly
82*0e209d39SAndroid Build Coastguard Worker * <pre>
83*0e209d39SAndroid Build Coastguard Worker * GMT[+|-]hh[[:]mm]
84*0e209d39SAndroid Build Coastguard Worker * </pre>
85*0e209d39SAndroid Build Coastguard Worker * \htmlonly</blockquote>\endhtmlonly
86*0e209d39SAndroid Build Coastguard Worker *
87*0e209d39SAndroid Build Coastguard Worker * For example, you might specify GMT+14:00 as a custom
88*0e209d39SAndroid Build Coastguard Worker * time zone ID. The <code>TimeZone</code> that is returned
89*0e209d39SAndroid Build Coastguard Worker * when you specify a custom time zone ID uses the specified
90*0e209d39SAndroid Build Coastguard Worker * offset from GMT(=UTC) and does not observe daylight saving
91*0e209d39SAndroid Build Coastguard Worker * time. For example, you might specify GMT+14:00 as a custom
92*0e209d39SAndroid Build Coastguard Worker * time zone ID to create a TimeZone representing 14 hours ahead
93*0e209d39SAndroid Build Coastguard Worker * of GMT (with no daylight saving time). In addition,
94*0e209d39SAndroid Build Coastguard Worker * <code>getCanonicalID</code> can also be used to
95*0e209d39SAndroid Build Coastguard Worker * normalize a custom time zone ID.
96*0e209d39SAndroid Build Coastguard Worker *
97*0e209d39SAndroid Build Coastguard Worker * TimeZone is an abstract class representing a time zone. A TimeZone is needed for
98*0e209d39SAndroid Build Coastguard Worker * Calendar to produce local time for a particular time zone. A TimeZone comprises
99*0e209d39SAndroid Build Coastguard Worker * three basic pieces of information:
100*0e209d39SAndroid Build Coastguard Worker * <ul>
101*0e209d39SAndroid Build Coastguard Worker * <li>A time zone offset; that, is the number of milliseconds to add or subtract
102*0e209d39SAndroid Build Coastguard Worker * from a time expressed in terms of GMT to convert it to the same time in that
103*0e209d39SAndroid Build Coastguard Worker * time zone (without taking daylight savings time into account).</li>
104*0e209d39SAndroid Build Coastguard Worker * <li>Logic necessary to take daylight savings time into account if daylight savings
105*0e209d39SAndroid Build Coastguard Worker * time is observed in that time zone (e.g., the days and hours on which daylight
106*0e209d39SAndroid Build Coastguard Worker * savings time begins and ends).</li>
107*0e209d39SAndroid Build Coastguard Worker * <li>An ID. This is a text string that uniquely identifies the time zone.</li>
108*0e209d39SAndroid Build Coastguard Worker * </ul>
109*0e209d39SAndroid Build Coastguard Worker *
110*0e209d39SAndroid Build Coastguard Worker * (Only the ID is actually implemented in TimeZone; subclasses of TimeZone may handle
111*0e209d39SAndroid Build Coastguard Worker * daylight savings time and GMT offset in different ways. Currently we have the following
112*0e209d39SAndroid Build Coastguard Worker * TimeZone subclasses: RuleBasedTimeZone, SimpleTimeZone, and VTimeZone.)
113*0e209d39SAndroid Build Coastguard Worker * <P>
114*0e209d39SAndroid Build Coastguard Worker * The TimeZone class contains a static list containing a TimeZone object for every
115*0e209d39SAndroid Build Coastguard Worker * combination of GMT offset and daylight-savings time rules currently in use in the
116*0e209d39SAndroid Build Coastguard Worker * world, each with a unique ID. Each ID consists of a region (usually a continent or
117*0e209d39SAndroid Build Coastguard Worker * ocean) and a city in that region, separated by a slash, (for example, US Pacific
118*0e209d39SAndroid Build Coastguard Worker * Time is "America/Los_Angeles.") Because older versions of this class used
119*0e209d39SAndroid Build Coastguard Worker * three- or four-letter abbreviations instead, there is also a table that maps the older
120*0e209d39SAndroid Build Coastguard Worker * abbreviations to the newer ones (for example, "PST" maps to "America/Los_Angeles").
121*0e209d39SAndroid Build Coastguard Worker * Anywhere the API requires an ID, you can use either form.
122*0e209d39SAndroid Build Coastguard Worker * <P>
123*0e209d39SAndroid Build Coastguard Worker * To create a new TimeZone, you call the factory function TimeZone::createTimeZone()
124*0e209d39SAndroid Build Coastguard Worker * and pass it a time zone ID. You can use the createEnumeration() function to
125*0e209d39SAndroid Build Coastguard Worker * obtain a list of all the time zone IDs recognized by createTimeZone().
126*0e209d39SAndroid Build Coastguard Worker * <P>
127*0e209d39SAndroid Build Coastguard Worker * You can also use TimeZone::createDefault() to create a TimeZone. This function uses
128*0e209d39SAndroid Build Coastguard Worker * platform-specific APIs to produce a TimeZone for the time zone corresponding to
129*0e209d39SAndroid Build Coastguard Worker * the client's computer's physical location. For example, if you're in Japan (assuming
130*0e209d39SAndroid Build Coastguard Worker * your machine is set up correctly), TimeZone::createDefault() will return a TimeZone
131*0e209d39SAndroid Build Coastguard Worker * for Japanese Standard Time ("Asia/Tokyo").
132*0e209d39SAndroid Build Coastguard Worker */
133*0e209d39SAndroid Build Coastguard Worker class U_I18N_API TimeZone : public UObject {
134*0e209d39SAndroid Build Coastguard Worker public:
135*0e209d39SAndroid Build Coastguard Worker /**
136*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
137*0e209d39SAndroid Build Coastguard Worker */
138*0e209d39SAndroid Build Coastguard Worker virtual ~TimeZone();
139*0e209d39SAndroid Build Coastguard Worker
140*0e209d39SAndroid Build Coastguard Worker /**
141*0e209d39SAndroid Build Coastguard Worker * Returns the "unknown" time zone.
142*0e209d39SAndroid Build Coastguard Worker * It behaves like the GMT/UTC time zone but has the
143*0e209d39SAndroid Build Coastguard Worker * <code>UCAL_UNKNOWN_ZONE_ID</code> = "Etc/Unknown".
144*0e209d39SAndroid Build Coastguard Worker * createTimeZone() returns a mutable clone of this time zone if the input ID is not recognized.
145*0e209d39SAndroid Build Coastguard Worker *
146*0e209d39SAndroid Build Coastguard Worker * @return the "unknown" time zone.
147*0e209d39SAndroid Build Coastguard Worker * @see UCAL_UNKNOWN_ZONE_ID
148*0e209d39SAndroid Build Coastguard Worker * @see createTimeZone
149*0e209d39SAndroid Build Coastguard Worker * @see getGMT
150*0e209d39SAndroid Build Coastguard Worker * @stable ICU 49
151*0e209d39SAndroid Build Coastguard Worker */
152*0e209d39SAndroid Build Coastguard Worker static const TimeZone& U_EXPORT2 getUnknown();
153*0e209d39SAndroid Build Coastguard Worker
154*0e209d39SAndroid Build Coastguard Worker /**
155*0e209d39SAndroid Build Coastguard Worker * The GMT (=UTC) time zone has a raw offset of zero and does not use daylight
156*0e209d39SAndroid Build Coastguard Worker * savings time. This is a commonly used time zone.
157*0e209d39SAndroid Build Coastguard Worker *
158*0e209d39SAndroid Build Coastguard Worker * <p>Note: For backward compatibility reason, the ID used by the time
159*0e209d39SAndroid Build Coastguard Worker * zone returned by this method is "GMT", although the ICU's canonical
160*0e209d39SAndroid Build Coastguard Worker * ID for the GMT time zone is "Etc/GMT".
161*0e209d39SAndroid Build Coastguard Worker *
162*0e209d39SAndroid Build Coastguard Worker * @return the GMT/UTC time zone.
163*0e209d39SAndroid Build Coastguard Worker * @see getUnknown
164*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
165*0e209d39SAndroid Build Coastguard Worker */
166*0e209d39SAndroid Build Coastguard Worker static const TimeZone* U_EXPORT2 getGMT();
167*0e209d39SAndroid Build Coastguard Worker
168*0e209d39SAndroid Build Coastguard Worker /**
169*0e209d39SAndroid Build Coastguard Worker * Creates a <code>TimeZone</code> for the given ID.
170*0e209d39SAndroid Build Coastguard Worker * @param ID the ID for a <code>TimeZone</code>, such as "America/Los_Angeles",
171*0e209d39SAndroid Build Coastguard Worker * or a custom ID such as "GMT-8:00".
172*0e209d39SAndroid Build Coastguard Worker * @return the specified <code>TimeZone</code>, or a mutable clone of getUnknown()
173*0e209d39SAndroid Build Coastguard Worker * if the given ID cannot be understood or if the given ID is "Etc/Unknown".
174*0e209d39SAndroid Build Coastguard Worker * The return result is guaranteed to be non-nullptr.
175*0e209d39SAndroid Build Coastguard Worker * If you require that the specific zone asked for be returned,
176*0e209d39SAndroid Build Coastguard Worker * compare the result with getUnknown() or check the ID of the return result.
177*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
178*0e209d39SAndroid Build Coastguard Worker */
179*0e209d39SAndroid Build Coastguard Worker static TimeZone* U_EXPORT2 createTimeZone(const UnicodeString& ID);
180*0e209d39SAndroid Build Coastguard Worker
181*0e209d39SAndroid Build Coastguard Worker /**
182*0e209d39SAndroid Build Coastguard Worker * Returns an enumeration over system time zone IDs with the given
183*0e209d39SAndroid Build Coastguard Worker * filter conditions.
184*0e209d39SAndroid Build Coastguard Worker * @param zoneType The system time zone type.
185*0e209d39SAndroid Build Coastguard Worker * @param region The ISO 3166 two-letter country code or UN M.49
186*0e209d39SAndroid Build Coastguard Worker * three-digit area code. When nullptr, no filtering
187*0e209d39SAndroid Build Coastguard Worker * done by region.
188*0e209d39SAndroid Build Coastguard Worker * @param rawOffset An offset from GMT in milliseconds, ignoring
189*0e209d39SAndroid Build Coastguard Worker * the effect of daylight savings time, if any.
190*0e209d39SAndroid Build Coastguard Worker * When nullptr, no filtering done by zone offset.
191*0e209d39SAndroid Build Coastguard Worker * @param ec Output param to filled in with a success or
192*0e209d39SAndroid Build Coastguard Worker * an error.
193*0e209d39SAndroid Build Coastguard Worker * @return an enumeration object, owned by the caller.
194*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.8
195*0e209d39SAndroid Build Coastguard Worker */
196*0e209d39SAndroid Build Coastguard Worker static StringEnumeration* U_EXPORT2 createTimeZoneIDEnumeration(
197*0e209d39SAndroid Build Coastguard Worker USystemTimeZoneType zoneType,
198*0e209d39SAndroid Build Coastguard Worker const char* region,
199*0e209d39SAndroid Build Coastguard Worker const int32_t* rawOffset,
200*0e209d39SAndroid Build Coastguard Worker UErrorCode& ec);
201*0e209d39SAndroid Build Coastguard Worker
202*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_DEPRECATED_API
203*0e209d39SAndroid Build Coastguard Worker /**
204*0e209d39SAndroid Build Coastguard Worker * Returns an enumeration over all recognized time zone IDs. (i.e.,
205*0e209d39SAndroid Build Coastguard Worker * all strings that createTimeZone() accepts)
206*0e209d39SAndroid Build Coastguard Worker *
207*0e209d39SAndroid Build Coastguard Worker * @return an enumeration object, owned by the caller.
208*0e209d39SAndroid Build Coastguard Worker * @deprecated ICU 70 Use createEnumeration(UErrorCode&) instead.
209*0e209d39SAndroid Build Coastguard Worker */
210*0e209d39SAndroid Build Coastguard Worker static StringEnumeration* U_EXPORT2 createEnumeration();
211*0e209d39SAndroid Build Coastguard Worker #endif // U_HIDE_DEPRECATED_API
212*0e209d39SAndroid Build Coastguard Worker
213*0e209d39SAndroid Build Coastguard Worker /**
214*0e209d39SAndroid Build Coastguard Worker * Returns an enumeration over all recognized time zone IDs. (i.e.,
215*0e209d39SAndroid Build Coastguard Worker * all strings that createTimeZone() accepts)
216*0e209d39SAndroid Build Coastguard Worker *
217*0e209d39SAndroid Build Coastguard Worker * @param status Receives the status.
218*0e209d39SAndroid Build Coastguard Worker * @return an enumeration object, owned by the caller.
219*0e209d39SAndroid Build Coastguard Worker * @stable ICU 70
220*0e209d39SAndroid Build Coastguard Worker */
221*0e209d39SAndroid Build Coastguard Worker static StringEnumeration* U_EXPORT2 createEnumeration(UErrorCode& status);
222*0e209d39SAndroid Build Coastguard Worker
223*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_DEPRECATED_API
224*0e209d39SAndroid Build Coastguard Worker /**
225*0e209d39SAndroid Build Coastguard Worker * Returns an enumeration over time zone IDs with a given raw
226*0e209d39SAndroid Build Coastguard Worker * offset from GMT. There may be several times zones with the
227*0e209d39SAndroid Build Coastguard Worker * same GMT offset that differ in the way they handle daylight
228*0e209d39SAndroid Build Coastguard Worker * savings time. For example, the state of Arizona doesn't
229*0e209d39SAndroid Build Coastguard Worker * observe daylight savings time. If you ask for the time zone
230*0e209d39SAndroid Build Coastguard Worker * IDs corresponding to GMT-7:00, you'll get back an enumeration
231*0e209d39SAndroid Build Coastguard Worker * over two time zone IDs: "America/Denver," which corresponds to
232*0e209d39SAndroid Build Coastguard Worker * Mountain Standard Time in the winter and Mountain Daylight Time
233*0e209d39SAndroid Build Coastguard Worker * in the summer, and "America/Phoenix", which corresponds to
234*0e209d39SAndroid Build Coastguard Worker * Mountain Standard Time year-round, even in the summer.
235*0e209d39SAndroid Build Coastguard Worker *
236*0e209d39SAndroid Build Coastguard Worker * @param rawOffset an offset from GMT in milliseconds, ignoring
237*0e209d39SAndroid Build Coastguard Worker * the effect of daylight savings time, if any
238*0e209d39SAndroid Build Coastguard Worker * @return an enumeration object, owned by the caller
239*0e209d39SAndroid Build Coastguard Worker * @deprecated ICU 70 Use createEnumerationForRawOffset(int32_t,UErrorCode&) instead.
240*0e209d39SAndroid Build Coastguard Worker */
241*0e209d39SAndroid Build Coastguard Worker static StringEnumeration* U_EXPORT2 createEnumeration(int32_t rawOffset);
242*0e209d39SAndroid Build Coastguard Worker #endif // U_HIDE_DEPRECATED_API
243*0e209d39SAndroid Build Coastguard Worker
244*0e209d39SAndroid Build Coastguard Worker /**
245*0e209d39SAndroid Build Coastguard Worker * Returns an enumeration over time zone IDs with a given raw
246*0e209d39SAndroid Build Coastguard Worker * offset from GMT. There may be several times zones with the
247*0e209d39SAndroid Build Coastguard Worker * same GMT offset that differ in the way they handle daylight
248*0e209d39SAndroid Build Coastguard Worker * savings time. For example, the state of Arizona doesn't
249*0e209d39SAndroid Build Coastguard Worker * observe daylight savings time. If you ask for the time zone
250*0e209d39SAndroid Build Coastguard Worker * IDs corresponding to GMT-7:00, you'll get back an enumeration
251*0e209d39SAndroid Build Coastguard Worker * over two time zone IDs: "America/Denver," which corresponds to
252*0e209d39SAndroid Build Coastguard Worker * Mountain Standard Time in the winter and Mountain Daylight Time
253*0e209d39SAndroid Build Coastguard Worker * in the summer, and "America/Phoenix", which corresponds to
254*0e209d39SAndroid Build Coastguard Worker * Mountain Standard Time year-round, even in the summer.
255*0e209d39SAndroid Build Coastguard Worker *
256*0e209d39SAndroid Build Coastguard Worker * @param rawOffset an offset from GMT in milliseconds, ignoring
257*0e209d39SAndroid Build Coastguard Worker * the effect of daylight savings time, if any
258*0e209d39SAndroid Build Coastguard Worker * @param status Receives the status.
259*0e209d39SAndroid Build Coastguard Worker * @return an enumeration object, owned by the caller
260*0e209d39SAndroid Build Coastguard Worker * @stable ICU 70
261*0e209d39SAndroid Build Coastguard Worker */
262*0e209d39SAndroid Build Coastguard Worker static StringEnumeration* U_EXPORT2 createEnumerationForRawOffset(int32_t rawOffset, UErrorCode& status);
263*0e209d39SAndroid Build Coastguard Worker
264*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_DEPRECATED_API
265*0e209d39SAndroid Build Coastguard Worker /**
266*0e209d39SAndroid Build Coastguard Worker * Returns an enumeration over time zone IDs associated with the
267*0e209d39SAndroid Build Coastguard Worker * given region. Some zones are affiliated with no region
268*0e209d39SAndroid Build Coastguard Worker * (e.g., "UTC"); these may also be retrieved, as a group.
269*0e209d39SAndroid Build Coastguard Worker *
270*0e209d39SAndroid Build Coastguard Worker * @param region The ISO 3166 two-letter country code, or nullptr to
271*0e209d39SAndroid Build Coastguard Worker * retrieve zones not affiliated with any region.
272*0e209d39SAndroid Build Coastguard Worker * @return an enumeration object, owned by the caller
273*0e209d39SAndroid Build Coastguard Worker * @deprecated ICU 70 Use createEnumerationForRegion(const char*,UErrorCode&) instead.
274*0e209d39SAndroid Build Coastguard Worker */
275*0e209d39SAndroid Build Coastguard Worker static StringEnumeration* U_EXPORT2 createEnumeration(const char* region);
276*0e209d39SAndroid Build Coastguard Worker #endif // U_HIDE_DEPRECATED_API
277*0e209d39SAndroid Build Coastguard Worker
278*0e209d39SAndroid Build Coastguard Worker /**
279*0e209d39SAndroid Build Coastguard Worker * Returns an enumeration over time zone IDs associated with the
280*0e209d39SAndroid Build Coastguard Worker * given region. Some zones are affiliated with no region
281*0e209d39SAndroid Build Coastguard Worker * (e.g., "UTC"); these may also be retrieved, as a group.
282*0e209d39SAndroid Build Coastguard Worker *
283*0e209d39SAndroid Build Coastguard Worker * @param region The ISO 3166 two-letter country code, or nullptr to
284*0e209d39SAndroid Build Coastguard Worker * retrieve zones not affiliated with any region.
285*0e209d39SAndroid Build Coastguard Worker * @param status Receives the status.
286*0e209d39SAndroid Build Coastguard Worker * @return an enumeration object, owned by the caller
287*0e209d39SAndroid Build Coastguard Worker * @stable ICU 70
288*0e209d39SAndroid Build Coastguard Worker */
289*0e209d39SAndroid Build Coastguard Worker static StringEnumeration* U_EXPORT2 createEnumerationForRegion(const char* region, UErrorCode& status);
290*0e209d39SAndroid Build Coastguard Worker
291*0e209d39SAndroid Build Coastguard Worker /**
292*0e209d39SAndroid Build Coastguard Worker * Returns the number of IDs in the equivalency group that
293*0e209d39SAndroid Build Coastguard Worker * includes the given ID. An equivalency group contains zones
294*0e209d39SAndroid Build Coastguard Worker * that have the same GMT offset and rules.
295*0e209d39SAndroid Build Coastguard Worker *
296*0e209d39SAndroid Build Coastguard Worker * <p>The returned count includes the given ID; it is always >= 1.
297*0e209d39SAndroid Build Coastguard Worker * The given ID must be a system time zone. If it is not, returns
298*0e209d39SAndroid Build Coastguard Worker * zero.
299*0e209d39SAndroid Build Coastguard Worker * @param id a system time zone ID
300*0e209d39SAndroid Build Coastguard Worker * @return the number of zones in the equivalency group containing
301*0e209d39SAndroid Build Coastguard Worker * 'id', or zero if 'id' is not a valid system ID
302*0e209d39SAndroid Build Coastguard Worker * @see #getEquivalentID
303*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
304*0e209d39SAndroid Build Coastguard Worker */
305*0e209d39SAndroid Build Coastguard Worker static int32_t U_EXPORT2 countEquivalentIDs(const UnicodeString& id);
306*0e209d39SAndroid Build Coastguard Worker
307*0e209d39SAndroid Build Coastguard Worker /**
308*0e209d39SAndroid Build Coastguard Worker * Returns an ID in the equivalency group that
309*0e209d39SAndroid Build Coastguard Worker * includes the given ID. An equivalency group contains zones
310*0e209d39SAndroid Build Coastguard Worker * that have the same GMT offset and rules.
311*0e209d39SAndroid Build Coastguard Worker *
312*0e209d39SAndroid Build Coastguard Worker * <p>The given index must be in the range 0..n-1, where n is the
313*0e209d39SAndroid Build Coastguard Worker * value returned by <code>countEquivalentIDs(id)</code>. For
314*0e209d39SAndroid Build Coastguard Worker * some value of 'index', the returned value will be equal to the
315*0e209d39SAndroid Build Coastguard Worker * given id. If the given id is not a valid system time zone, or
316*0e209d39SAndroid Build Coastguard Worker * if 'index' is out of range, then returns an empty string.
317*0e209d39SAndroid Build Coastguard Worker * @param id a system time zone ID
318*0e209d39SAndroid Build Coastguard Worker * @param index a value from 0 to n-1, where n is the value
319*0e209d39SAndroid Build Coastguard Worker * returned by <code>countEquivalentIDs(id)</code>
320*0e209d39SAndroid Build Coastguard Worker * @return the ID of the index-th zone in the equivalency group
321*0e209d39SAndroid Build Coastguard Worker * containing 'id', or an empty string if 'id' is not a valid
322*0e209d39SAndroid Build Coastguard Worker * system ID or 'index' is out of range
323*0e209d39SAndroid Build Coastguard Worker * @see #countEquivalentIDs
324*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
325*0e209d39SAndroid Build Coastguard Worker */
326*0e209d39SAndroid Build Coastguard Worker static const UnicodeString U_EXPORT2 getEquivalentID(const UnicodeString& id,
327*0e209d39SAndroid Build Coastguard Worker int32_t index);
328*0e209d39SAndroid Build Coastguard Worker
329*0e209d39SAndroid Build Coastguard Worker /**
330*0e209d39SAndroid Build Coastguard Worker * Creates an instance of TimeZone detected from the current host
331*0e209d39SAndroid Build Coastguard Worker * system configuration. If the host system detection routines fail,
332*0e209d39SAndroid Build Coastguard Worker * or if they specify a TimeZone or TimeZone offset which is not
333*0e209d39SAndroid Build Coastguard Worker * recognized, then the special TimeZone "Etc/Unknown" is returned.
334*0e209d39SAndroid Build Coastguard Worker *
335*0e209d39SAndroid Build Coastguard Worker * Note that ICU4C does not change the default time zone unless
336*0e209d39SAndroid Build Coastguard Worker * `TimeZone::adoptDefault(TimeZone*)` or
337*0e209d39SAndroid Build Coastguard Worker * `TimeZone::setDefault(const TimeZone&)` is explicitly called by a
338*0e209d39SAndroid Build Coastguard Worker * user. This method does not update the current ICU's default,
339*0e209d39SAndroid Build Coastguard Worker * and may return a different TimeZone from the one returned by
340*0e209d39SAndroid Build Coastguard Worker * `TimeZone::createDefault()`.
341*0e209d39SAndroid Build Coastguard Worker *
342*0e209d39SAndroid Build Coastguard Worker * <p>This function is not thread safe.</p>
343*0e209d39SAndroid Build Coastguard Worker *
344*0e209d39SAndroid Build Coastguard Worker * @return A new instance of TimeZone detected from the current host system
345*0e209d39SAndroid Build Coastguard Worker * configuration.
346*0e209d39SAndroid Build Coastguard Worker * @see adoptDefault
347*0e209d39SAndroid Build Coastguard Worker * @see setDefault
348*0e209d39SAndroid Build Coastguard Worker * @see createDefault
349*0e209d39SAndroid Build Coastguard Worker * @see getUnknown
350*0e209d39SAndroid Build Coastguard Worker * @stable ICU 55
351*0e209d39SAndroid Build Coastguard Worker */
352*0e209d39SAndroid Build Coastguard Worker static TimeZone* U_EXPORT2 detectHostTimeZone();
353*0e209d39SAndroid Build Coastguard Worker
354*0e209d39SAndroid Build Coastguard Worker /**
355*0e209d39SAndroid Build Coastguard Worker * Creates a new copy of the default TimeZone for this host. Unless the default time
356*0e209d39SAndroid Build Coastguard Worker * zone has already been set using adoptDefault() or setDefault(), the default is
357*0e209d39SAndroid Build Coastguard Worker * determined by querying the host system configuration. If the host system detection
358*0e209d39SAndroid Build Coastguard Worker * routines fail, or if they specify a TimeZone or TimeZone offset which is not
359*0e209d39SAndroid Build Coastguard Worker * recognized, then the special TimeZone "Etc/Unknown" is instantiated and made the
360*0e209d39SAndroid Build Coastguard Worker * default.
361*0e209d39SAndroid Build Coastguard Worker *
362*0e209d39SAndroid Build Coastguard Worker * @return A default TimeZone. Clients are responsible for deleting the time zone
363*0e209d39SAndroid Build Coastguard Worker * object returned.
364*0e209d39SAndroid Build Coastguard Worker * @see getUnknown
365*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
366*0e209d39SAndroid Build Coastguard Worker */
367*0e209d39SAndroid Build Coastguard Worker static TimeZone* U_EXPORT2 createDefault();
368*0e209d39SAndroid Build Coastguard Worker
369*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_INTERNAL_API
370*0e209d39SAndroid Build Coastguard Worker /**
371*0e209d39SAndroid Build Coastguard Worker * If the locale contains the timezone keyword, creates a copy of that TimeZone.
372*0e209d39SAndroid Build Coastguard Worker * Otherwise, create the default timezone.
373*0e209d39SAndroid Build Coastguard Worker *
374*0e209d39SAndroid Build Coastguard Worker * @param locale a locale which may contains 'timezone' keyword/value.
375*0e209d39SAndroid Build Coastguard Worker * @return A TimeZone. Clients are responsible for deleting the time zone
376*0e209d39SAndroid Build Coastguard Worker * object returned.
377*0e209d39SAndroid Build Coastguard Worker * @internal
378*0e209d39SAndroid Build Coastguard Worker */
379*0e209d39SAndroid Build Coastguard Worker static TimeZone* U_EXPORT2 forLocaleOrDefault(const Locale& locale);
380*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_INTERNAL_API */
381*0e209d39SAndroid Build Coastguard Worker
382*0e209d39SAndroid Build Coastguard Worker /**
383*0e209d39SAndroid Build Coastguard Worker * Sets the default time zone (i.e., what's returned by createDefault()) to be the
384*0e209d39SAndroid Build Coastguard Worker * specified time zone. If nullptr is specified for the time zone, the default time
385*0e209d39SAndroid Build Coastguard Worker * zone is set to the default host time zone. This call adopts the TimeZone object
386*0e209d39SAndroid Build Coastguard Worker * passed in; the client is no longer responsible for deleting it.
387*0e209d39SAndroid Build Coastguard Worker *
388*0e209d39SAndroid Build Coastguard Worker * @param zone A pointer to the new TimeZone object to use as the default.
389*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
390*0e209d39SAndroid Build Coastguard Worker */
391*0e209d39SAndroid Build Coastguard Worker static void U_EXPORT2 adoptDefault(TimeZone* zone);
392*0e209d39SAndroid Build Coastguard Worker
393*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_SYSTEM_API
394*0e209d39SAndroid Build Coastguard Worker /**
395*0e209d39SAndroid Build Coastguard Worker * Same as adoptDefault(), except that the TimeZone object passed in is NOT adopted;
396*0e209d39SAndroid Build Coastguard Worker * the caller remains responsible for deleting it.
397*0e209d39SAndroid Build Coastguard Worker *
398*0e209d39SAndroid Build Coastguard Worker * @param zone The given timezone.
399*0e209d39SAndroid Build Coastguard Worker * @system
400*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
401*0e209d39SAndroid Build Coastguard Worker */
402*0e209d39SAndroid Build Coastguard Worker static void U_EXPORT2 setDefault(const TimeZone& zone);
403*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_SYSTEM_API */
404*0e209d39SAndroid Build Coastguard Worker
405*0e209d39SAndroid Build Coastguard Worker /**
406*0e209d39SAndroid Build Coastguard Worker * Returns the timezone data version currently used by ICU.
407*0e209d39SAndroid Build Coastguard Worker * @param status Output param to filled in with a success or an error.
408*0e209d39SAndroid Build Coastguard Worker * @return the version string, such as "2007f"
409*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.8
410*0e209d39SAndroid Build Coastguard Worker */
411*0e209d39SAndroid Build Coastguard Worker static const char* U_EXPORT2 getTZDataVersion(UErrorCode& status);
412*0e209d39SAndroid Build Coastguard Worker
413*0e209d39SAndroid Build Coastguard Worker /**
414*0e209d39SAndroid Build Coastguard Worker * Returns the canonical system timezone ID or the normalized
415*0e209d39SAndroid Build Coastguard Worker * custom time zone ID for the given time zone ID.
416*0e209d39SAndroid Build Coastguard Worker * @param id The input time zone ID to be canonicalized.
417*0e209d39SAndroid Build Coastguard Worker * @param canonicalID Receives the canonical system time zone ID
418*0e209d39SAndroid Build Coastguard Worker * or the custom time zone ID in normalized format.
419*0e209d39SAndroid Build Coastguard Worker * @param status Receives the status. When the given time zone ID
420*0e209d39SAndroid Build Coastguard Worker * is neither a known system time zone ID nor a
421*0e209d39SAndroid Build Coastguard Worker * valid custom time zone ID, U_ILLEGAL_ARGUMENT_ERROR
422*0e209d39SAndroid Build Coastguard Worker * is set.
423*0e209d39SAndroid Build Coastguard Worker * @return A reference to the result.
424*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.0
425*0e209d39SAndroid Build Coastguard Worker */
426*0e209d39SAndroid Build Coastguard Worker static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id,
427*0e209d39SAndroid Build Coastguard Worker UnicodeString& canonicalID, UErrorCode& status);
428*0e209d39SAndroid Build Coastguard Worker
429*0e209d39SAndroid Build Coastguard Worker /**
430*0e209d39SAndroid Build Coastguard Worker * Returns the canonical system time zone ID or the normalized
431*0e209d39SAndroid Build Coastguard Worker * custom time zone ID for the given time zone ID.
432*0e209d39SAndroid Build Coastguard Worker * @param id The input time zone ID to be canonicalized.
433*0e209d39SAndroid Build Coastguard Worker * @param canonicalID Receives the canonical system time zone ID
434*0e209d39SAndroid Build Coastguard Worker * or the custom time zone ID in normalized format.
435*0e209d39SAndroid Build Coastguard Worker * @param isSystemID Receives if the given ID is a known system
436*0e209d39SAndroid Build Coastguard Worker * time zone ID.
437*0e209d39SAndroid Build Coastguard Worker * @param status Receives the status. When the given time zone ID
438*0e209d39SAndroid Build Coastguard Worker * is neither a known system time zone ID nor a
439*0e209d39SAndroid Build Coastguard Worker * valid custom time zone ID, U_ILLEGAL_ARGUMENT_ERROR
440*0e209d39SAndroid Build Coastguard Worker * is set.
441*0e209d39SAndroid Build Coastguard Worker * @return A reference to the result.
442*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.0
443*0e209d39SAndroid Build Coastguard Worker */
444*0e209d39SAndroid Build Coastguard Worker static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id,
445*0e209d39SAndroid Build Coastguard Worker UnicodeString& canonicalID, UBool& isSystemID, UErrorCode& status);
446*0e209d39SAndroid Build Coastguard Worker
447*0e209d39SAndroid Build Coastguard Worker
448*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_DRAFT_API
449*0e209d39SAndroid Build Coastguard Worker /**
450*0e209d39SAndroid Build Coastguard Worker * Returns the preferred time zone ID in the IANA time zone database for the given time zone ID.
451*0e209d39SAndroid Build Coastguard Worker * There are two types of preferred IDs. The first type is the one defined in zone.tab file,
452*0e209d39SAndroid Build Coastguard Worker * such as "America/Los_Angeles". The second types is the one defined for zones not associated
453*0e209d39SAndroid Build Coastguard Worker * with a specific region, but not defined with "Link" syntax such as "Etc/GMT+10".
454*0e209d39SAndroid Build Coastguard Worker *
455*0e209d39SAndroid Build Coastguard Worker * <p>Note: For most of valid time zone IDs, this method returns an ID same as getCanonicalID().
456*0e209d39SAndroid Build Coastguard Worker * getCanonicalID() is based on canonical time zone IDs defined in Unicode CLDR.
457*0e209d39SAndroid Build Coastguard Worker * These canonical time zone IDs in CLDR were based on very old version of the time zone database.
458*0e209d39SAndroid Build Coastguard Worker * In the IANA time zone database, some IDs were updated since then. This API returns a newer
459*0e209d39SAndroid Build Coastguard Worker * time zone ID. For example, CLDR defines "Asia/Calcutta" as the canonical time zone ID. This
460*0e209d39SAndroid Build Coastguard Worker * method returns "Asia/Kolkata" instead.
461*0e209d39SAndroid Build Coastguard Worker * <p> "Etc/Unknown" is a special time zone ID defined by CLDR. There are no corresponding zones
462*0e209d39SAndroid Build Coastguard Worker * in the IANA time zone database. Therefore, this API returns U_ILLEGAL_ARGUMENT_ERROR when the
463*0e209d39SAndroid Build Coastguard Worker * input ID is "Etc/Unknown".
464*0e209d39SAndroid Build Coastguard Worker *
465*0e209d39SAndroid Build Coastguard Worker * @param id The input time zone ID.
466*0e209d39SAndroid Build Coastguard Worker * @param ianaID Receives the preferred time zone ID in the IANA time zone database. When
467*0e209d39SAndroid Build Coastguard Worker * the given time zone ID is not a known time zone ID, this method sets an
468*0e209d39SAndroid Build Coastguard Worker * invalid (bogus) string.
469*0e209d39SAndroid Build Coastguard Worker * @param status Receives the status. When the given time zone ID is not a known time zone
470*0e209d39SAndroid Build Coastguard Worker * ID, U_ILLEGAL_ARGUMENT_ERROR is set.
471*0e209d39SAndroid Build Coastguard Worker * @return A reference to the result.
472*0e209d39SAndroid Build Coastguard Worker * @draft ICU 74
473*0e209d39SAndroid Build Coastguard Worker */
474*0e209d39SAndroid Build Coastguard Worker static UnicodeString& U_EXPORT2 getIanaID(const UnicodeString&id, UnicodeString& ianaID,
475*0e209d39SAndroid Build Coastguard Worker UErrorCode& status);
476*0e209d39SAndroid Build Coastguard Worker #endif // U_HIDE_DRAFT_API
477*0e209d39SAndroid Build Coastguard Worker
478*0e209d39SAndroid Build Coastguard Worker /**
479*0e209d39SAndroid Build Coastguard Worker * Converts a system time zone ID to an equivalent Windows time zone ID. For example,
480*0e209d39SAndroid Build Coastguard Worker * Windows time zone ID "Pacific Standard Time" is returned for input "America/Los_Angeles".
481*0e209d39SAndroid Build Coastguard Worker *
482*0e209d39SAndroid Build Coastguard Worker * <p>There are system time zones that cannot be mapped to Windows zones. When the input
483*0e209d39SAndroid Build Coastguard Worker * system time zone ID is unknown or unmappable to a Windows time zone, then the result will be
484*0e209d39SAndroid Build Coastguard Worker * empty, but the operation itself remains successful (no error status set on return).
485*0e209d39SAndroid Build Coastguard Worker *
486*0e209d39SAndroid Build Coastguard Worker * <p>This implementation utilizes <a href="http://unicode.org/cldr/charts/supplemental/zone_tzid.html">
487*0e209d39SAndroid Build Coastguard Worker * Zone-Tzid mapping data</a>. The mapping data is updated time to time. To get the latest changes,
488*0e209d39SAndroid Build Coastguard Worker * please read the ICU user guide section <a href="https://unicode-org.github.io/icu/userguide/datetime/timezone#updating-the-time-zone-data">
489*0e209d39SAndroid Build Coastguard Worker * Updating the Time Zone Data</a>.
490*0e209d39SAndroid Build Coastguard Worker *
491*0e209d39SAndroid Build Coastguard Worker * @param id A system time zone ID.
492*0e209d39SAndroid Build Coastguard Worker * @param winid Receives a Windows time zone ID. When the input system time zone ID is unknown
493*0e209d39SAndroid Build Coastguard Worker * or unmappable to a Windows time zone ID, then an empty string is set on return.
494*0e209d39SAndroid Build Coastguard Worker * @param status Receives the status.
495*0e209d39SAndroid Build Coastguard Worker * @return A reference to the result (<code>winid</code>).
496*0e209d39SAndroid Build Coastguard Worker * @see getIDForWindowsID
497*0e209d39SAndroid Build Coastguard Worker *
498*0e209d39SAndroid Build Coastguard Worker * @stable ICU 52
499*0e209d39SAndroid Build Coastguard Worker */
500*0e209d39SAndroid Build Coastguard Worker static UnicodeString& U_EXPORT2 getWindowsID(const UnicodeString& id,
501*0e209d39SAndroid Build Coastguard Worker UnicodeString& winid, UErrorCode& status);
502*0e209d39SAndroid Build Coastguard Worker
503*0e209d39SAndroid Build Coastguard Worker /**
504*0e209d39SAndroid Build Coastguard Worker * Converts a Windows time zone ID to an equivalent system time zone ID
505*0e209d39SAndroid Build Coastguard Worker * for a region. For example, system time zone ID "America/Los_Angeles" is returned
506*0e209d39SAndroid Build Coastguard Worker * for input Windows ID "Pacific Standard Time" and region "US" (or <code>null</code>),
507*0e209d39SAndroid Build Coastguard Worker * "America/Vancouver" is returned for the same Windows ID "Pacific Standard Time" and
508*0e209d39SAndroid Build Coastguard Worker * region "CA".
509*0e209d39SAndroid Build Coastguard Worker *
510*0e209d39SAndroid Build Coastguard Worker * <p>Not all Windows time zones can be mapped to system time zones. When the input
511*0e209d39SAndroid Build Coastguard Worker * Windows time zone ID is unknown or unmappable to a system time zone, then the result
512*0e209d39SAndroid Build Coastguard Worker * will be empty, but the operation itself remains successful (no error status set on return).
513*0e209d39SAndroid Build Coastguard Worker *
514*0e209d39SAndroid Build Coastguard Worker * <p>This implementation utilizes <a href="http://unicode.org/cldr/charts/supplemental/zone_tzid.html">
515*0e209d39SAndroid Build Coastguard Worker * Zone-Tzid mapping data</a>. The mapping data is updated time to time. To get the latest changes,
516*0e209d39SAndroid Build Coastguard Worker * please read the ICU user guide section <a href="https://unicode-org.github.io/icu/userguide/datetime/timezone#updating-the-time-zone-data">
517*0e209d39SAndroid Build Coastguard Worker * Updating the Time Zone Data</a>.
518*0e209d39SAndroid Build Coastguard Worker *
519*0e209d39SAndroid Build Coastguard Worker * @param winid A Windows time zone ID.
520*0e209d39SAndroid Build Coastguard Worker * @param region A NUL-terminated region code, or <code>nullptr</code> if no regional preference.
521*0e209d39SAndroid Build Coastguard Worker * @param id Receives a system time zone ID. When the input Windows time zone ID is unknown
522*0e209d39SAndroid Build Coastguard Worker * or unmappable to a system time zone ID, then an empty string is set on return.
523*0e209d39SAndroid Build Coastguard Worker * @param status Receives the status.
524*0e209d39SAndroid Build Coastguard Worker * @return A reference to the result (<code>id</code>).
525*0e209d39SAndroid Build Coastguard Worker * @see getWindowsID
526*0e209d39SAndroid Build Coastguard Worker *
527*0e209d39SAndroid Build Coastguard Worker * @stable ICU 52
528*0e209d39SAndroid Build Coastguard Worker */
529*0e209d39SAndroid Build Coastguard Worker static UnicodeString& U_EXPORT2 getIDForWindowsID(const UnicodeString& winid, const char* region,
530*0e209d39SAndroid Build Coastguard Worker UnicodeString& id, UErrorCode& status);
531*0e209d39SAndroid Build Coastguard Worker
532*0e209d39SAndroid Build Coastguard Worker /**
533*0e209d39SAndroid Build Coastguard Worker * Returns true if the two TimeZones are equal. (The TimeZone version only compares
534*0e209d39SAndroid Build Coastguard Worker * IDs, but subclasses are expected to also compare the fields they add.)
535*0e209d39SAndroid Build Coastguard Worker *
536*0e209d39SAndroid Build Coastguard Worker * @param that The TimeZone object to be compared with.
537*0e209d39SAndroid Build Coastguard Worker * @return true if the given TimeZone is equal to this TimeZone; false
538*0e209d39SAndroid Build Coastguard Worker * otherwise.
539*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
540*0e209d39SAndroid Build Coastguard Worker */
541*0e209d39SAndroid Build Coastguard Worker virtual bool operator==(const TimeZone& that) const;
542*0e209d39SAndroid Build Coastguard Worker
543*0e209d39SAndroid Build Coastguard Worker /**
544*0e209d39SAndroid Build Coastguard Worker * Returns true if the two TimeZones are NOT equal; that is, if operator==() returns
545*0e209d39SAndroid Build Coastguard Worker * false.
546*0e209d39SAndroid Build Coastguard Worker *
547*0e209d39SAndroid Build Coastguard Worker * @param that The TimeZone object to be compared with.
548*0e209d39SAndroid Build Coastguard Worker * @return true if the given TimeZone is not equal to this TimeZone; false
549*0e209d39SAndroid Build Coastguard Worker * otherwise.
550*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
551*0e209d39SAndroid Build Coastguard Worker */
552*0e209d39SAndroid Build Coastguard Worker bool operator!=(const TimeZone& that) const {return !operator==(that);}
553*0e209d39SAndroid Build Coastguard Worker
554*0e209d39SAndroid Build Coastguard Worker /**
555*0e209d39SAndroid Build Coastguard Worker * Returns the TimeZone's adjusted GMT offset (i.e., the number of milliseconds to add
556*0e209d39SAndroid Build Coastguard Worker * to GMT to get local time in this time zone, taking daylight savings time into
557*0e209d39SAndroid Build Coastguard Worker * account) as of a particular reference date. The reference date is used to determine
558*0e209d39SAndroid Build Coastguard Worker * whether daylight savings time is in effect and needs to be figured into the offset
559*0e209d39SAndroid Build Coastguard Worker * that is returned (in other words, what is the adjusted GMT offset in this time zone
560*0e209d39SAndroid Build Coastguard Worker * at this particular date and time?). For the time zones produced by createTimeZone(),
561*0e209d39SAndroid Build Coastguard Worker * the reference data is specified according to the Gregorian calendar, and the date
562*0e209d39SAndroid Build Coastguard Worker * and time fields are local standard time.
563*0e209d39SAndroid Build Coastguard Worker *
564*0e209d39SAndroid Build Coastguard Worker * <p>Note: Don't call this method. Instead, call the getOffset(UDate...) overload,
565*0e209d39SAndroid Build Coastguard Worker * which returns both the raw and the DST offset for a given time. This method
566*0e209d39SAndroid Build Coastguard Worker * is retained only for backward compatibility.
567*0e209d39SAndroid Build Coastguard Worker *
568*0e209d39SAndroid Build Coastguard Worker * @param era The reference date's era
569*0e209d39SAndroid Build Coastguard Worker * @param year The reference date's year
570*0e209d39SAndroid Build Coastguard Worker * @param month The reference date's month (0-based; 0 is January)
571*0e209d39SAndroid Build Coastguard Worker * @param day The reference date's day-in-month (1-based)
572*0e209d39SAndroid Build Coastguard Worker * @param dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday)
573*0e209d39SAndroid Build Coastguard Worker * @param millis The reference date's milliseconds in day, local standard time
574*0e209d39SAndroid Build Coastguard Worker * @param status Output param to filled in with a success or an error.
575*0e209d39SAndroid Build Coastguard Worker * @return The offset in milliseconds to add to GMT to get local time.
576*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
577*0e209d39SAndroid Build Coastguard Worker */
578*0e209d39SAndroid Build Coastguard Worker virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
579*0e209d39SAndroid Build Coastguard Worker uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const = 0;
580*0e209d39SAndroid Build Coastguard Worker
581*0e209d39SAndroid Build Coastguard Worker /**
582*0e209d39SAndroid Build Coastguard Worker * Gets the time zone offset, for current date, modified in case of
583*0e209d39SAndroid Build Coastguard Worker * daylight savings. This is the offset to add *to* UTC to get local time.
584*0e209d39SAndroid Build Coastguard Worker *
585*0e209d39SAndroid Build Coastguard Worker * <p>Note: Don't call this method. Instead, call the getOffset(UDate...) overload,
586*0e209d39SAndroid Build Coastguard Worker * which returns both the raw and the DST offset for a given time. This method
587*0e209d39SAndroid Build Coastguard Worker * is retained only for backward compatibility.
588*0e209d39SAndroid Build Coastguard Worker *
589*0e209d39SAndroid Build Coastguard Worker * @param era the era of the given date.
590*0e209d39SAndroid Build Coastguard Worker * @param year the year in the given date.
591*0e209d39SAndroid Build Coastguard Worker * @param month the month in the given date.
592*0e209d39SAndroid Build Coastguard Worker * Month is 0-based. e.g., 0 for January.
593*0e209d39SAndroid Build Coastguard Worker * @param day the day-in-month of the given date.
594*0e209d39SAndroid Build Coastguard Worker * @param dayOfWeek the day-of-week of the given date.
595*0e209d39SAndroid Build Coastguard Worker * @param milliseconds the millis in day in <em>standard</em> local time.
596*0e209d39SAndroid Build Coastguard Worker * @param monthLength the length of the given month in days.
597*0e209d39SAndroid Build Coastguard Worker * @param status Output param to filled in with a success or an error.
598*0e209d39SAndroid Build Coastguard Worker * @return the offset to add *to* GMT to get local time.
599*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
600*0e209d39SAndroid Build Coastguard Worker */
601*0e209d39SAndroid Build Coastguard Worker virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
602*0e209d39SAndroid Build Coastguard Worker uint8_t dayOfWeek, int32_t milliseconds,
603*0e209d39SAndroid Build Coastguard Worker int32_t monthLength, UErrorCode& status) const = 0;
604*0e209d39SAndroid Build Coastguard Worker
605*0e209d39SAndroid Build Coastguard Worker /**
606*0e209d39SAndroid Build Coastguard Worker * Returns the time zone raw and GMT offset for the given moment
607*0e209d39SAndroid Build Coastguard Worker * in time. Upon return, local-millis = GMT-millis + rawOffset +
608*0e209d39SAndroid Build Coastguard Worker * dstOffset. All computations are performed in the proleptic
609*0e209d39SAndroid Build Coastguard Worker * Gregorian calendar. The default implementation in the TimeZone
610*0e209d39SAndroid Build Coastguard Worker * class delegates to the 8-argument getOffset().
611*0e209d39SAndroid Build Coastguard Worker *
612*0e209d39SAndroid Build Coastguard Worker * @param date moment in time for which to return offsets, in
613*0e209d39SAndroid Build Coastguard Worker * units of milliseconds from January 1, 1970 0:00 GMT, either GMT
614*0e209d39SAndroid Build Coastguard Worker * time or local wall time, depending on `local'.
615*0e209d39SAndroid Build Coastguard Worker * @param local if true, `date' is local wall time; otherwise it
616*0e209d39SAndroid Build Coastguard Worker * is in GMT time.
617*0e209d39SAndroid Build Coastguard Worker * @param rawOffset output parameter to receive the raw offset, that
618*0e209d39SAndroid Build Coastguard Worker * is, the offset not including DST adjustments
619*0e209d39SAndroid Build Coastguard Worker * @param dstOffset output parameter to receive the DST offset,
620*0e209d39SAndroid Build Coastguard Worker * that is, the offset to be added to `rawOffset' to obtain the
621*0e209d39SAndroid Build Coastguard Worker * total offset between local and GMT time. If DST is not in
622*0e209d39SAndroid Build Coastguard Worker * effect, this value is zero; otherwise it is a positive value,
623*0e209d39SAndroid Build Coastguard Worker * typically one hour.
624*0e209d39SAndroid Build Coastguard Worker * @param ec input-output error code
625*0e209d39SAndroid Build Coastguard Worker *
626*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.8
627*0e209d39SAndroid Build Coastguard Worker */
628*0e209d39SAndroid Build Coastguard Worker virtual void getOffset(UDate date, UBool local, int32_t& rawOffset,
629*0e209d39SAndroid Build Coastguard Worker int32_t& dstOffset, UErrorCode& ec) const;
630*0e209d39SAndroid Build Coastguard Worker
631*0e209d39SAndroid Build Coastguard Worker /**
632*0e209d39SAndroid Build Coastguard Worker * Sets the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
633*0e209d39SAndroid Build Coastguard Worker * to GMT to get local time, before taking daylight savings time into account).
634*0e209d39SAndroid Build Coastguard Worker *
635*0e209d39SAndroid Build Coastguard Worker * @param offsetMillis The new raw GMT offset for this time zone.
636*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
637*0e209d39SAndroid Build Coastguard Worker */
638*0e209d39SAndroid Build Coastguard Worker virtual void setRawOffset(int32_t offsetMillis) = 0;
639*0e209d39SAndroid Build Coastguard Worker
640*0e209d39SAndroid Build Coastguard Worker /**
641*0e209d39SAndroid Build Coastguard Worker * Returns the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
642*0e209d39SAndroid Build Coastguard Worker * to GMT to get local time, before taking daylight savings time into account).
643*0e209d39SAndroid Build Coastguard Worker *
644*0e209d39SAndroid Build Coastguard Worker * @return The TimeZone's raw GMT offset.
645*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
646*0e209d39SAndroid Build Coastguard Worker */
647*0e209d39SAndroid Build Coastguard Worker virtual int32_t getRawOffset() const = 0;
648*0e209d39SAndroid Build Coastguard Worker
649*0e209d39SAndroid Build Coastguard Worker /**
650*0e209d39SAndroid Build Coastguard Worker * Fills in "ID" with the TimeZone's ID.
651*0e209d39SAndroid Build Coastguard Worker *
652*0e209d39SAndroid Build Coastguard Worker * @param ID Receives this TimeZone's ID.
653*0e209d39SAndroid Build Coastguard Worker * @return A reference to 'ID'
654*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
655*0e209d39SAndroid Build Coastguard Worker */
656*0e209d39SAndroid Build Coastguard Worker UnicodeString& getID(UnicodeString& ID) const;
657*0e209d39SAndroid Build Coastguard Worker
658*0e209d39SAndroid Build Coastguard Worker /**
659*0e209d39SAndroid Build Coastguard Worker * Sets the TimeZone's ID to the specified value. This doesn't affect any other
660*0e209d39SAndroid Build Coastguard Worker * fields (for example, if you say<
661*0e209d39SAndroid Build Coastguard Worker * blockquote><pre>
662*0e209d39SAndroid Build Coastguard Worker * . TimeZone* foo = TimeZone::createTimeZone("America/New_York");
663*0e209d39SAndroid Build Coastguard Worker * . foo.setID("America/Los_Angeles");
664*0e209d39SAndroid Build Coastguard Worker * </pre>\htmlonly</blockquote>\endhtmlonly
665*0e209d39SAndroid Build Coastguard Worker * the time zone's GMT offset and daylight-savings rules don't change to those for
666*0e209d39SAndroid Build Coastguard Worker * Los Angeles. They're still those for New York. Only the ID has changed.)
667*0e209d39SAndroid Build Coastguard Worker *
668*0e209d39SAndroid Build Coastguard Worker * @param ID The new time zone ID.
669*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
670*0e209d39SAndroid Build Coastguard Worker */
671*0e209d39SAndroid Build Coastguard Worker void setID(const UnicodeString& ID);
672*0e209d39SAndroid Build Coastguard Worker
673*0e209d39SAndroid Build Coastguard Worker /**
674*0e209d39SAndroid Build Coastguard Worker * Enum for use with getDisplayName
675*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.4
676*0e209d39SAndroid Build Coastguard Worker */
677*0e209d39SAndroid Build Coastguard Worker enum EDisplayType {
678*0e209d39SAndroid Build Coastguard Worker /**
679*0e209d39SAndroid Build Coastguard Worker * Selector for short display name
680*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.4
681*0e209d39SAndroid Build Coastguard Worker */
682*0e209d39SAndroid Build Coastguard Worker SHORT = 1,
683*0e209d39SAndroid Build Coastguard Worker /**
684*0e209d39SAndroid Build Coastguard Worker * Selector for long display name
685*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.4
686*0e209d39SAndroid Build Coastguard Worker */
687*0e209d39SAndroid Build Coastguard Worker LONG,
688*0e209d39SAndroid Build Coastguard Worker /**
689*0e209d39SAndroid Build Coastguard Worker * Selector for short generic display name
690*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.4
691*0e209d39SAndroid Build Coastguard Worker */
692*0e209d39SAndroid Build Coastguard Worker SHORT_GENERIC,
693*0e209d39SAndroid Build Coastguard Worker /**
694*0e209d39SAndroid Build Coastguard Worker * Selector for long generic display name
695*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.4
696*0e209d39SAndroid Build Coastguard Worker */
697*0e209d39SAndroid Build Coastguard Worker LONG_GENERIC,
698*0e209d39SAndroid Build Coastguard Worker /**
699*0e209d39SAndroid Build Coastguard Worker * Selector for short display name derived
700*0e209d39SAndroid Build Coastguard Worker * from time zone offset
701*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.4
702*0e209d39SAndroid Build Coastguard Worker */
703*0e209d39SAndroid Build Coastguard Worker SHORT_GMT,
704*0e209d39SAndroid Build Coastguard Worker /**
705*0e209d39SAndroid Build Coastguard Worker * Selector for long display name derived
706*0e209d39SAndroid Build Coastguard Worker * from time zone offset
707*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.4
708*0e209d39SAndroid Build Coastguard Worker */
709*0e209d39SAndroid Build Coastguard Worker LONG_GMT,
710*0e209d39SAndroid Build Coastguard Worker /**
711*0e209d39SAndroid Build Coastguard Worker * Selector for short display name derived
712*0e209d39SAndroid Build Coastguard Worker * from the time zone's fallback name
713*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.4
714*0e209d39SAndroid Build Coastguard Worker */
715*0e209d39SAndroid Build Coastguard Worker SHORT_COMMONLY_USED,
716*0e209d39SAndroid Build Coastguard Worker /**
717*0e209d39SAndroid Build Coastguard Worker * Selector for long display name derived
718*0e209d39SAndroid Build Coastguard Worker * from the time zone's fallback name
719*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.4
720*0e209d39SAndroid Build Coastguard Worker */
721*0e209d39SAndroid Build Coastguard Worker GENERIC_LOCATION
722*0e209d39SAndroid Build Coastguard Worker };
723*0e209d39SAndroid Build Coastguard Worker
724*0e209d39SAndroid Build Coastguard Worker /**
725*0e209d39SAndroid Build Coastguard Worker * Returns a name of this time zone suitable for presentation to the user
726*0e209d39SAndroid Build Coastguard Worker * in the default locale.
727*0e209d39SAndroid Build Coastguard Worker * This method returns the long name, not including daylight savings.
728*0e209d39SAndroid Build Coastguard Worker * If the display name is not available for the locale,
729*0e209d39SAndroid Build Coastguard Worker * then this method returns a string in the localized GMT offset format
730*0e209d39SAndroid Build Coastguard Worker * such as <code>GMT[+-]HH:mm</code>.
731*0e209d39SAndroid Build Coastguard Worker * @param result the human-readable name of this time zone in the default locale.
732*0e209d39SAndroid Build Coastguard Worker * @return A reference to 'result'.
733*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
734*0e209d39SAndroid Build Coastguard Worker */
735*0e209d39SAndroid Build Coastguard Worker UnicodeString& getDisplayName(UnicodeString& result) const;
736*0e209d39SAndroid Build Coastguard Worker
737*0e209d39SAndroid Build Coastguard Worker /**
738*0e209d39SAndroid Build Coastguard Worker * Returns a name of this time zone suitable for presentation to the user
739*0e209d39SAndroid Build Coastguard Worker * in the specified locale.
740*0e209d39SAndroid Build Coastguard Worker * This method returns the long name, not including daylight savings.
741*0e209d39SAndroid Build Coastguard Worker * If the display name is not available for the locale,
742*0e209d39SAndroid Build Coastguard Worker * then this method returns a string in the localized GMT offset format
743*0e209d39SAndroid Build Coastguard Worker * such as <code>GMT[+-]HH:mm</code>.
744*0e209d39SAndroid Build Coastguard Worker * @param locale the locale in which to supply the display name.
745*0e209d39SAndroid Build Coastguard Worker * @param result the human-readable name of this time zone in the given locale
746*0e209d39SAndroid Build Coastguard Worker * or in the default locale if the given locale is not recognized.
747*0e209d39SAndroid Build Coastguard Worker * @return A reference to 'result'.
748*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
749*0e209d39SAndroid Build Coastguard Worker */
750*0e209d39SAndroid Build Coastguard Worker UnicodeString& getDisplayName(const Locale& locale, UnicodeString& result) const;
751*0e209d39SAndroid Build Coastguard Worker
752*0e209d39SAndroid Build Coastguard Worker /**
753*0e209d39SAndroid Build Coastguard Worker * Returns a name of this time zone suitable for presentation to the user
754*0e209d39SAndroid Build Coastguard Worker * in the default locale.
755*0e209d39SAndroid Build Coastguard Worker * If the display name is not available for the locale,
756*0e209d39SAndroid Build Coastguard Worker * then this method returns a string in the localized GMT offset format
757*0e209d39SAndroid Build Coastguard Worker * such as <code>GMT[+-]HH:mm</code>.
758*0e209d39SAndroid Build Coastguard Worker * @param inDaylight if true, return the daylight savings name.
759*0e209d39SAndroid Build Coastguard Worker * @param style
760*0e209d39SAndroid Build Coastguard Worker * @param result the human-readable name of this time zone in the default locale.
761*0e209d39SAndroid Build Coastguard Worker * @return A reference to 'result'.
762*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
763*0e209d39SAndroid Build Coastguard Worker */
764*0e209d39SAndroid Build Coastguard Worker UnicodeString& getDisplayName(UBool inDaylight, EDisplayType style, UnicodeString& result) const;
765*0e209d39SAndroid Build Coastguard Worker
766*0e209d39SAndroid Build Coastguard Worker /**
767*0e209d39SAndroid Build Coastguard Worker * Returns a name of this time zone suitable for presentation to the user
768*0e209d39SAndroid Build Coastguard Worker * in the specified locale.
769*0e209d39SAndroid Build Coastguard Worker * If the display name is not available for the locale,
770*0e209d39SAndroid Build Coastguard Worker * then this method returns a string in the localized GMT offset format
771*0e209d39SAndroid Build Coastguard Worker * such as <code>GMT[+-]HH:mm</code>.
772*0e209d39SAndroid Build Coastguard Worker * @param inDaylight if true, return the daylight savings name.
773*0e209d39SAndroid Build Coastguard Worker * @param style
774*0e209d39SAndroid Build Coastguard Worker * @param locale the locale in which to supply the display name.
775*0e209d39SAndroid Build Coastguard Worker * @param result the human-readable name of this time zone in the given locale
776*0e209d39SAndroid Build Coastguard Worker * or in the default locale if the given locale is not recognized.
777*0e209d39SAndroid Build Coastguard Worker * @return A reference to 'result'.
778*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
779*0e209d39SAndroid Build Coastguard Worker */
780*0e209d39SAndroid Build Coastguard Worker UnicodeString& getDisplayName(UBool inDaylight, EDisplayType style, const Locale& locale, UnicodeString& result) const;
781*0e209d39SAndroid Build Coastguard Worker
782*0e209d39SAndroid Build Coastguard Worker /**
783*0e209d39SAndroid Build Coastguard Worker * Queries if this time zone uses daylight savings time.
784*0e209d39SAndroid Build Coastguard Worker * @return true if this time zone uses daylight savings time,
785*0e209d39SAndroid Build Coastguard Worker * false, otherwise.
786*0e209d39SAndroid Build Coastguard Worker * <p><strong>Note:</strong>The default implementation of
787*0e209d39SAndroid Build Coastguard Worker * ICU TimeZone uses the tz database, which supports historic
788*0e209d39SAndroid Build Coastguard Worker * rule changes, for system time zones. With the implementation,
789*0e209d39SAndroid Build Coastguard Worker * there are time zones that used daylight savings time in the
790*0e209d39SAndroid Build Coastguard Worker * past, but no longer used currently. For example, Asia/Tokyo has
791*0e209d39SAndroid Build Coastguard Worker * never used daylight savings time since 1951. Most clients would
792*0e209d39SAndroid Build Coastguard Worker * expect that this method to return <code>false</code> for such case.
793*0e209d39SAndroid Build Coastguard Worker * The default implementation of this method returns <code>true</code>
794*0e209d39SAndroid Build Coastguard Worker * when the time zone uses daylight savings time in the current
795*0e209d39SAndroid Build Coastguard Worker * (Gregorian) calendar year.
796*0e209d39SAndroid Build Coastguard Worker * <p>In Java 7, <code>observesDaylightTime()</code> was added in
797*0e209d39SAndroid Build Coastguard Worker * addition to <code>useDaylightTime()</code>. In Java, <code>useDaylightTime()</code>
798*0e209d39SAndroid Build Coastguard Worker * only checks if daylight saving time is observed by the last known
799*0e209d39SAndroid Build Coastguard Worker * rule. This specification might not be what most users would expect
800*0e209d39SAndroid Build Coastguard Worker * if daylight saving time is currently observed, but not scheduled
801*0e209d39SAndroid Build Coastguard Worker * in future. In this case, Java's <code>userDaylightTime()</code> returns
802*0e209d39SAndroid Build Coastguard Worker * <code>false</code>. To resolve the issue, Java 7 added <code>observesDaylightTime()</code>,
803*0e209d39SAndroid Build Coastguard Worker * which takes the current rule into account. The method <code>observesDaylightTime()</code>
804*0e209d39SAndroid Build Coastguard Worker * was added in ICU4J for supporting API signature compatibility with JDK.
805*0e209d39SAndroid Build Coastguard Worker * In general, ICU4C also provides JDK compatible methods, but the current
806*0e209d39SAndroid Build Coastguard Worker * implementation <code>userDaylightTime()</code> serves the purpose
807*0e209d39SAndroid Build Coastguard Worker * (takes the current rule into account), <code>observesDaylightTime()</code>
808*0e209d39SAndroid Build Coastguard Worker * is not added in ICU4C. In addition to <code>useDaylightTime()</code>, ICU4C
809*0e209d39SAndroid Build Coastguard Worker * <code>BasicTimeZone</code> class (Note that <code>TimeZone::createTimeZone(const UnicodeString &ID)</code>
810*0e209d39SAndroid Build Coastguard Worker * always returns a <code>BasicTimeZone</code>) provides a series of methods allowing
811*0e209d39SAndroid Build Coastguard Worker * historic and future time zone rule iteration, so you can check if daylight saving
812*0e209d39SAndroid Build Coastguard Worker * time is observed or not within a given period.
813*0e209d39SAndroid Build Coastguard Worker *
814*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
815*0e209d39SAndroid Build Coastguard Worker */
816*0e209d39SAndroid Build Coastguard Worker virtual UBool useDaylightTime() const = 0;
817*0e209d39SAndroid Build Coastguard Worker
818*0e209d39SAndroid Build Coastguard Worker #ifndef U_FORCE_HIDE_DEPRECATED_API
819*0e209d39SAndroid Build Coastguard Worker /**
820*0e209d39SAndroid Build Coastguard Worker * Queries if the given date is in daylight savings time in
821*0e209d39SAndroid Build Coastguard Worker * this time zone.
822*0e209d39SAndroid Build Coastguard Worker * This method is wasteful since it creates a new GregorianCalendar and
823*0e209d39SAndroid Build Coastguard Worker * deletes it each time it is called. This is a deprecated method
824*0e209d39SAndroid Build Coastguard Worker * and provided only for Java compatibility.
825*0e209d39SAndroid Build Coastguard Worker *
826*0e209d39SAndroid Build Coastguard Worker * @param date the given UDate.
827*0e209d39SAndroid Build Coastguard Worker * @param status Output param filled in with success/error code.
828*0e209d39SAndroid Build Coastguard Worker * @return true if the given date is in daylight savings time,
829*0e209d39SAndroid Build Coastguard Worker * false, otherwise.
830*0e209d39SAndroid Build Coastguard Worker * @deprecated ICU 2.4. Use Calendar::inDaylightTime() instead.
831*0e209d39SAndroid Build Coastguard Worker */
832*0e209d39SAndroid Build Coastguard Worker virtual UBool inDaylightTime(UDate date, UErrorCode& status) const = 0;
833*0e209d39SAndroid Build Coastguard Worker #endif // U_FORCE_HIDE_DEPRECATED_API
834*0e209d39SAndroid Build Coastguard Worker
835*0e209d39SAndroid Build Coastguard Worker /**
836*0e209d39SAndroid Build Coastguard Worker * Returns true if this zone has the same rule and offset as another zone.
837*0e209d39SAndroid Build Coastguard Worker * That is, if this zone differs only in ID, if at all.
838*0e209d39SAndroid Build Coastguard Worker * @param other the <code>TimeZone</code> object to be compared with
839*0e209d39SAndroid Build Coastguard Worker * @return true if the given zone is the same as this one,
840*0e209d39SAndroid Build Coastguard Worker * with the possible exception of the ID
841*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
842*0e209d39SAndroid Build Coastguard Worker */
843*0e209d39SAndroid Build Coastguard Worker virtual UBool hasSameRules(const TimeZone& other) const;
844*0e209d39SAndroid Build Coastguard Worker
845*0e209d39SAndroid Build Coastguard Worker /**
846*0e209d39SAndroid Build Coastguard Worker * Clones TimeZone objects polymorphically. Clients are responsible for deleting
847*0e209d39SAndroid Build Coastguard Worker * the TimeZone object cloned.
848*0e209d39SAndroid Build Coastguard Worker *
849*0e209d39SAndroid Build Coastguard Worker * @return A new copy of this TimeZone object.
850*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
851*0e209d39SAndroid Build Coastguard Worker */
852*0e209d39SAndroid Build Coastguard Worker virtual TimeZone* clone() const = 0;
853*0e209d39SAndroid Build Coastguard Worker
854*0e209d39SAndroid Build Coastguard Worker /**
855*0e209d39SAndroid Build Coastguard Worker * Return the class ID for this class. This is useful only for
856*0e209d39SAndroid Build Coastguard Worker * comparing to a return value from getDynamicClassID().
857*0e209d39SAndroid Build Coastguard Worker * @return The class ID for all objects of this class.
858*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
859*0e209d39SAndroid Build Coastguard Worker */
860*0e209d39SAndroid Build Coastguard Worker static UClassID U_EXPORT2 getStaticClassID();
861*0e209d39SAndroid Build Coastguard Worker
862*0e209d39SAndroid Build Coastguard Worker /**
863*0e209d39SAndroid Build Coastguard Worker * Returns a unique class ID POLYMORPHICALLY. This method is to
864*0e209d39SAndroid Build Coastguard Worker * implement a simple version of RTTI, since not all C++ compilers support genuine
865*0e209d39SAndroid Build Coastguard Worker * RTTI. Polymorphic operator==() and clone() methods call this method.
866*0e209d39SAndroid Build Coastguard Worker * <P>
867*0e209d39SAndroid Build Coastguard Worker * Concrete subclasses of TimeZone must use the UOBJECT_DEFINE_RTTI_IMPLEMENTATION
868*0e209d39SAndroid Build Coastguard Worker * macro from uobject.h in their implementation to provide correct RTTI information.
869*0e209d39SAndroid Build Coastguard Worker * @return The class ID for this object. All objects of a given class have the
870*0e209d39SAndroid Build Coastguard Worker * same class ID. Objects of other classes have different class IDs.
871*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
872*0e209d39SAndroid Build Coastguard Worker */
873*0e209d39SAndroid Build Coastguard Worker virtual UClassID getDynamicClassID() const override = 0;
874*0e209d39SAndroid Build Coastguard Worker
875*0e209d39SAndroid Build Coastguard Worker /**
876*0e209d39SAndroid Build Coastguard Worker * Returns the amount of time to be added to local standard time
877*0e209d39SAndroid Build Coastguard Worker * to get local wall clock time.
878*0e209d39SAndroid Build Coastguard Worker * <p>
879*0e209d39SAndroid Build Coastguard Worker * The default implementation always returns 3600000 milliseconds
880*0e209d39SAndroid Build Coastguard Worker * (i.e., one hour) if this time zone observes Daylight Saving
881*0e209d39SAndroid Build Coastguard Worker * Time. Otherwise, 0 (zero) is returned.
882*0e209d39SAndroid Build Coastguard Worker * <p>
883*0e209d39SAndroid Build Coastguard Worker * If an underlying TimeZone implementation subclass supports
884*0e209d39SAndroid Build Coastguard Worker * historical Daylight Saving Time changes, this method returns
885*0e209d39SAndroid Build Coastguard Worker * the known latest daylight saving value.
886*0e209d39SAndroid Build Coastguard Worker *
887*0e209d39SAndroid Build Coastguard Worker * @return the amount of saving time in milliseconds
888*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.6
889*0e209d39SAndroid Build Coastguard Worker */
890*0e209d39SAndroid Build Coastguard Worker virtual int32_t getDSTSavings() const;
891*0e209d39SAndroid Build Coastguard Worker
892*0e209d39SAndroid Build Coastguard Worker /**
893*0e209d39SAndroid Build Coastguard Worker * Gets the region code associated with the given
894*0e209d39SAndroid Build Coastguard Worker * system time zone ID. The region code is either ISO 3166
895*0e209d39SAndroid Build Coastguard Worker * 2-letter country code or UN M.49 3-digit area code.
896*0e209d39SAndroid Build Coastguard Worker * When the time zone is not associated with a specific location,
897*0e209d39SAndroid Build Coastguard Worker * for example - "Etc/UTC", "EST5EDT", then this method returns
898*0e209d39SAndroid Build Coastguard Worker * "001" (UN M.49 area code for World).
899*0e209d39SAndroid Build Coastguard Worker *
900*0e209d39SAndroid Build Coastguard Worker * @param id The system time zone ID.
901*0e209d39SAndroid Build Coastguard Worker * @param region Output buffer for receiving the region code.
902*0e209d39SAndroid Build Coastguard Worker * @param capacity The size of the output buffer.
903*0e209d39SAndroid Build Coastguard Worker * @param status Receives the status. When the given time zone ID
904*0e209d39SAndroid Build Coastguard Worker * is not a known system time zone ID,
905*0e209d39SAndroid Build Coastguard Worker * U_ILLEGAL_ARGUMENT_ERROR is set.
906*0e209d39SAndroid Build Coastguard Worker * @return The length of the output region code.
907*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.8
908*0e209d39SAndroid Build Coastguard Worker */
909*0e209d39SAndroid Build Coastguard Worker static int32_t U_EXPORT2 getRegion(const UnicodeString& id,
910*0e209d39SAndroid Build Coastguard Worker char *region, int32_t capacity, UErrorCode& status);
911*0e209d39SAndroid Build Coastguard Worker
912*0e209d39SAndroid Build Coastguard Worker protected:
913*0e209d39SAndroid Build Coastguard Worker
914*0e209d39SAndroid Build Coastguard Worker /**
915*0e209d39SAndroid Build Coastguard Worker * Default constructor. ID is initialized to the empty string.
916*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
917*0e209d39SAndroid Build Coastguard Worker */
918*0e209d39SAndroid Build Coastguard Worker TimeZone();
919*0e209d39SAndroid Build Coastguard Worker
920*0e209d39SAndroid Build Coastguard Worker /**
921*0e209d39SAndroid Build Coastguard Worker * Construct a TimeZone with a given ID.
922*0e209d39SAndroid Build Coastguard Worker * @param id a system time zone ID
923*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
924*0e209d39SAndroid Build Coastguard Worker */
925*0e209d39SAndroid Build Coastguard Worker TimeZone(const UnicodeString &id);
926*0e209d39SAndroid Build Coastguard Worker
927*0e209d39SAndroid Build Coastguard Worker /**
928*0e209d39SAndroid Build Coastguard Worker * Copy constructor.
929*0e209d39SAndroid Build Coastguard Worker * @param source the object to be copied.
930*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
931*0e209d39SAndroid Build Coastguard Worker */
932*0e209d39SAndroid Build Coastguard Worker TimeZone(const TimeZone& source);
933*0e209d39SAndroid Build Coastguard Worker
934*0e209d39SAndroid Build Coastguard Worker /**
935*0e209d39SAndroid Build Coastguard Worker * Default assignment operator.
936*0e209d39SAndroid Build Coastguard Worker * @param right the object to be copied.
937*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
938*0e209d39SAndroid Build Coastguard Worker */
939*0e209d39SAndroid Build Coastguard Worker TimeZone& operator=(const TimeZone& right);
940*0e209d39SAndroid Build Coastguard Worker
941*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_INTERNAL_API
942*0e209d39SAndroid Build Coastguard Worker /**
943*0e209d39SAndroid Build Coastguard Worker * Utility function. For internally loading rule data.
944*0e209d39SAndroid Build Coastguard Worker * @param top Top resource bundle for tz data
945*0e209d39SAndroid Build Coastguard Worker * @param ruleid ID of rule to load
946*0e209d39SAndroid Build Coastguard Worker * @param oldbundle Old bundle to reuse or nullptr
947*0e209d39SAndroid Build Coastguard Worker * @param status Status parameter
948*0e209d39SAndroid Build Coastguard Worker * @return either a new bundle or *oldbundle
949*0e209d39SAndroid Build Coastguard Worker * @internal
950*0e209d39SAndroid Build Coastguard Worker */
951*0e209d39SAndroid Build Coastguard Worker static UResourceBundle* loadRule(const UResourceBundle* top, const UnicodeString& ruleid, UResourceBundle* oldbundle, UErrorCode&status);
952*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_INTERNAL_API */
953*0e209d39SAndroid Build Coastguard Worker
954*0e209d39SAndroid Build Coastguard Worker private:
955*0e209d39SAndroid Build Coastguard Worker friend class ZoneMeta;
956*0e209d39SAndroid Build Coastguard Worker
957*0e209d39SAndroid Build Coastguard Worker
958*0e209d39SAndroid Build Coastguard Worker static TimeZone* createCustomTimeZone(const UnicodeString&); // Creates a time zone based on the string.
959*0e209d39SAndroid Build Coastguard Worker
960*0e209d39SAndroid Build Coastguard Worker /**
961*0e209d39SAndroid Build Coastguard Worker * Finds the given ID in the Olson tzdata. If the given ID is found in the tzdata,
962*0e209d39SAndroid Build Coastguard Worker * returns the pointer to the ID resource. This method is exposed through ZoneMeta class
963*0e209d39SAndroid Build Coastguard Worker * for ICU internal implementation and useful for building hashtable using a time zone
964*0e209d39SAndroid Build Coastguard Worker * ID as a key.
965*0e209d39SAndroid Build Coastguard Worker * @param id zone id string
966*0e209d39SAndroid Build Coastguard Worker * @return the pointer of the ID resource, or nullptr.
967*0e209d39SAndroid Build Coastguard Worker */
968*0e209d39SAndroid Build Coastguard Worker static const char16_t* findID(const UnicodeString& id);
969*0e209d39SAndroid Build Coastguard Worker
970*0e209d39SAndroid Build Coastguard Worker /**
971*0e209d39SAndroid Build Coastguard Worker * Resolve a link in Olson tzdata. When the given id is known and it's not a link,
972*0e209d39SAndroid Build Coastguard Worker * the id itself is returned. When the given id is known and it is a link, then
973*0e209d39SAndroid Build Coastguard Worker * dereferenced zone id is returned. When the given id is unknown, then it returns
974*0e209d39SAndroid Build Coastguard Worker * nullptr.
975*0e209d39SAndroid Build Coastguard Worker * @param id zone id string
976*0e209d39SAndroid Build Coastguard Worker * @return the dereferenced zone or nullptr
977*0e209d39SAndroid Build Coastguard Worker */
978*0e209d39SAndroid Build Coastguard Worker static const char16_t* dereferOlsonLink(const UnicodeString& id);
979*0e209d39SAndroid Build Coastguard Worker
980*0e209d39SAndroid Build Coastguard Worker /**
981*0e209d39SAndroid Build Coastguard Worker * Returns the region code associated with the given zone,
982*0e209d39SAndroid Build Coastguard Worker * or nullptr if the zone is not known.
983*0e209d39SAndroid Build Coastguard Worker * @param id zone id string
984*0e209d39SAndroid Build Coastguard Worker * @return the region associated with the given zone
985*0e209d39SAndroid Build Coastguard Worker */
986*0e209d39SAndroid Build Coastguard Worker static const char16_t* getRegion(const UnicodeString& id);
987*0e209d39SAndroid Build Coastguard Worker
988*0e209d39SAndroid Build Coastguard Worker public:
989*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_INTERNAL_API
990*0e209d39SAndroid Build Coastguard Worker /**
991*0e209d39SAndroid Build Coastguard Worker * Returns the region code associated with the given zone,
992*0e209d39SAndroid Build Coastguard Worker * or nullptr if the zone is not known.
993*0e209d39SAndroid Build Coastguard Worker * @param id zone id string
994*0e209d39SAndroid Build Coastguard Worker * @param status Status parameter
995*0e209d39SAndroid Build Coastguard Worker * @return the region associated with the given zone
996*0e209d39SAndroid Build Coastguard Worker * @internal
997*0e209d39SAndroid Build Coastguard Worker */
998*0e209d39SAndroid Build Coastguard Worker static const char16_t* getRegion(const UnicodeString& id, UErrorCode& status);
999*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_INTERNAL_API */
1000*0e209d39SAndroid Build Coastguard Worker
1001*0e209d39SAndroid Build Coastguard Worker private:
1002*0e209d39SAndroid Build Coastguard Worker /**
1003*0e209d39SAndroid Build Coastguard Worker * Parses the given custom time zone identifier
1004*0e209d39SAndroid Build Coastguard Worker * @param id id A string of the form GMT[+-]hh:mm, GMT[+-]hhmm, or
1005*0e209d39SAndroid Build Coastguard Worker * GMT[+-]hh.
1006*0e209d39SAndroid Build Coastguard Worker * @param sign Receives parsed sign, 1 for positive, -1 for negative.
1007*0e209d39SAndroid Build Coastguard Worker * @param hour Receives parsed hour field
1008*0e209d39SAndroid Build Coastguard Worker * @param minute Receives parsed minute field
1009*0e209d39SAndroid Build Coastguard Worker * @param second Receives parsed second field
1010*0e209d39SAndroid Build Coastguard Worker * @return Returns true when the given custom id is valid.
1011*0e209d39SAndroid Build Coastguard Worker */
1012*0e209d39SAndroid Build Coastguard Worker static UBool parseCustomID(const UnicodeString& id, int32_t& sign, int32_t& hour,
1013*0e209d39SAndroid Build Coastguard Worker int32_t& minute, int32_t& second);
1014*0e209d39SAndroid Build Coastguard Worker
1015*0e209d39SAndroid Build Coastguard Worker /**
1016*0e209d39SAndroid Build Coastguard Worker * Parse a custom time zone identifier and return the normalized
1017*0e209d39SAndroid Build Coastguard Worker * custom time zone identifier for the given custom id string.
1018*0e209d39SAndroid Build Coastguard Worker * @param id a string of the form GMT[+-]hh:mm, GMT[+-]hhmm, or
1019*0e209d39SAndroid Build Coastguard Worker * GMT[+-]hh.
1020*0e209d39SAndroid Build Coastguard Worker * @param normalized Receives the normalized custom ID
1021*0e209d39SAndroid Build Coastguard Worker * @param status Receives the status. When the input ID string is invalid,
1022*0e209d39SAndroid Build Coastguard Worker * U_ILLEGAL_ARGUMENT_ERROR is set.
1023*0e209d39SAndroid Build Coastguard Worker * @return The normalized custom id string.
1024*0e209d39SAndroid Build Coastguard Worker */
1025*0e209d39SAndroid Build Coastguard Worker static UnicodeString& getCustomID(const UnicodeString& id, UnicodeString& normalized,
1026*0e209d39SAndroid Build Coastguard Worker UErrorCode& status);
1027*0e209d39SAndroid Build Coastguard Worker
1028*0e209d39SAndroid Build Coastguard Worker /**
1029*0e209d39SAndroid Build Coastguard Worker * Returns the normalized custom time zone ID for the given offset fields.
1030*0e209d39SAndroid Build Coastguard Worker * @param hour offset hours
1031*0e209d39SAndroid Build Coastguard Worker * @param min offset minutes
1032*0e209d39SAndroid Build Coastguard Worker * @param sec offset seconds
1033*0e209d39SAndroid Build Coastguard Worker * @param negative sign of the offset, true for negative offset.
1034*0e209d39SAndroid Build Coastguard Worker * @param id Receives the format result (normalized custom ID)
1035*0e209d39SAndroid Build Coastguard Worker * @return The reference to id
1036*0e209d39SAndroid Build Coastguard Worker */
1037*0e209d39SAndroid Build Coastguard Worker static UnicodeString& formatCustomID(int32_t hour, int32_t min, int32_t sec,
1038*0e209d39SAndroid Build Coastguard Worker UBool negative, UnicodeString& id);
1039*0e209d39SAndroid Build Coastguard Worker
1040*0e209d39SAndroid Build Coastguard Worker UnicodeString fID; // this time zone's ID
1041*0e209d39SAndroid Build Coastguard Worker
1042*0e209d39SAndroid Build Coastguard Worker friend class TZEnumeration;
1043*0e209d39SAndroid Build Coastguard Worker };
1044*0e209d39SAndroid Build Coastguard Worker
1045*0e209d39SAndroid Build Coastguard Worker
1046*0e209d39SAndroid Build Coastguard Worker // -------------------------------------
1047*0e209d39SAndroid Build Coastguard Worker
1048*0e209d39SAndroid Build Coastguard Worker inline UnicodeString&
getID(UnicodeString & ID)1049*0e209d39SAndroid Build Coastguard Worker TimeZone::getID(UnicodeString& ID) const
1050*0e209d39SAndroid Build Coastguard Worker {
1051*0e209d39SAndroid Build Coastguard Worker ID = fID;
1052*0e209d39SAndroid Build Coastguard Worker return ID;
1053*0e209d39SAndroid Build Coastguard Worker }
1054*0e209d39SAndroid Build Coastguard Worker
1055*0e209d39SAndroid Build Coastguard Worker // -------------------------------------
1056*0e209d39SAndroid Build Coastguard Worker
1057*0e209d39SAndroid Build Coastguard Worker inline void
setID(const UnicodeString & ID)1058*0e209d39SAndroid Build Coastguard Worker TimeZone::setID(const UnicodeString& ID)
1059*0e209d39SAndroid Build Coastguard Worker {
1060*0e209d39SAndroid Build Coastguard Worker fID = ID;
1061*0e209d39SAndroid Build Coastguard Worker }
1062*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END
1063*0e209d39SAndroid Build Coastguard Worker
1064*0e209d39SAndroid Build Coastguard Worker #endif /* #if !UCONFIG_NO_FORMATTING */
1065*0e209d39SAndroid Build Coastguard Worker
1066*0e209d39SAndroid Build Coastguard Worker #endif /* U_SHOW_CPLUSPLUS_API */
1067*0e209d39SAndroid Build Coastguard Worker
1068*0e209d39SAndroid Build Coastguard Worker #endif //_TIMEZONE
1069*0e209d39SAndroid Build Coastguard Worker //eof
1070