]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /* |
2 | * Copyright (C) {1997-2003}, International Business Machines Corporation and others. All Rights Reserved. | |
3 | * * | |
4 | ******************************************************************************** | |
5 | * | |
6 | * File SIMPLETZ.H | |
7 | * | |
8 | * Modification History: | |
9 | * | |
10 | * Date Name Description | |
11 | * 04/21/97 aliu Overhauled header. | |
12 | * 08/10/98 stephen JDK 1.2 sync | |
13 | * Added setStartRule() / setEndRule() overloads | |
14 | * Added hasSameRules() | |
15 | * 09/02/98 stephen Added getOffset(monthLen) | |
16 | * Changed getOffset() to take UErrorCode | |
17 | * 07/09/99 stephen Removed millisPerHour (unused, for HP compiler) | |
18 | * 12/02/99 aliu Added TimeMode and constructor and setStart/EndRule | |
19 | * methods that take TimeMode. Added to docs. | |
20 | ******************************************************************************** | |
21 | */ | |
22 | ||
23 | #ifndef SIMPLETZ_H | |
24 | #define SIMPLETZ_H | |
25 | ||
26 | #include "unicode/utypes.h" | |
27 | ||
28 | #if !UCONFIG_NO_FORMATTING | |
29 | ||
30 | #include "unicode/timezone.h" | |
31 | ||
32 | struct StandardZone; | |
33 | struct DSTZone; | |
34 | ||
35 | U_NAMESPACE_BEGIN | |
36 | ||
37 | class TimeZone; | |
38 | ||
39 | /** | |
40 | * <code>SimpleTimeZone</code> is a concrete subclass of <code>TimeZone</code> | |
41 | * that represents a time zone for use with a Gregorian calendar. This | |
42 | * class does not handle historical changes. | |
43 | * <P> | |
44 | * When specifying daylight-savings-time begin and end dates, use a negative value for | |
45 | * <code>dayOfWeekInMonth</code> to indicate that <code>SimpleTimeZone</code> should | |
46 | * count from the end of the month backwards. For example, in the U.S., Daylight Savings | |
47 | * Time ends at the last (dayOfWeekInMonth = -1) Sunday in October, at 2 AM in standard | |
48 | * time. | |
49 | * | |
50 | * @see Calendar | |
51 | * @see GregorianCalendar | |
52 | * @see TimeZone | |
53 | * @author D. Goldsmith, Mark Davis, Chen-Lieh Huang, Alan Liu | |
54 | */ | |
55 | class U_I18N_API SimpleTimeZone: public TimeZone { | |
56 | public: | |
57 | ||
58 | /** | |
59 | * TimeMode is used, together with a millisecond offset after | |
60 | * midnight, to specify a rule transition time. Most rules | |
61 | * transition at a local wall time, that is, according to the | |
62 | * current time in effect, either standard, or DST. However, some | |
63 | * rules transition at local standard time, and some at a specific | |
64 | * UTC time. Although it might seem that all times could be | |
65 | * converted to wall time, thus eliminating the need for this | |
66 | * parameter, this is not the case. | |
67 | * @stable ICU 2.0 | |
68 | */ | |
69 | enum TimeMode { | |
70 | WALL_TIME = 0, | |
71 | STANDARD_TIME, | |
72 | UTC_TIME | |
73 | }; | |
74 | ||
75 | /** | |
76 | * Copy constructor | |
77 | * @param source the object to be copied. | |
78 | * @stable ICU 2.0 | |
79 | */ | |
80 | SimpleTimeZone(const SimpleTimeZone& source); | |
81 | ||
82 | /** | |
83 | * Default assignment operator | |
84 | * @param right the object to be copied. | |
85 | * @stable ICU 2.0 | |
86 | */ | |
87 | SimpleTimeZone& operator=(const SimpleTimeZone& right); | |
88 | ||
89 | /** | |
90 | * Destructor | |
91 | * @stable ICU 2.0 | |
92 | */ | |
93 | virtual ~SimpleTimeZone(); | |
94 | ||
95 | /** | |
96 | * Returns true if the two TimeZone objects are equal; that is, they have | |
97 | * the same ID, raw GMT offset, and DST rules. | |
98 | * | |
99 | * @param that The SimpleTimeZone object to be compared with. | |
100 | * @return True if the given time zone is equal to this time zone; false | |
101 | * otherwise. | |
102 | * @stable ICU 2.0 | |
103 | */ | |
104 | virtual UBool operator==(const TimeZone& that) const; | |
105 | ||
106 | /** | |
107 | * Constructs a SimpleTimeZone with the given raw GMT offset and time zone ID, | |
108 | * and which doesn't observe daylight savings time. Normally you should use | |
109 | * TimeZone::createInstance() to create a TimeZone instead of creating a | |
110 | * SimpleTimeZone directly with this constructor. | |
111 | * | |
112 | * @param rawOffsetGMT The given base time zone offset to GMT. | |
113 | * @param ID The timezone ID which is obtained from | |
114 | * TimeZone.getAvailableIDs. | |
115 | * @stable ICU 2.0 | |
116 | */ | |
117 | SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID); | |
118 | ||
119 | /** | |
120 | * Construct a SimpleTimeZone with the given raw GMT offset, time zone ID, | |
121 | * and times to start and end daylight savings time. To create a TimeZone that | |
122 | * doesn't observe daylight savings time, don't use this constructor; use | |
123 | * SimpleTimeZone(rawOffset, ID) instead. Normally, you should use | |
124 | * TimeZone.createInstance() to create a TimeZone instead of creating a | |
125 | * SimpleTimeZone directly with this constructor. | |
126 | * <P> | |
127 | * Various types of daylight-savings time rules can be specfied by using different | |
128 | * values for startDay and startDayOfWeek and endDay and endDayOfWeek. For a | |
129 | * complete explanation of how these parameters work, see the documentation for | |
130 | * setStartRule(). | |
131 | * | |
132 | * @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset | |
133 | * @param ID The new SimpleTimeZone's time zone ID. | |
134 | * @param savingsStartMonth The daylight savings starting month. Month is | |
135 | * 0-based. eg, 0 for January. | |
136 | * @param savingsStartDayOfWeekInMonth The daylight savings starting | |
137 | * day-of-week-in-month. See setStartRule() for a | |
138 | * complete explanation. | |
139 | * @param savingsStartDayOfWeek The daylight savings starting day-of-week. | |
140 | * See setStartRule() for a complete explanation. | |
141 | * @param savingsStartTime The daylight savings starting time, expressed as the | |
142 | * number of milliseconds after midnight. | |
143 | * @param savingsEndMonth The daylight savings ending month. Month is | |
144 | * 0-based. eg, 0 for January. | |
145 | * @param savingsEndDayOfWeekInMonth The daylight savings ending day-of-week-in-month. | |
146 | * See setStartRule() for a complete explanation. | |
147 | * @param savingsEndDayOfWeek The daylight savings ending day-of-week. | |
148 | * See setStartRule() for a complete explanation. | |
149 | * @param savingsEndTime The daylight savings ending time, expressed as the | |
150 | * number of milliseconds after midnight. | |
151 | * @param status An UErrorCode to receive the status. | |
152 | * @stable ICU 2.0 | |
153 | */ | |
154 | SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID, | |
155 | int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth, | |
156 | int8_t savingsStartDayOfWeek, int32_t savingsStartTime, | |
157 | int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth, | |
158 | int8_t savingsEndDayOfWeek, int32_t savingsEndTime, | |
159 | UErrorCode& status); | |
160 | /** | |
161 | * Construct a SimpleTimeZone with the given raw GMT offset, time zone ID, | |
162 | * and times to start and end daylight savings time. To create a TimeZone that | |
163 | * doesn't observe daylight savings time, don't use this constructor; use | |
164 | * SimpleTimeZone(rawOffset, ID) instead. Normally, you should use | |
165 | * TimeZone.createInstance() to create a TimeZone instead of creating a | |
166 | * SimpleTimeZone directly with this constructor. | |
167 | * <P> | |
168 | * Various types of daylight-savings time rules can be specfied by using different | |
169 | * values for startDay and startDayOfWeek and endDay and endDayOfWeek. For a | |
170 | * complete explanation of how these parameters work, see the documentation for | |
171 | * setStartRule(). | |
172 | * | |
173 | * @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset | |
174 | * @param ID The new SimpleTimeZone's time zone ID. | |
175 | * @param savingsStartMonth The daylight savings starting month. Month is | |
176 | * 0-based. eg, 0 for January. | |
177 | * @param savingsStartDayOfWeekInMonth The daylight savings starting | |
178 | * day-of-week-in-month. See setStartRule() for a | |
179 | * complete explanation. | |
180 | * @param savingsStartDayOfWeek The daylight savings starting day-of-week. | |
181 | * See setStartRule() for a complete explanation. | |
182 | * @param savingsStartTime The daylight savings starting time, expressed as the | |
183 | * number of milliseconds after midnight. | |
184 | * @param savingsEndMonth The daylight savings ending month. Month is | |
185 | * 0-based. eg, 0 for January. | |
186 | * @param savingsEndDayOfWeekInMonth The daylight savings ending day-of-week-in-month. | |
187 | * See setStartRule() for a complete explanation. | |
188 | * @param savingsEndDayOfWeek The daylight savings ending day-of-week. | |
189 | * See setStartRule() for a complete explanation. | |
190 | * @param savingsEndTime The daylight savings ending time, expressed as the | |
191 | * number of milliseconds after midnight. | |
192 | * @param savingsDST The number of milliseconds added to standard time | |
193 | * to get DST time. Default is one hour. | |
194 | * @param status An UErrorCode to receive the status. | |
195 | * @stable ICU 2.0 | |
196 | */ | |
197 | SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID, | |
198 | int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth, | |
199 | int8_t savingsStartDayOfWeek, int32_t savingsStartTime, | |
200 | int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth, | |
201 | int8_t savingsEndDayOfWeek, int32_t savingsEndTime, | |
202 | int32_t savingsDST, UErrorCode& status); | |
203 | ||
204 | /** | |
205 | * Construct a SimpleTimeZone with the given raw GMT offset, time zone ID, | |
206 | * and times to start and end daylight savings time. To create a TimeZone that | |
207 | * doesn't observe daylight savings time, don't use this constructor; use | |
208 | * SimpleTimeZone(rawOffset, ID) instead. Normally, you should use | |
209 | * TimeZone.createInstance() to create a TimeZone instead of creating a | |
210 | * SimpleTimeZone directly with this constructor. | |
211 | * <P> | |
212 | * Various types of daylight-savings time rules can be specfied by using different | |
213 | * values for startDay and startDayOfWeek and endDay and endDayOfWeek. For a | |
214 | * complete explanation of how these parameters work, see the documentation for | |
215 | * setStartRule(). | |
216 | * | |
217 | * @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset | |
218 | * @param ID The new SimpleTimeZone's time zone ID. | |
219 | * @param savingsStartMonth The daylight savings starting month. Month is | |
220 | * 0-based. eg, 0 for January. | |
221 | * @param savingsStartDayOfWeekInMonth The daylight savings starting | |
222 | * day-of-week-in-month. See setStartRule() for a | |
223 | * complete explanation. | |
224 | * @param savingsStartDayOfWeek The daylight savings starting day-of-week. | |
225 | * See setStartRule() for a complete explanation. | |
226 | * @param savingsStartTime The daylight savings starting time, expressed as the | |
227 | * number of milliseconds after midnight. | |
228 | * @param savingsStartTimeMode Whether the start time is local wall time, local | |
229 | * standard time, or UTC time. Default is local wall time. | |
230 | * @param savingsEndMonth The daylight savings ending month. Month is | |
231 | * 0-based. eg, 0 for January. | |
232 | * @param savingsEndDayOfWeekInMonth The daylight savings ending day-of-week-in-month. | |
233 | * See setStartRule() for a complete explanation. | |
234 | * @param savingsEndDayOfWeek The daylight savings ending day-of-week. | |
235 | * See setStartRule() for a complete explanation. | |
236 | * @param savingsEndTime The daylight savings ending time, expressed as the | |
237 | * number of milliseconds after midnight. | |
238 | * @param savingsEndTimeMode Whether the end time is local wall time, local | |
239 | * standard time, or UTC time. Default is local wall time. | |
240 | * @param savingsDST The number of milliseconds added to standard time | |
241 | * to get DST time. Default is one hour. | |
242 | * @param status An UErrorCode to receive the status. | |
243 | * @stable ICU 2.0 | |
244 | */ | |
245 | SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID, | |
246 | int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth, | |
247 | int8_t savingsStartDayOfWeek, int32_t savingsStartTime, | |
248 | TimeMode savingsStartTimeMode, | |
249 | int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth, | |
250 | int8_t savingsEndDayOfWeek, int32_t savingsEndTime, TimeMode savingsEndTimeMode, | |
251 | int32_t savingsDST, UErrorCode& status); | |
252 | ||
253 | /** | |
254 | * Sets the daylight savings starting year, that is, the year this time zone began | |
255 | * observing its specified daylight savings time rules. The time zone is considered | |
256 | * not to observe daylight savings time prior to that year; SimpleTimeZone doesn't | |
257 | * support historical daylight-savings-time rules. | |
258 | * @param year the daylight savings starting year. | |
259 | * @stable ICU 2.0 | |
260 | */ | |
261 | void setStartYear(int32_t year); | |
262 | ||
263 | /** | |
264 | * Sets the daylight savings starting rule. For example, in the U.S., Daylight Savings | |
265 | * Time starts at the first Sunday in April, at 2 AM in standard time. | |
266 | * Therefore, you can set the start rule by calling: | |
267 | * setStartRule(TimeFields.APRIL, 1, TimeFields.SUNDAY, 2*60*60*1000); | |
268 | * The dayOfWeekInMonth and dayOfWeek parameters together specify how to calculate | |
269 | * the exact starting date. Their exact meaning depend on their respective signs, | |
270 | * allowing various types of rules to be constructed, as follows:<ul> | |
271 | * <li>If both dayOfWeekInMonth and dayOfWeek are positive, they specify the | |
272 | * day of week in the month (e.g., (2, WEDNESDAY) is the second Wednesday | |
273 | * of the month). | |
274 | * <li>If dayOfWeek is positive and dayOfWeekInMonth is negative, they specify | |
275 | * the day of week in the month counting backward from the end of the month. | |
276 | * (e.g., (-1, MONDAY) is the last Monday in the month) | |
277 | * <li>If dayOfWeek is zero and dayOfWeekInMonth is positive, dayOfWeekInMonth | |
278 | * specifies the day of the month, regardless of what day of the week it is. | |
279 | * (e.g., (10, 0) is the tenth day of the month) | |
280 | * <li>If dayOfWeek is zero and dayOfWeekInMonth is negative, dayOfWeekInMonth | |
281 | * specifies the day of the month counting backward from the end of the | |
282 | * month, regardless of what day of the week it is (e.g., (-2, 0) is the | |
283 | * next-to-last day of the month). | |
284 | * <li>If dayOfWeek is negative and dayOfWeekInMonth is positive, they specify the | |
285 | * first specified day of the week on or after the specfied day of the month. | |
286 | * (e.g., (15, -SUNDAY) is the first Sunday after the 15th of the month | |
287 | * [or the 15th itself if the 15th is a Sunday].) | |
288 | * <li>If dayOfWeek and DayOfWeekInMonth are both negative, they specify the | |
289 | * last specified day of the week on or before the specified day of the month. | |
290 | * (e.g., (-20, -TUESDAY) is the last Tuesday before the 20th of the month | |
291 | * [or the 20th itself if the 20th is a Tuesday].)</ul> | |
292 | * @param month the daylight savings starting month. Month is 0-based. | |
293 | * eg, 0 for January. | |
294 | * @param dayOfWeekInMonth the daylight savings starting | |
295 | * day-of-week-in-month. Please see the member description for an example. | |
296 | * @param dayOfWeek the daylight savings starting day-of-week. Please see | |
297 | * the member description for an example. | |
298 | * @param time the daylight savings starting time. Please see the member | |
299 | * description for an example. | |
300 | * @param status An UErrorCode | |
301 | * @stable ICU 2.0 | |
302 | */ | |
303 | void setStartRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek, | |
304 | int32_t time, UErrorCode& status); | |
305 | /** | |
306 | * Sets the daylight savings starting rule. For example, in the U.S., Daylight Savings | |
307 | * Time starts at the first Sunday in April, at 2 AM in standard time. | |
308 | * Therefore, you can set the start rule by calling: | |
309 | * setStartRule(TimeFields.APRIL, 1, TimeFields.SUNDAY, 2*60*60*1000); | |
310 | * The dayOfWeekInMonth and dayOfWeek parameters together specify how to calculate | |
311 | * the exact starting date. Their exact meaning depend on their respective signs, | |
312 | * allowing various types of rules to be constructed, as follows:<ul> | |
313 | * <li>If both dayOfWeekInMonth and dayOfWeek are positive, they specify the | |
314 | * day of week in the month (e.g., (2, WEDNESDAY) is the second Wednesday | |
315 | * of the month). | |
316 | * <li>If dayOfWeek is positive and dayOfWeekInMonth is negative, they specify | |
317 | * the day of week in the month counting backward from the end of the month. | |
318 | * (e.g., (-1, MONDAY) is the last Monday in the month) | |
319 | * <li>If dayOfWeek is zero and dayOfWeekInMonth is positive, dayOfWeekInMonth | |
320 | * specifies the day of the month, regardless of what day of the week it is. | |
321 | * (e.g., (10, 0) is the tenth day of the month) | |
322 | * <li>If dayOfWeek is zero and dayOfWeekInMonth is negative, dayOfWeekInMonth | |
323 | * specifies the day of the month counting backward from the end of the | |
324 | * month, regardless of what day of the week it is (e.g., (-2, 0) is the | |
325 | * next-to-last day of the month). | |
326 | * <li>If dayOfWeek is negative and dayOfWeekInMonth is positive, they specify the | |
327 | * first specified day of the week on or after the specfied day of the month. | |
328 | * (e.g., (15, -SUNDAY) is the first Sunday after the 15th of the month | |
329 | * [or the 15th itself if the 15th is a Sunday].) | |
330 | * <li>If dayOfWeek and DayOfWeekInMonth are both negative, they specify the | |
331 | * last specified day of the week on or before the specified day of the month. | |
332 | * (e.g., (-20, -TUESDAY) is the last Tuesday before the 20th of the month | |
333 | * [or the 20th itself if the 20th is a Tuesday].)</ul> | |
334 | * @param month the daylight savings starting month. Month is 0-based. | |
335 | * eg, 0 for January. | |
336 | * @param dayOfWeekInMonth the daylight savings starting | |
337 | * day-of-week-in-month. Please see the member description for an example. | |
338 | * @param dayOfWeek the daylight savings starting day-of-week. Please see | |
339 | * the member description for an example. | |
340 | * @param time the daylight savings starting time. Please see the member | |
341 | * description for an example. | |
342 | * @param mode whether the time is local wall time, local standard time, | |
343 | * or UTC time. Default is local wall time. | |
344 | * @param status An UErrorCode | |
345 | * @stable ICU 2.0 | |
346 | */ | |
347 | void setStartRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek, | |
348 | int32_t time, TimeMode mode, UErrorCode& status); | |
349 | ||
350 | /** | |
351 | * Sets the DST start rule to a fixed date within a month. | |
352 | * | |
353 | * @param month The month in which this rule occurs (0-based). | |
354 | * @param dayOfMonth The date in that month (1-based). | |
355 | * @param time The time of that day (number of millis after midnight) | |
356 | * when DST takes effect in local wall time, which is | |
357 | * standard time in this case. | |
358 | * @param status An UErrorCode | |
359 | * @stable ICU 2.0 | |
360 | */ | |
361 | void setStartRule(int32_t month, int32_t dayOfMonth, int32_t time, | |
362 | UErrorCode& status); | |
363 | /** | |
364 | * Sets the DST start rule to a fixed date within a month. | |
365 | * | |
366 | * @param month The month in which this rule occurs (0-based). | |
367 | * @param dayOfMonth The date in that month (1-based). | |
368 | * @param time The time of that day (number of millis after midnight) | |
369 | * when DST takes effect in local wall time, which is | |
370 | * standard time in this case. | |
371 | * @param mode whether the time is local wall time, local standard time, | |
372 | * or UTC time. Default is local wall time. | |
373 | * @param status An UErrorCode | |
374 | * @stable ICU 2.0 | |
375 | */ | |
376 | void setStartRule(int32_t month, int32_t dayOfMonth, int32_t time, | |
377 | TimeMode mode, UErrorCode& status); | |
378 | ||
379 | /** | |
380 | * Sets the DST start rule to a weekday before or after a give date within | |
381 | * a month, e.g., the first Monday on or after the 8th. | |
382 | * | |
383 | * @param month The month in which this rule occurs (0-based). | |
384 | * @param dayOfMonth A date within that month (1-based). | |
385 | * @param dayOfWeek The day of the week on which this rule occurs. | |
386 | * @param time The time of that day (number of millis after midnight) | |
387 | * when DST takes effect in local wall time, which is | |
388 | * standard time in this case. | |
389 | * @param after If true, this rule selects the first dayOfWeek on | |
390 | * or after dayOfMonth. If false, this rule selects | |
391 | * the last dayOfWeek on or before dayOfMonth. | |
392 | * @param status An UErrorCode | |
393 | * @stable ICU 2.0 | |
394 | */ | |
395 | void setStartRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek, | |
396 | int32_t time, UBool after, UErrorCode& status); | |
397 | /** | |
398 | * Sets the DST start rule to a weekday before or after a give date within | |
399 | * a month, e.g., the first Monday on or after the 8th. | |
400 | * | |
401 | * @param month The month in which this rule occurs (0-based). | |
402 | * @param dayOfMonth A date within that month (1-based). | |
403 | * @param dayOfWeek The day of the week on which this rule occurs. | |
404 | * @param time The time of that day (number of millis after midnight) | |
405 | * when DST takes effect in local wall time, which is | |
406 | * standard time in this case. | |
407 | * @param mode whether the time is local wall time, local standard time, | |
408 | * or UTC time. Default is local wall time. | |
409 | * @param after If true, this rule selects the first dayOfWeek on | |
410 | * or after dayOfMonth. If false, this rule selects | |
411 | * the last dayOfWeek on or before dayOfMonth. | |
412 | * @param status An UErrorCode | |
413 | * @stable ICU 2.0 | |
414 | */ | |
415 | void setStartRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek, | |
416 | int32_t time, TimeMode mode, UBool after, UErrorCode& status); | |
417 | ||
418 | /** | |
419 | * Sets the daylight savings ending rule. For example, in the U.S., Daylight | |
420 | * Savings Time ends at the last (-1) Sunday in October, at 2 AM in standard time. | |
421 | * Therefore, you can set the end rule by calling: | |
422 | * <pre> | |
423 | * . setEndRule(TimeFields.OCTOBER, -1, TimeFields.SUNDAY, 2*60*60*1000); | |
424 | * </pre> | |
425 | * Various other types of rules can be specified by manipulating the dayOfWeek | |
426 | * and dayOfWeekInMonth parameters. For complete details, see the documentation | |
427 | * for setStartRule(). | |
428 | * | |
429 | * @param month the daylight savings ending month. Month is 0-based. | |
430 | * eg, 0 for January. | |
431 | * @param dayOfWeekInMonth the daylight savings ending | |
432 | * day-of-week-in-month. See setStartRule() for a complete explanation. | |
433 | * @param dayOfWeek the daylight savings ending day-of-week. See setStartRule() | |
434 | * for a complete explanation. | |
435 | * @param time the daylight savings ending time. Please see the member | |
436 | * description for an example. | |
437 | * @param status An UErrorCode | |
438 | * @stable ICU 2.0 | |
439 | */ | |
440 | void setEndRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek, | |
441 | int32_t time, UErrorCode& status); | |
442 | ||
443 | /** | |
444 | * Sets the daylight savings ending rule. For example, in the U.S., Daylight | |
445 | * Savings Time ends at the last (-1) Sunday in October, at 2 AM in standard time. | |
446 | * Therefore, you can set the end rule by calling: | |
447 | * <pre> | |
448 | * . setEndRule(TimeFields.OCTOBER, -1, TimeFields.SUNDAY, 2*60*60*1000); | |
449 | * </pre> | |
450 | * Various other types of rules can be specified by manipulating the dayOfWeek | |
451 | * and dayOfWeekInMonth parameters. For complete details, see the documentation | |
452 | * for setStartRule(). | |
453 | * | |
454 | * @param month the daylight savings ending month. Month is 0-based. | |
455 | * eg, 0 for January. | |
456 | * @param dayOfWeekInMonth the daylight savings ending | |
457 | * day-of-week-in-month. See setStartRule() for a complete explanation. | |
458 | * @param dayOfWeek the daylight savings ending day-of-week. See setStartRule() | |
459 | * for a complete explanation. | |
460 | * @param time the daylight savings ending time. Please see the member | |
461 | * description for an example. | |
462 | * @param mode whether the time is local wall time, local standard time, | |
463 | * or UTC time. Default is local wall time. | |
464 | * @param status An UErrorCode | |
465 | * @stable ICU 2.0 | |
466 | */ | |
467 | void setEndRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek, | |
468 | int32_t time, TimeMode mode, UErrorCode& status); | |
469 | ||
470 | /** | |
471 | * Sets the DST end rule to a fixed date within a month. | |
472 | * | |
473 | * @param month The month in which this rule occurs (0-based). | |
474 | * @param dayOfMonth The date in that month (1-based). | |
475 | * @param time The time of that day (number of millis after midnight) | |
476 | * when DST ends in local wall time, which is daylight | |
477 | * time in this case. | |
478 | * @param status An UErrorCode | |
479 | * @stable ICU 2.0 | |
480 | */ | |
481 | void setEndRule(int32_t month, int32_t dayOfMonth, int32_t time, UErrorCode& status); | |
482 | ||
483 | /** | |
484 | * Sets the DST end rule to a fixed date within a month. | |
485 | * | |
486 | * @param month The month in which this rule occurs (0-based). | |
487 | * @param dayOfMonth The date in that month (1-based). | |
488 | * @param time The time of that day (number of millis after midnight) | |
489 | * when DST ends in local wall time, which is daylight | |
490 | * time in this case. | |
491 | * @param mode whether the time is local wall time, local standard time, | |
492 | * or UTC time. Default is local wall time. | |
493 | * @param status An UErrorCode | |
494 | * @stable ICU 2.0 | |
495 | */ | |
496 | void setEndRule(int32_t month, int32_t dayOfMonth, int32_t time, | |
497 | TimeMode mode, UErrorCode& status); | |
498 | ||
499 | /** | |
500 | * Sets the DST end rule to a weekday before or after a give date within | |
501 | * a month, e.g., the first Monday on or after the 8th. | |
502 | * | |
503 | * @param month The month in which this rule occurs (0-based). | |
504 | * @param dayOfMonth A date within that month (1-based). | |
505 | * @param dayOfWeek The day of the week on which this rule occurs. | |
506 | * @param time The time of that day (number of millis after midnight) | |
507 | * when DST ends in local wall time, which is daylight | |
508 | * time in this case. | |
509 | * @param after If true, this rule selects the first dayOfWeek on | |
510 | * or after dayOfMonth. If false, this rule selects | |
511 | * the last dayOfWeek on or before dayOfMonth. | |
512 | * @param status An UErrorCode | |
513 | * @stable ICU 2.0 | |
514 | */ | |
515 | void setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek, | |
516 | int32_t time, UBool after, UErrorCode& status); | |
517 | ||
518 | /** | |
519 | * Sets the DST end rule to a weekday before or after a give date within | |
520 | * a month, e.g., the first Monday on or after the 8th. | |
521 | * | |
522 | * @param month The month in which this rule occurs (0-based). | |
523 | * @param dayOfMonth A date within that month (1-based). | |
524 | * @param dayOfWeek The day of the week on which this rule occurs. | |
525 | * @param time The time of that day (number of millis after midnight) | |
526 | * when DST ends in local wall time, which is daylight | |
527 | * time in this case. | |
528 | * @param mode whether the time is local wall time, local standard time, | |
529 | * or UTC time. Default is local wall time. | |
530 | * @param after If true, this rule selects the first dayOfWeek on | |
531 | * or after dayOfMonth. If false, this rule selects | |
532 | * the last dayOfWeek on or before dayOfMonth. | |
533 | * @param status An UErrorCode | |
534 | * @stable ICU 2.0 | |
535 | */ | |
536 | void setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek, | |
537 | int32_t time, TimeMode mode, UBool after, UErrorCode& status); | |
538 | ||
539 | /** | |
540 | * Returns the TimeZone's adjusted GMT offset (i.e., the number of milliseconds to add | |
541 | * to GMT to get local time in this time zone, taking daylight savings time into | |
542 | * account) as of a particular reference date. The reference date is used to determine | |
543 | * whether daylight savings time is in effect and needs to be figured into the offset | |
544 | * that is returned (in other words, what is the adjusted GMT offset in this time zone | |
545 | * at this particular date and time?). For the time zones produced by createTimeZone(), | |
546 | * the reference data is specified according to the Gregorian calendar, and the date | |
547 | * and time fields are in GMT, NOT local time. | |
548 | * | |
549 | * @param era The reference date's era | |
550 | * @param year The reference date's year | |
551 | * @param month The reference date's month (0-based; 0 is January) | |
552 | * @param day The reference date's day-in-month (1-based) | |
553 | * @param dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday) | |
554 | * @param millis The reference date's milliseconds in day, UTT (NOT local time). | |
555 | * @param status An UErrorCode to receive the status. | |
556 | * @return The offset in milliseconds to add to GMT to get local time. | |
557 | * @stable ICU 2.0 | |
558 | */ | |
559 | virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day, | |
560 | uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const; | |
561 | ||
562 | /** | |
563 | * Gets the time zone offset, for current date, modified in case of | |
564 | * daylight savings. This is the offset to add *to* UTC to get local time. | |
565 | * @param era the era of the given date. | |
566 | * @param year the year in the given date. | |
567 | * @param month the month in the given date. | |
568 | * Month is 0-based. e.g., 0 for January. | |
569 | * @param day the day-in-month of the given date. | |
570 | * @param dayOfWeek the day-of-week of the given date. | |
571 | * @param milliseconds the millis in day in <em>standard</em> local time. | |
572 | * @param monthLength the length of the given month in days. | |
573 | * @param status An UErrorCode to receive the status. | |
574 | * @return the offset to add *to* GMT to get local time. | |
575 | * @stable ICU 2.0 | |
576 | */ | |
577 | virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day, | |
578 | uint8_t dayOfWeek, int32_t milliseconds, | |
579 | int32_t monthLength, UErrorCode& status) const; | |
580 | /** | |
581 | * Gets the time zone offset, for current date, modified in case of | |
582 | * daylight savings. This is the offset to add *to* UTC to get local time. | |
583 | * @param era the era of the given date. | |
584 | * @param year the year in the given date. | |
585 | * @param month the month in the given date. | |
586 | * Month is 0-based. e.g., 0 for January. | |
587 | * @param day the day-in-month of the given date. | |
588 | * @param dayOfWeek the day-of-week of the given date. | |
589 | * @param milliseconds the millis in day in <em>standard</em> local time. | |
590 | * @param monthLength the length of the given month in days. | |
591 | * @param prevMonthLength length of the previous month in days. | |
592 | * @param status An UErrorCode to receive the status. | |
593 | * @return the offset to add *to* GMT to get local time. | |
594 | * @stable ICU 2.0 | |
595 | */ | |
596 | virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day, | |
597 | uint8_t dayOfWeek, int32_t milliseconds, | |
598 | int32_t monthLength, int32_t prevMonthLength, | |
599 | UErrorCode& status) const; | |
600 | ||
601 | /** | |
602 | * Returns the TimeZone's raw GMT offset (i.e., the number of milliseconds to add | |
603 | * to GMT to get local time, before taking daylight savings time into account). | |
604 | * | |
605 | * @return The TimeZone's raw GMT offset. | |
606 | * @stable ICU 2.0 | |
607 | */ | |
608 | virtual int32_t getRawOffset(void) const; | |
609 | ||
610 | /** | |
611 | * Sets the TimeZone's raw GMT offset (i.e., the number of milliseconds to add | |
612 | * to GMT to get local time, before taking daylight savings time into account). | |
613 | * | |
614 | * @param offsetMillis The new raw GMT offset for this time zone. | |
615 | * @stable ICU 2.0 | |
616 | */ | |
617 | virtual void setRawOffset(int32_t offsetMillis); | |
618 | ||
619 | /** | |
620 | * Sets the amount of time in ms that the clock is advanced during DST. | |
621 | * @param millisSavedDuringDST the number of milliseconds the time is | |
622 | * advanced with respect to standard time when the daylight savings rules | |
623 | * are in effect. A positive number, typically one hour (3600000). | |
624 | * @param status An UErrorCode to receive the status. | |
625 | * @stable ICU 2.0 | |
626 | */ | |
627 | void setDSTSavings(int32_t millisSavedDuringDST, UErrorCode& status); | |
628 | ||
629 | /** | |
630 | * Returns the amount of time in ms that the clock is advanced during DST. | |
631 | * @return the number of milliseconds the time is | |
632 | * advanced with respect to standard time when the daylight savings rules | |
633 | * are in effect. A positive number, typically one hour (3600000). | |
634 | * @stable ICU 2.0 | |
635 | */ | |
636 | int32_t getDSTSavings(void) const; | |
637 | ||
638 | /** | |
639 | * Queries if this TimeZone uses Daylight Savings Time. | |
640 | * | |
641 | * @return True if this TimeZone uses Daylight Savings Time; false otherwise. | |
642 | * @stable ICU 2.0 | |
643 | */ | |
644 | virtual UBool useDaylightTime(void) const; | |
645 | ||
646 | /** | |
647 | * Returns true if the given date is within the period when daylight savings time | |
648 | * is in effect; false otherwise. If the TimeZone doesn't observe daylight savings | |
649 | * time, this functions always returns false. | |
650 | * This method is wasteful since it creates a new GregorianCalendar and | |
651 | * deletes it each time it is called. This is a deprecated method | |
652 | * and provided only for Java compatibility. | |
653 | * | |
654 | * @param date The date to test. | |
655 | * @param status An UErrorCode to receive the status. | |
656 | * @return true if the given date is in Daylight Savings Time; | |
657 | * false otherwise. | |
658 | * @deprecated ICU 2.4. Use Calendar::inDaylightTime() instead. | |
659 | */ | |
660 | virtual UBool inDaylightTime(UDate date, UErrorCode& status) const; | |
661 | ||
662 | /** | |
663 | * Return true if this zone has the same rules and offset as another zone. | |
664 | * @param other the TimeZone object to be compared with | |
665 | * @return true if the given zone has the same rules and offset as this one | |
666 | * @stable ICU 2.0 | |
667 | */ | |
668 | UBool hasSameRules(const TimeZone& other) const; | |
669 | ||
670 | /** | |
671 | * Clones TimeZone objects polymorphically. Clients are responsible for deleting | |
672 | * the TimeZone object cloned. | |
673 | * | |
674 | * @return A new copy of this TimeZone object. | |
675 | * @stable ICU 2.0 | |
676 | */ | |
677 | virtual TimeZone* clone(void) const; | |
678 | ||
679 | public: | |
680 | ||
681 | /** | |
682 | * Override TimeZone Returns a unique class ID POLYMORPHICALLY. Pure virtual | |
683 | * override. This method is to implement a simple version of RTTI, since not all C++ | |
684 | * compilers support genuine RTTI. Polymorphic operator==() and clone() methods call | |
685 | * this method. | |
686 | * | |
687 | * @return The class ID for this object. All objects of a given class have the | |
688 | * same class ID. Objects of other classes have different class IDs. | |
689 | * @stable ICU 2.0 | |
690 | */ | |
691 | virtual UClassID getDynamicClassID(void) const; | |
692 | ||
693 | /** | |
694 | * Return the class ID for this class. This is useful only for comparing to a return | |
695 | * value from getDynamicClassID(). For example: | |
696 | * <pre> | |
697 | * . Base* polymorphic_pointer = createPolymorphicObject(); | |
698 | * . if (polymorphic_pointer->getDynamicClassID() == | |
699 | * . Derived::getStaticClassID()) ... | |
700 | * </pre> | |
701 | * @return The class ID for all objects of this class. | |
702 | * @stable ICU 2.0 | |
703 | */ | |
704 | static UClassID getStaticClassID(void); | |
705 | ||
706 | private: | |
707 | /** | |
708 | * Constants specifying values of startMode and endMode. | |
709 | */ | |
710 | enum EMode | |
711 | { | |
712 | DOM_MODE = 1, | |
713 | DOW_IN_MONTH_MODE, | |
714 | DOW_GE_DOM_MODE, | |
715 | DOW_LE_DOM_MODE | |
716 | }; | |
717 | ||
718 | friend class TimeZone; // for access to these 2 constructors: | |
719 | ||
720 | SimpleTimeZone(); // default constructor not implemented | |
721 | ||
722 | /** | |
723 | * Construct from memory-mapped data. | |
724 | */ | |
725 | SimpleTimeZone(const StandardZone& stdZone, const UnicodeString& id); | |
726 | SimpleTimeZone(const DSTZone& dstZone, const UnicodeString& id); | |
727 | ||
728 | /** | |
729 | * Internal construction method. | |
730 | * @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset | |
731 | * @param startMonth the month DST starts | |
732 | * @param startDay the day DST starts | |
733 | * @param startDayOfWeek the DOW DST starts | |
734 | * @param startTime the time DST starts | |
735 | * @param startTimeMode Whether the start time is local wall time, local | |
736 | * standard time, or UTC time. Default is local wall time. | |
737 | * @param endMonth the month DST ends | |
738 | * @param endDay the day DST ends | |
739 | * @param endDayOfWeek the DOW DST ends | |
740 | * @param endTime the time DST ends | |
741 | * @param endTimeMode Whether the end time is local wall time, local | |
742 | * standard time, or UTC time. Default is local wall time. | |
743 | * @param savingsDST The number of milliseconds added to standard time | |
744 | * to get DST time. Default is one hour. | |
745 | * @param status An UErrorCode to receive the status. | |
746 | */ | |
747 | void construct(int32_t rawOffsetGMT, | |
748 | int8_t startMonth, int8_t startDay, int8_t startDayOfWeek, | |
749 | int32_t startTime, TimeMode startTimeMode, | |
750 | int8_t endMonth, int8_t endDay, int8_t endDayOfWeek, | |
751 | int32_t endTime, TimeMode endTimeMode, | |
752 | int32_t dstSavings, UErrorCode& status); | |
753 | ||
754 | /** | |
755 | * Compare a given date in the year to a rule. Return 1, 0, or -1, depending | |
756 | * on whether the date is after, equal to, or before the rule date. The | |
757 | * millis are compared directly against the ruleMillis, so any | |
758 | * standard-daylight adjustments must be handled by the caller. | |
759 | * | |
760 | * @return 1 if the date is after the rule date, -1 if the date is before | |
761 | * the rule date, or 0 if the date is equal to the rule date. | |
762 | */ | |
763 | static int32_t compareToRule(int8_t month, int8_t monthLen, int8_t prevMonthLen, | |
764 | int8_t dayOfMonth, | |
765 | int8_t dayOfWeek, int32_t millis, int32_t millisDelta, | |
766 | EMode ruleMode, int8_t ruleMonth, int8_t ruleDayOfWeek, | |
767 | int8_t ruleDay, int32_t ruleMillis); | |
768 | ||
769 | /** | |
770 | * Given a set of encoded rules in startDay and startDayOfMonth, decode | |
771 | * them and set the startMode appropriately. Do the same for endDay and | |
772 | * endDayOfMonth. | |
773 | * <P> | |
774 | * Upon entry, the day of week variables may be zero or | |
775 | * negative, in order to indicate special modes. The day of month | |
776 | * variables may also be negative. | |
777 | * <P> | |
778 | * Upon exit, the mode variables will be | |
779 | * set, and the day of week and day of month variables will be positive. | |
780 | * <P> | |
781 | * This method also recognizes a startDay or endDay of zero as indicating | |
782 | * no DST. | |
783 | */ | |
784 | void decodeRules(UErrorCode& status); | |
785 | void decodeStartRule(UErrorCode& status); | |
786 | void decodeEndRule(UErrorCode& status); | |
787 | ||
788 | static const char fgClassID; | |
789 | ||
790 | int8_t startMonth, startDay, startDayOfWeek; // the month, day, DOW, and time DST starts | |
791 | int32_t startTime; | |
792 | TimeMode startTimeMode, endTimeMode; // Mode for startTime, endTime; see TimeMode | |
793 | int8_t endMonth, endDay, endDayOfWeek; // the month, day, DOW, and time DST ends | |
794 | int32_t endTime; | |
795 | int32_t startYear; // the year these DST rules took effect | |
796 | int32_t rawOffset; // the TimeZone's raw GMT offset | |
797 | UBool useDaylight; // flag indicating whether this TimeZone uses DST | |
798 | static const int8_t staticMonthLength[12]; // lengths of the months | |
799 | EMode startMode, endMode; // flags indicating what kind of rules the DST rules are | |
800 | ||
801 | /** | |
802 | * A positive value indicating the amount of time saved during DST in ms. | |
803 | * Typically one hour; sometimes 30 minutes. | |
804 | */ | |
805 | int32_t dstSavings; | |
806 | }; | |
807 | ||
808 | inline UClassID | |
809 | SimpleTimeZone::getStaticClassID(void) | |
810 | { return (UClassID)&fgClassID; } | |
811 | ||
812 | inline UClassID | |
813 | SimpleTimeZone::getDynamicClassID(void) const | |
814 | { return SimpleTimeZone::getStaticClassID(); } | |
815 | ||
816 | inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfWeekInMonth, | |
817 | int32_t dayOfWeek, | |
818 | int32_t time, UErrorCode& status) { | |
819 | setStartRule(month, dayOfWeekInMonth, dayOfWeek, time, WALL_TIME, status); | |
820 | } | |
821 | ||
822 | inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfMonth, | |
823 | int32_t time, | |
824 | UErrorCode& status) { | |
825 | setStartRule(month, dayOfMonth, time, WALL_TIME, status); | |
826 | } | |
827 | ||
828 | inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfMonth, | |
829 | int32_t dayOfWeek, | |
830 | int32_t time, UBool after, UErrorCode& status) { | |
831 | setStartRule(month, dayOfMonth, dayOfWeek, time, WALL_TIME, after, status); | |
832 | } | |
833 | ||
834 | inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfWeekInMonth, | |
835 | int32_t dayOfWeek, | |
836 | int32_t time, UErrorCode& status) { | |
837 | setEndRule(month, dayOfWeekInMonth, dayOfWeek, time, WALL_TIME, status); | |
838 | } | |
839 | ||
840 | inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfMonth, | |
841 | int32_t time, UErrorCode& status) { | |
842 | setEndRule(month, dayOfMonth, time, WALL_TIME, status); | |
843 | } | |
844 | ||
845 | inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek, | |
846 | int32_t time, UBool after, UErrorCode& status) { | |
847 | setEndRule(month, dayOfMonth, dayOfWeek, time, WALL_TIME, after, status); | |
848 | } | |
849 | ||
850 | U_NAMESPACE_END | |
851 | ||
852 | #endif /* #if !UCONFIG_NO_FORMATTING */ | |
853 | ||
854 | #endif // _SIMPLETZ |