]>
git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/olsontz.h
2 **********************************************************************
3 * Copyright (c) 2003-2004, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
7 * Created: July 21 2003
9 **********************************************************************
14 #include "unicode/utypes.h"
16 #if !UCONFIG_NO_FORMATTING
18 #include "unicode/timezone.h"
20 struct UResourceBundle
;
27 * A time zone based on the Olson database. Olson time zones change
28 * behavior over time. The raw offset, rules, presence or absence of
29 * daylight savings time, and even the daylight savings amount can all
32 * This class uses a resource bundle named "zoneinfo". Zoneinfo is a
33 * table containing different kinds of resources. In several places,
34 * zones are referred to using integers. A zone's integer is a number
35 * from 0..n-1, where n is the number of zones, with the zones sorted
36 * in lexicographic order.
38 * 1. Zones. These have keys corresponding to the Olson IDs, e.g.,
39 * "Asia/Shanghai". Each resource describes the behavior of the given
40 * zone. Zones come in several formats, which are differentiated
43 * a. Alias (int, length 1). An alias zone is an int resource. The
44 * integer is the zone number of the target zone. The key of this
45 * resource is an alternate name for the target zone. Aliases
46 * represent Olson links and ICU compatibility IDs.
48 * b. Simple zone (array, length 3). The three subelements are:
50 * i. An intvector of transitions. These are given in epoch
51 * seconds. This may be an empty invector (length 0). If the
52 * transtions list is empty, then the zone's behavior is fixed and
53 * given by the offset list, which will contain exactly one pair.
54 * Otherwise each transtion indicates a time after which (inclusive)
55 * the associated offset pair is in effect.
57 * ii. An intvector of offsets. These are in pairs of raw offset /
58 * DST offset, in units of seconds. There will be at least one pair
59 * (length >= 2 && length % 2 == 0).
61 * iii. A binary resource. This is of the same length as the
62 * transitions vector, so length may be zero. Each unsigned byte
63 * corresponds to one transition, and has a value of 0..n-1, where n
64 * is the number of pairs in the offset vector. This forms a map
65 * between transitions and offset pairs.
67 * c. Simple zone with aliases (array, length 4). This is like a
68 * simple zone, but also contains a fourth element:
70 * iv. An intvector of aliases. This list includes this zone
71 * itself, and lists all aliases of this zone.
73 * d. Complex zone (array, length 5). This is like a simple zone,
74 * but contains two more elements:
76 * iv. A string, giving the name of a rule. This is the "final
77 * rule", which governs the zone's behavior beginning in the "final
78 * year". The rule ID is given without leading underscore, e.g.,
81 * v. An intvector of length 2, containing the raw offset for the
82 * final rule (in seconds), and the final year. The final rule
83 * takes effect for years >= the final year.
85 * e. Complex zone with aliases (array, length 6). This is like a
86 * complex zone, but also contains a sixth element:
88 * vi. An intvector of aliases. This list includes this zone
89 * itself, and lists all aliases of this zone.
91 * 2. Rules. These have keys corresponding to the Olson rule IDs,
92 * with an underscore prepended, e.g., "_EU". Each resource describes
93 * the behavior of the given rule using an intvector, containing the
94 * onset list, the cessation list, and the DST savings. The onset and
95 * cessation lists consist of the month, dowim, dow, time, and time
96 * mode. The end result is that the 11 integers describing the rule
97 * can be passed directly into the SimpleTimeZone 13-argument
98 * constructor (the other two arguments will be the raw offset, taken
99 * from the complex zone element 5, and the ID string, which is not
100 * used), with the times and the DST savings multiplied by 1000 to
101 * scale from seconds to milliseconds.
103 * 3. Countries. These have keys corresponding to the 2-letter ISO
104 * country codes, with a percent sign prepended, e.g., "%US". Each
105 * resource is an intvector listing the zones associated with the
106 * given country. The special entry "%" corresponds to "no country",
107 * that is, the category of zones assigned to no country in the Olson
110 * 4. Metadata. Metadata is stored under the key "_". It is an
111 * intvector of length three containing the number of zones resources,
112 * rule resources, and country resources. For the purposes of this
113 * count, the metadata entry itself is considered a rule resource,
114 * since its key begins with an underscore.
116 class U_I18N_API OlsonTimeZone
: public TimeZone
{
119 * Construct from a resource bundle.
120 * @param top the top-level zoneinfo resource bundle. This is used
121 * to lookup the rule that `res' may refer to, if there is one.
122 * @param res the resource bundle of the zone to be constructed
123 * @param ec input-output error code
125 OlsonTimeZone(const UResourceBundle
* top
,
126 const UResourceBundle
* res
, UErrorCode
& ec
);
131 OlsonTimeZone(const OlsonTimeZone
& other
);
136 virtual ~OlsonTimeZone();
139 * Assignment operator
141 OlsonTimeZone
& operator=(const OlsonTimeZone
& other
);
144 * Returns true if the two TimeZone objects are equal.
146 virtual UBool
operator==(const TimeZone
& other
) const;
151 virtual TimeZone
* clone() const;
156 static UClassID U_EXPORT2
getStaticClassID();
161 virtual UClassID
getDynamicClassID() const;
164 * TimeZone API. Do not call this; prefer getOffset(UDate,...).
166 virtual int32_t getOffset(uint8_t era
, int32_t year
, int32_t month
,
167 int32_t day
, uint8_t dayOfWeek
,
168 int32_t millis
, UErrorCode
& ec
) const;
171 * TimeZone API. Do not call this; prefer getOffset(UDate,...).
173 virtual int32_t getOffset(uint8_t era
, int32_t year
, int32_t month
,
174 int32_t day
, uint8_t dayOfWeek
,
175 int32_t millis
, int32_t monthLength
,
176 UErrorCode
& ec
) const;
181 virtual void getOffset(UDate date
, UBool local
, int32_t& rawOffset
,
182 int32_t& dstOffset
, UErrorCode
& ec
) const;
185 * TimeZone API. This method has no effect since objects of this
186 * class are quasi-immutable (the base class allows the ID to be
189 virtual void setRawOffset(int32_t offsetMillis
);
192 * TimeZone API. For a historical zone, the raw offset can change
193 * over time, so this API is not useful. In order to approximate
194 * expected behavior, this method returns the raw offset for the
195 * current moment in time.
197 virtual int32_t getRawOffset() const;
200 * TimeZone API. For a historical zone, whether DST is used or
201 * not varies over time. In order to approximate expected
202 * behavior, this method returns TRUE if DST is observed at any
203 * point in the current year.
205 virtual UBool
useDaylightTime() const;
210 virtual UBool
inDaylightTime(UDate date
, UErrorCode
& ec
) const;
214 * Default constructor. Creates a time zone with an empty ID and
215 * a fixed GMT offset of zero.
221 void constructEmpty();
223 int16_t findTransition(double time
, UBool local
) const;
225 int32_t zoneOffset(int16_t index
) const;
226 int32_t rawOffset(int16_t index
) const;
227 int32_t dstOffset(int16_t index
) const;
230 * Number of transitions, 0..~370
232 int16_t transitionCount
;
235 * Number of types, 1..255
240 * Time of each transition in seconds from 1970 epoch.
241 * Length is transitionCount int32_t's.
243 const int32_t *transitionTimes
; // alias into res; do not delete
246 * Offset from GMT in seconds for each type.
247 * Length is typeCount int32_t's.
249 const int32_t *typeOffsets
; // alias into res; do not delete
252 * Type description data, consisting of transitionCount uint8_t
253 * type indices (from 0..typeCount-1).
254 * Length is transitionCount int8_t's.
256 const uint8_t *typeData
; // alias into res; do not delete
259 * The last year for which the transitions data are to be used
260 * rather than the finalZone. If there is no finalZone, then this
261 * is set to INT32_MAX. NOTE: This corresponds to the year _before_
262 * the one indicated by finalMillis.
267 * The millis for the start of the first year for which finalZone
268 * is to be used, or DBL_MAX if finalZone is 0. NOTE: This is
269 * 0:00 GMT Jan 1, <finalYear + 1> (not <finalMillis>).
274 * A SimpleTimeZone that governs the behavior for years > finalYear.
275 * If and only if finalYear == INT32_MAX then finalZone == 0.
277 SimpleTimeZone
*finalZone
; // owned, may be NULL
282 OlsonTimeZone::zoneOffset(int16_t index
) const {
284 return typeOffsets
[index
] + typeOffsets
[index
+1];
288 OlsonTimeZone::rawOffset(int16_t index
) const {
289 return typeOffsets
[(uint32_t)(index
<< 1)];
293 OlsonTimeZone::dstOffset(int16_t index
) const {
294 return typeOffsets
[(uint32_t)((index
<< 1) + 1)];
299 #endif // !UCONFIG_NO_FORMATTING