]> git.saurik.com Git - apple/icu.git/blame - icuSources/i18n/unicode/simpletz.h
ICU-8.11.4.tar.gz
[apple/icu.git] / icuSources / i18n / unicode / simpletz.h
CommitLineData
b75a7d8f 1/*
73c04bcf 2* Copyright (C) {1997-2005}, International Business Machines Corporation and others. All Rights Reserved.
b75a7d8f
A
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
73c04bcf
A
28/**
29 * \file
30 * \brief C++ API: SimpleTimeZone is a concrete subclass of TimeZone.
31 */
32
b75a7d8f
A
33#if !UCONFIG_NO_FORMATTING
34
35#include "unicode/timezone.h"
36
b75a7d8f
A
37U_NAMESPACE_BEGIN
38
b75a7d8f
A
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 */
55class U_I18N_API SimpleTimeZone: public TimeZone {
56public:
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,
374ca955
A
270 * allowing various types of rules to be constructed, as follows:
271 * <ul>
b75a7d8f
A
272 * <li>If both dayOfWeekInMonth and dayOfWeek are positive, they specify the
273 * day of week in the month (e.g., (2, WEDNESDAY) is the second Wednesday
374ca955 274 * of the month).</li>
b75a7d8f
A
275 * <li>If dayOfWeek is positive and dayOfWeekInMonth is negative, they specify
276 * the day of week in the month counting backward from the end of the month.
374ca955 277 * (e.g., (-1, MONDAY) is the last Monday in the month)</li>
b75a7d8f
A
278 * <li>If dayOfWeek is zero and dayOfWeekInMonth is positive, dayOfWeekInMonth
279 * specifies the day of the month, regardless of what day of the week it is.
374ca955 280 * (e.g., (10, 0) is the tenth day of the month)</li>
b75a7d8f
A
281 * <li>If dayOfWeek is zero and dayOfWeekInMonth is negative, dayOfWeekInMonth
282 * specifies the day of the month counting backward from the end of the
283 * month, regardless of what day of the week it is (e.g., (-2, 0) is the
374ca955 284 * next-to-last day of the month).</li>
b75a7d8f
A
285 * <li>If dayOfWeek is negative and dayOfWeekInMonth is positive, they specify the
286 * first specified day of the week on or after the specfied day of the month.
287 * (e.g., (15, -SUNDAY) is the first Sunday after the 15th of the month
374ca955 288 * [or the 15th itself if the 15th is a Sunday].)</li>
b75a7d8f
A
289 * <li>If dayOfWeek and DayOfWeekInMonth are both negative, they specify the
290 * last specified day of the week on or before the specified day of the month.
291 * (e.g., (-20, -TUESDAY) is the last Tuesday before the 20th of the month
374ca955
A
292 * [or the 20th itself if the 20th is a Tuesday].)</li>
293 * </ul>
b75a7d8f
A
294 * @param month the daylight savings starting month. Month is 0-based.
295 * eg, 0 for January.
296 * @param dayOfWeekInMonth the daylight savings starting
297 * day-of-week-in-month. Please see the member description for an example.
298 * @param dayOfWeek the daylight savings starting day-of-week. Please see
299 * the member description for an example.
300 * @param time the daylight savings starting time. Please see the member
301 * description for an example.
302 * @param status An UErrorCode
303 * @stable ICU 2.0
304 */
305 void setStartRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
306 int32_t time, UErrorCode& status);
307 /**
308 * Sets the daylight savings starting rule. For example, in the U.S., Daylight Savings
309 * Time starts at the first Sunday in April, at 2 AM in standard time.
310 * Therefore, you can set the start rule by calling:
311 * setStartRule(TimeFields.APRIL, 1, TimeFields.SUNDAY, 2*60*60*1000);
312 * The dayOfWeekInMonth and dayOfWeek parameters together specify how to calculate
313 * the exact starting date. Their exact meaning depend on their respective signs,
374ca955
A
314 * allowing various types of rules to be constructed, as follows:
315 * <ul>
b75a7d8f
A
316 * <li>If both dayOfWeekInMonth and dayOfWeek are positive, they specify the
317 * day of week in the month (e.g., (2, WEDNESDAY) is the second Wednesday
374ca955 318 * of the month).</li>
b75a7d8f
A
319 * <li>If dayOfWeek is positive and dayOfWeekInMonth is negative, they specify
320 * the day of week in the month counting backward from the end of the month.
374ca955 321 * (e.g., (-1, MONDAY) is the last Monday in the month)</li>
b75a7d8f
A
322 * <li>If dayOfWeek is zero and dayOfWeekInMonth is positive, dayOfWeekInMonth
323 * specifies the day of the month, regardless of what day of the week it is.
374ca955 324 * (e.g., (10, 0) is the tenth day of the month)</li>
b75a7d8f
A
325 * <li>If dayOfWeek is zero and dayOfWeekInMonth is negative, dayOfWeekInMonth
326 * specifies the day of the month counting backward from the end of the
327 * month, regardless of what day of the week it is (e.g., (-2, 0) is the
374ca955 328 * next-to-last day of the month).</li>
b75a7d8f
A
329 * <li>If dayOfWeek is negative and dayOfWeekInMonth is positive, they specify the
330 * first specified day of the week on or after the specfied day of the month.
331 * (e.g., (15, -SUNDAY) is the first Sunday after the 15th of the month
374ca955 332 * [or the 15th itself if the 15th is a Sunday].)</li>
b75a7d8f
A
333 * <li>If dayOfWeek and DayOfWeekInMonth are both negative, they specify the
334 * last specified day of the week on or before the specified day of the month.
335 * (e.g., (-20, -TUESDAY) is the last Tuesday before the 20th of the month
374ca955
A
336 * [or the 20th itself if the 20th is a Tuesday].)</li>
337 * </ul>
b75a7d8f
A
338 * @param month the daylight savings starting month. Month is 0-based.
339 * eg, 0 for January.
340 * @param dayOfWeekInMonth the daylight savings starting
341 * day-of-week-in-month. Please see the member description for an example.
342 * @param dayOfWeek the daylight savings starting day-of-week. Please see
343 * the member description for an example.
344 * @param time the daylight savings starting time. Please see the member
345 * description for an example.
346 * @param mode whether the time is local wall time, local standard time,
347 * or UTC time. Default is local wall time.
348 * @param status An UErrorCode
349 * @stable ICU 2.0
350 */
351 void setStartRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
352 int32_t time, TimeMode mode, UErrorCode& status);
353
354 /**
355 * Sets the DST start rule to a fixed date within a month.
356 *
357 * @param month The month in which this rule occurs (0-based).
358 * @param dayOfMonth The date in that month (1-based).
359 * @param time The time of that day (number of millis after midnight)
360 * when DST takes effect in local wall time, which is
361 * standard time in this case.
362 * @param status An UErrorCode
363 * @stable ICU 2.0
364 */
365 void setStartRule(int32_t month, int32_t dayOfMonth, int32_t time,
366 UErrorCode& status);
367 /**
368 * Sets the DST start rule to a fixed date within a month.
369 *
370 * @param month The month in which this rule occurs (0-based).
371 * @param dayOfMonth The date in that month (1-based).
372 * @param time The time of that day (number of millis after midnight)
373 * when DST takes effect in local wall time, which is
374 * standard time in this case.
375 * @param mode whether the time is local wall time, local standard time,
376 * or UTC time. Default is local wall time.
377 * @param status An UErrorCode
378 * @stable ICU 2.0
379 */
380 void setStartRule(int32_t month, int32_t dayOfMonth, int32_t time,
381 TimeMode mode, UErrorCode& status);
382
383 /**
384 * Sets the DST start rule to a weekday before or after a give date within
385 * a month, e.g., the first Monday on or after the 8th.
386 *
387 * @param month The month in which this rule occurs (0-based).
388 * @param dayOfMonth A date within that month (1-based).
389 * @param dayOfWeek The day of the week on which this rule occurs.
390 * @param time The time of that day (number of millis after midnight)
391 * when DST takes effect in local wall time, which is
392 * standard time in this case.
393 * @param after If true, this rule selects the first dayOfWeek on
394 * or after dayOfMonth. If false, this rule selects
395 * the last dayOfWeek on or before dayOfMonth.
396 * @param status An UErrorCode
397 * @stable ICU 2.0
398 */
399 void setStartRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
400 int32_t time, UBool after, UErrorCode& status);
401 /**
402 * Sets the DST start rule to a weekday before or after a give date within
403 * a month, e.g., the first Monday on or after the 8th.
404 *
405 * @param month The month in which this rule occurs (0-based).
406 * @param dayOfMonth A date within that month (1-based).
407 * @param dayOfWeek The day of the week on which this rule occurs.
408 * @param time The time of that day (number of millis after midnight)
409 * when DST takes effect in local wall time, which is
410 * standard time in this case.
411 * @param mode whether the time is local wall time, local standard time,
412 * or UTC time. Default is local wall time.
413 * @param after If true, this rule selects the first dayOfWeek on
414 * or after dayOfMonth. If false, this rule selects
415 * the last dayOfWeek on or before dayOfMonth.
416 * @param status An UErrorCode
417 * @stable ICU 2.0
418 */
419 void setStartRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
420 int32_t time, TimeMode mode, UBool after, UErrorCode& status);
421
422 /**
423 * Sets the daylight savings ending rule. For example, in the U.S., Daylight
424 * Savings Time ends at the last (-1) Sunday in October, at 2 AM in standard time.
425 * Therefore, you can set the end rule by calling:
426 * <pre>
427 * . setEndRule(TimeFields.OCTOBER, -1, TimeFields.SUNDAY, 2*60*60*1000);
428 * </pre>
429 * Various other types of rules can be specified by manipulating the dayOfWeek
430 * and dayOfWeekInMonth parameters. For complete details, see the documentation
431 * for setStartRule().
432 *
433 * @param month the daylight savings ending month. Month is 0-based.
434 * eg, 0 for January.
435 * @param dayOfWeekInMonth the daylight savings ending
436 * day-of-week-in-month. See setStartRule() for a complete explanation.
437 * @param dayOfWeek the daylight savings ending day-of-week. See setStartRule()
438 * for a complete explanation.
439 * @param time the daylight savings ending time. Please see the member
440 * description for an example.
441 * @param status An UErrorCode
442 * @stable ICU 2.0
443 */
444 void setEndRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
445 int32_t time, UErrorCode& status);
446
447 /**
448 * Sets the daylight savings ending rule. For example, in the U.S., Daylight
449 * Savings Time ends at the last (-1) Sunday in October, at 2 AM in standard time.
450 * Therefore, you can set the end rule by calling:
451 * <pre>
452 * . setEndRule(TimeFields.OCTOBER, -1, TimeFields.SUNDAY, 2*60*60*1000);
453 * </pre>
454 * Various other types of rules can be specified by manipulating the dayOfWeek
455 * and dayOfWeekInMonth parameters. For complete details, see the documentation
456 * for setStartRule().
457 *
458 * @param month the daylight savings ending month. Month is 0-based.
459 * eg, 0 for January.
460 * @param dayOfWeekInMonth the daylight savings ending
461 * day-of-week-in-month. See setStartRule() for a complete explanation.
462 * @param dayOfWeek the daylight savings ending day-of-week. See setStartRule()
463 * for a complete explanation.
464 * @param time the daylight savings ending time. Please see the member
465 * description for an example.
466 * @param mode whether the time is local wall time, local standard time,
467 * or UTC time. Default is local wall time.
468 * @param status An UErrorCode
469 * @stable ICU 2.0
470 */
471 void setEndRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
472 int32_t time, TimeMode mode, UErrorCode& status);
473
474 /**
475 * Sets the DST end rule to a fixed date within a month.
476 *
477 * @param month The month in which this rule occurs (0-based).
478 * @param dayOfMonth The date in that month (1-based).
479 * @param time The time of that day (number of millis after midnight)
480 * when DST ends in local wall time, which is daylight
481 * time in this case.
482 * @param status An UErrorCode
483 * @stable ICU 2.0
484 */
485 void setEndRule(int32_t month, int32_t dayOfMonth, int32_t time, UErrorCode& status);
486
487 /**
488 * Sets the DST end rule to a fixed date within a month.
489 *
490 * @param month The month in which this rule occurs (0-based).
491 * @param dayOfMonth The date in that month (1-based).
492 * @param time The time of that day (number of millis after midnight)
493 * when DST ends in local wall time, which is daylight
494 * time in this case.
495 * @param mode whether the time is local wall time, local standard time,
496 * or UTC time. Default is local wall time.
497 * @param status An UErrorCode
498 * @stable ICU 2.0
499 */
500 void setEndRule(int32_t month, int32_t dayOfMonth, int32_t time,
501 TimeMode mode, UErrorCode& status);
502
503 /**
504 * Sets the DST end rule to a weekday before or after a give date within
505 * a month, e.g., the first Monday on or after the 8th.
506 *
507 * @param month The month in which this rule occurs (0-based).
508 * @param dayOfMonth A date within that month (1-based).
509 * @param dayOfWeek The day of the week on which this rule occurs.
510 * @param time The time of that day (number of millis after midnight)
511 * when DST ends in local wall time, which is daylight
512 * time in this case.
513 * @param after If true, this rule selects the first dayOfWeek on
514 * or after dayOfMonth. If false, this rule selects
515 * the last dayOfWeek on or before dayOfMonth.
516 * @param status An UErrorCode
517 * @stable ICU 2.0
518 */
519 void setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
520 int32_t time, UBool after, UErrorCode& status);
521
522 /**
523 * Sets the DST end rule to a weekday before or after a give date within
524 * a month, e.g., the first Monday on or after the 8th.
525 *
526 * @param month The month in which this rule occurs (0-based).
527 * @param dayOfMonth A date within that month (1-based).
528 * @param dayOfWeek The day of the week on which this rule occurs.
529 * @param time The time of that day (number of millis after midnight)
530 * when DST ends in local wall time, which is daylight
531 * time in this case.
532 * @param mode whether the time is local wall time, local standard time,
533 * or UTC time. Default is local wall time.
534 * @param after If true, this rule selects the first dayOfWeek on
535 * or after dayOfMonth. If false, this rule selects
536 * the last dayOfWeek on or before dayOfMonth.
537 * @param status An UErrorCode
538 * @stable ICU 2.0
539 */
540 void setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
541 int32_t time, TimeMode mode, UBool after, UErrorCode& status);
542
543 /**
544 * Returns the TimeZone's adjusted GMT offset (i.e., the number of milliseconds to add
545 * to GMT to get local time in this time zone, taking daylight savings time into
546 * account) as of a particular reference date. The reference date is used to determine
547 * whether daylight savings time is in effect and needs to be figured into the offset
548 * that is returned (in other words, what is the adjusted GMT offset in this time zone
549 * at this particular date and time?). For the time zones produced by createTimeZone(),
550 * the reference data is specified according to the Gregorian calendar, and the date
551 * and time fields are in GMT, NOT local time.
552 *
553 * @param era The reference date's era
554 * @param year The reference date's year
555 * @param month The reference date's month (0-based; 0 is January)
556 * @param day The reference date's day-in-month (1-based)
557 * @param dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday)
558 * @param millis The reference date's milliseconds in day, UTT (NOT local time).
559 * @param status An UErrorCode to receive the status.
560 * @return The offset in milliseconds to add to GMT to get local time.
561 * @stable ICU 2.0
562 */
563 virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
564 uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const;
565
566 /**
567 * Gets the time zone offset, for current date, modified in case of
568 * daylight savings. This is the offset to add *to* UTC to get local time.
569 * @param era the era of the given date.
570 * @param year the year in the given date.
571 * @param month the month in the given date.
572 * Month is 0-based. e.g., 0 for January.
573 * @param day the day-in-month of the given date.
574 * @param dayOfWeek the day-of-week of the given date.
575 * @param milliseconds the millis in day in <em>standard</em> local time.
576 * @param monthLength the length of the given month in days.
577 * @param status An UErrorCode to receive the status.
578 * @return the offset to add *to* GMT to get local time.
579 * @stable ICU 2.0
580 */
581 virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
582 uint8_t dayOfWeek, int32_t milliseconds,
583 int32_t monthLength, UErrorCode& status) const;
584 /**
585 * Gets the time zone offset, for current date, modified in case of
586 * daylight savings. This is the offset to add *to* UTC to get local time.
587 * @param era the era of the given date.
588 * @param year the year in the given date.
589 * @param month the month in the given date.
590 * Month is 0-based. e.g., 0 for January.
591 * @param day the day-in-month of the given date.
592 * @param dayOfWeek the day-of-week of the given date.
593 * @param milliseconds the millis in day in <em>standard</em> local time.
594 * @param monthLength the length of the given month in days.
595 * @param prevMonthLength length of the previous month in days.
596 * @param status An UErrorCode to receive the status.
597 * @return the offset to add *to* GMT to get local time.
598 * @stable ICU 2.0
599 */
600 virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
601 uint8_t dayOfWeek, int32_t milliseconds,
602 int32_t monthLength, int32_t prevMonthLength,
603 UErrorCode& status) const;
604
374ca955
A
605 /**
606 * Redeclared TimeZone method. This implementation simply calls
607 * the base class method, which otherwise would be hidden.
73c04bcf 608 * @stable ICU 2.8
374ca955
A
609 */
610 virtual void getOffset(UDate date, UBool local, int32_t& rawOffset,
611 int32_t& dstOffset, UErrorCode& ec) const;
612
b75a7d8f
A
613 /**
614 * Returns the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
615 * to GMT to get local time, before taking daylight savings time into account).
616 *
617 * @return The TimeZone's raw GMT offset.
618 * @stable ICU 2.0
619 */
620 virtual int32_t getRawOffset(void) const;
621
622 /**
623 * Sets the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
624 * to GMT to get local time, before taking daylight savings time into account).
625 *
626 * @param offsetMillis The new raw GMT offset for this time zone.
627 * @stable ICU 2.0
628 */
629 virtual void setRawOffset(int32_t offsetMillis);
630
631 /**
632 * Sets the amount of time in ms that the clock is advanced during DST.
633 * @param millisSavedDuringDST the number of milliseconds the time is
634 * advanced with respect to standard time when the daylight savings rules
635 * are in effect. A positive number, typically one hour (3600000).
636 * @param status An UErrorCode to receive the status.
637 * @stable ICU 2.0
638 */
639 void setDSTSavings(int32_t millisSavedDuringDST, UErrorCode& status);
640
641 /**
642 * Returns the amount of time in ms that the clock is advanced during DST.
643 * @return the number of milliseconds the time is
644 * advanced with respect to standard time when the daylight savings rules
645 * are in effect. A positive number, typically one hour (3600000).
646 * @stable ICU 2.0
647 */
73c04bcf 648 virtual int32_t getDSTSavings(void) const;
b75a7d8f
A
649
650 /**
651 * Queries if this TimeZone uses Daylight Savings Time.
652 *
653 * @return True if this TimeZone uses Daylight Savings Time; false otherwise.
654 * @stable ICU 2.0
655 */
656 virtual UBool useDaylightTime(void) const;
657
658 /**
659 * Returns true if the given date is within the period when daylight savings time
660 * is in effect; false otherwise. If the TimeZone doesn't observe daylight savings
661 * time, this functions always returns false.
662 * This method is wasteful since it creates a new GregorianCalendar and
663 * deletes it each time it is called. This is a deprecated method
664 * and provided only for Java compatibility.
665 *
666 * @param date The date to test.
667 * @param status An UErrorCode to receive the status.
668 * @return true if the given date is in Daylight Savings Time;
669 * false otherwise.
670 * @deprecated ICU 2.4. Use Calendar::inDaylightTime() instead.
671 */
672 virtual UBool inDaylightTime(UDate date, UErrorCode& status) const;
673
674 /**
675 * Return true if this zone has the same rules and offset as another zone.
676 * @param other the TimeZone object to be compared with
677 * @return true if the given zone has the same rules and offset as this one
678 * @stable ICU 2.0
679 */
680 UBool hasSameRules(const TimeZone& other) const;
681
682 /**
683 * Clones TimeZone objects polymorphically. Clients are responsible for deleting
684 * the TimeZone object cloned.
685 *
686 * @return A new copy of this TimeZone object.
687 * @stable ICU 2.0
688 */
689 virtual TimeZone* clone(void) const;
690
691public:
692
693 /**
694 * Override TimeZone Returns a unique class ID POLYMORPHICALLY. Pure virtual
695 * override. This method is to implement a simple version of RTTI, since not all C++
696 * compilers support genuine RTTI. Polymorphic operator==() and clone() methods call
697 * this method.
698 *
699 * @return The class ID for this object. All objects of a given class have the
700 * same class ID. Objects of other classes have different class IDs.
701 * @stable ICU 2.0
702 */
703 virtual UClassID getDynamicClassID(void) const;
704
705 /**
706 * Return the class ID for this class. This is useful only for comparing to a return
707 * value from getDynamicClassID(). For example:
708 * <pre>
709 * . Base* polymorphic_pointer = createPolymorphicObject();
710 * . if (polymorphic_pointer->getDynamicClassID() ==
711 * . Derived::getStaticClassID()) ...
712 * </pre>
713 * @return The class ID for all objects of this class.
714 * @stable ICU 2.0
715 */
374ca955 716 static UClassID U_EXPORT2 getStaticClassID(void);
b75a7d8f
A
717
718private:
719 /**
720 * Constants specifying values of startMode and endMode.
721 */
722 enum EMode
723 {
724 DOM_MODE = 1,
725 DOW_IN_MONTH_MODE,
726 DOW_GE_DOM_MODE,
727 DOW_LE_DOM_MODE
728 };
729
b75a7d8f
A
730 SimpleTimeZone(); // default constructor not implemented
731
b75a7d8f
A
732 /**
733 * Internal construction method.
734 * @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset
735 * @param startMonth the month DST starts
736 * @param startDay the day DST starts
737 * @param startDayOfWeek the DOW DST starts
738 * @param startTime the time DST starts
739 * @param startTimeMode Whether the start time is local wall time, local
740 * standard time, or UTC time. Default is local wall time.
741 * @param endMonth the month DST ends
742 * @param endDay the day DST ends
743 * @param endDayOfWeek the DOW DST ends
744 * @param endTime the time DST ends
745 * @param endTimeMode Whether the end time is local wall time, local
746 * standard time, or UTC time. Default is local wall time.
747 * @param savingsDST The number of milliseconds added to standard time
748 * to get DST time. Default is one hour.
749 * @param status An UErrorCode to receive the status.
750 */
751 void construct(int32_t rawOffsetGMT,
752 int8_t startMonth, int8_t startDay, int8_t startDayOfWeek,
753 int32_t startTime, TimeMode startTimeMode,
754 int8_t endMonth, int8_t endDay, int8_t endDayOfWeek,
755 int32_t endTime, TimeMode endTimeMode,
756 int32_t dstSavings, UErrorCode& status);
757
758 /**
759 * Compare a given date in the year to a rule. Return 1, 0, or -1, depending
760 * on whether the date is after, equal to, or before the rule date. The
761 * millis are compared directly against the ruleMillis, so any
762 * standard-daylight adjustments must be handled by the caller.
763 *
764 * @return 1 if the date is after the rule date, -1 if the date is before
765 * the rule date, or 0 if the date is equal to the rule date.
766 */
767 static int32_t compareToRule(int8_t month, int8_t monthLen, int8_t prevMonthLen,
768 int8_t dayOfMonth,
769 int8_t dayOfWeek, int32_t millis, int32_t millisDelta,
770 EMode ruleMode, int8_t ruleMonth, int8_t ruleDayOfWeek,
771 int8_t ruleDay, int32_t ruleMillis);
772
773 /**
774 * Given a set of encoded rules in startDay and startDayOfMonth, decode
775 * them and set the startMode appropriately. Do the same for endDay and
776 * endDayOfMonth.
777 * <P>
778 * Upon entry, the day of week variables may be zero or
779 * negative, in order to indicate special modes. The day of month
780 * variables may also be negative.
781 * <P>
782 * Upon exit, the mode variables will be
783 * set, and the day of week and day of month variables will be positive.
784 * <P>
785 * This method also recognizes a startDay or endDay of zero as indicating
786 * no DST.
787 */
788 void decodeRules(UErrorCode& status);
789 void decodeStartRule(UErrorCode& status);
790 void decodeEndRule(UErrorCode& status);
791
b75a7d8f
A
792 int8_t startMonth, startDay, startDayOfWeek; // the month, day, DOW, and time DST starts
793 int32_t startTime;
794 TimeMode startTimeMode, endTimeMode; // Mode for startTime, endTime; see TimeMode
795 int8_t endMonth, endDay, endDayOfWeek; // the month, day, DOW, and time DST ends
796 int32_t endTime;
797 int32_t startYear; // the year these DST rules took effect
798 int32_t rawOffset; // the TimeZone's raw GMT offset
799 UBool useDaylight; // flag indicating whether this TimeZone uses DST
374ca955 800 static const int8_t STATICMONTHLENGTH[12]; // lengths of the months
b75a7d8f
A
801 EMode startMode, endMode; // flags indicating what kind of rules the DST rules are
802
803 /**
804 * A positive value indicating the amount of time saved during DST in ms.
805 * Typically one hour; sometimes 30 minutes.
806 */
807 int32_t dstSavings;
808};
809
b75a7d8f
A
810inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfWeekInMonth,
811 int32_t dayOfWeek,
812 int32_t time, UErrorCode& status) {
813 setStartRule(month, dayOfWeekInMonth, dayOfWeek, time, WALL_TIME, status);
814}
815
816inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfMonth,
817 int32_t time,
818 UErrorCode& status) {
819 setStartRule(month, dayOfMonth, time, WALL_TIME, status);
820}
821
822inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfMonth,
823 int32_t dayOfWeek,
824 int32_t time, UBool after, UErrorCode& status) {
825 setStartRule(month, dayOfMonth, dayOfWeek, time, WALL_TIME, after, status);
826}
827
828inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfWeekInMonth,
829 int32_t dayOfWeek,
830 int32_t time, UErrorCode& status) {
831 setEndRule(month, dayOfWeekInMonth, dayOfWeek, time, WALL_TIME, status);
832}
833
834inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfMonth,
835 int32_t time, UErrorCode& status) {
836 setEndRule(month, dayOfMonth, time, WALL_TIME, status);
837}
838
839inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
840 int32_t time, UBool after, UErrorCode& status) {
841 setEndRule(month, dayOfMonth, dayOfWeek, time, WALL_TIME, after, status);
842}
843
374ca955
A
844inline void
845SimpleTimeZone::getOffset(UDate date, UBool local, int32_t& rawOffsetRef,
846 int32_t& dstOffsetRef, UErrorCode& ec) const {
847 TimeZone::getOffset(date, local, rawOffsetRef, dstOffsetRef, ec);
848}
849
b75a7d8f
A
850U_NAMESPACE_END
851
852#endif /* #if !UCONFIG_NO_FORMATTING */
853
854#endif // _SIMPLETZ