2
********************************************************************************
3
* Copyright (C) 1997-2009, International Business Machines *
4
* Corporation and others. All Rights Reserved. *
5
********************************************************************************
9
* Modification History:
11
* Date Name Description
12
* 04/21/97 aliu Overhauled header.
13
* 08/10/98 stephen JDK 1.2 sync
14
* Added setStartRule() / setEndRule() overloads
15
* Added hasSameRules()
16
* 09/02/98 stephen Added getOffset(monthLen)
17
* Changed getOffset() to take UErrorCode
18
* 07/09/99 stephen Removed millisPerHour (unused, for HP compiler)
19
* 12/02/99 aliu Added TimeMode and constructor and setStart/EndRule
20
* methods that take TimeMode. Added to docs.
21
********************************************************************************
27
#include "unicode/utypes.h"
31
* \brief C++ API: SimpleTimeZone is a concrete subclass of TimeZone.
34
#if !UCONFIG_NO_FORMATTING
36
#include "unicode/basictz.h"
40
// forward declaration
41
class InitialTimeZoneRule;
42
class TimeZoneTransition;
43
class AnnualTimeZoneRule;
46
* <code>SimpleTimeZone</code> is a concrete subclass of <code>TimeZone</code>
47
* that represents a time zone for use with a Gregorian calendar. This
48
* class does not handle historical changes.
50
* When specifying daylight-savings-time begin and end dates, use a negative value for
51
* <code>dayOfWeekInMonth</code> to indicate that <code>SimpleTimeZone</code> should
52
* count from the end of the month backwards. For example, if Daylight Savings
53
* Time starts or ends at the last Sunday a month, use <code>dayOfWeekInMonth = -1</code>
54
* along with <code>dayOfWeek = UCAL_SUNDAY</code> to specify the rule.
57
* @see GregorianCalendar
59
* @author D. Goldsmith, Mark Davis, Chen-Lieh Huang, Alan Liu
61
class U_I18N_API SimpleTimeZone: public BasicTimeZone {
65
* TimeMode is used, together with a millisecond offset after
66
* midnight, to specify a rule transition time. Most rules
67
* transition at a local wall time, that is, according to the
68
* current time in effect, either standard, or DST. However, some
69
* rules transition at local standard time, and some at a specific
70
* UTC time. Although it might seem that all times could be
71
* converted to wall time, thus eliminating the need for this
72
* parameter, this is not the case.
83
* @param source the object to be copied.
86
SimpleTimeZone(const SimpleTimeZone& source);
89
* Default assignment operator
90
* @param right the object to be copied.
93
SimpleTimeZone& operator=(const SimpleTimeZone& right);
99
virtual ~SimpleTimeZone();
102
* Returns true if the two TimeZone objects are equal; that is, they have
103
* the same ID, raw GMT offset, and DST rules.
105
* @param that The SimpleTimeZone object to be compared with.
106
* @return True if the given time zone is equal to this time zone; false
110
virtual UBool operator==(const TimeZone& that) const;
113
* Constructs a SimpleTimeZone with the given raw GMT offset and time zone ID,
114
* and which doesn't observe daylight savings time. Normally you should use
115
* TimeZone::createInstance() to create a TimeZone instead of creating a
116
* SimpleTimeZone directly with this constructor.
118
* @param rawOffsetGMT The given base time zone offset to GMT.
119
* @param ID The timezone ID which is obtained from
120
* TimeZone.getAvailableIDs.
123
SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID);
126
* Construct a SimpleTimeZone with the given raw GMT offset, time zone ID,
127
* and times to start and end daylight savings time. To create a TimeZone that
128
* doesn't observe daylight savings time, don't use this constructor; use
129
* SimpleTimeZone(rawOffset, ID) instead. Normally, you should use
130
* TimeZone.createInstance() to create a TimeZone instead of creating a
131
* SimpleTimeZone directly with this constructor.
133
* Various types of daylight-savings time rules can be specfied by using different
134
* values for startDay and startDayOfWeek and endDay and endDayOfWeek. For a
135
* complete explanation of how these parameters work, see the documentation for
138
* @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset
139
* @param ID The new SimpleTimeZone's time zone ID.
140
* @param savingsStartMonth The daylight savings starting month. Month is
141
* 0-based. eg, 0 for January.
142
* @param savingsStartDayOfWeekInMonth The daylight savings starting
143
* day-of-week-in-month. See setStartRule() for a
144
* complete explanation.
145
* @param savingsStartDayOfWeek The daylight savings starting day-of-week.
146
* See setStartRule() for a complete explanation.
147
* @param savingsStartTime The daylight savings starting time, expressed as the
148
* number of milliseconds after midnight.
149
* @param savingsEndMonth The daylight savings ending month. Month is
150
* 0-based. eg, 0 for January.
151
* @param savingsEndDayOfWeekInMonth The daylight savings ending day-of-week-in-month.
152
* See setStartRule() for a complete explanation.
153
* @param savingsEndDayOfWeek The daylight savings ending day-of-week.
154
* See setStartRule() for a complete explanation.
155
* @param savingsEndTime The daylight savings ending time, expressed as the
156
* number of milliseconds after midnight.
157
* @param status An UErrorCode to receive the status.
160
SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID,
161
int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth,
162
int8_t savingsStartDayOfWeek, int32_t savingsStartTime,
163
int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth,
164
int8_t savingsEndDayOfWeek, int32_t savingsEndTime,
167
* Construct a SimpleTimeZone with the given raw GMT offset, time zone ID,
168
* and times to start and end daylight savings time. To create a TimeZone that
169
* doesn't observe daylight savings time, don't use this constructor; use
170
* SimpleTimeZone(rawOffset, ID) instead. Normally, you should use
171
* TimeZone.createInstance() to create a TimeZone instead of creating a
172
* SimpleTimeZone directly with this constructor.
174
* Various types of daylight-savings time rules can be specfied by using different
175
* values for startDay and startDayOfWeek and endDay and endDayOfWeek. For a
176
* complete explanation of how these parameters work, see the documentation for
179
* @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset
180
* @param ID The new SimpleTimeZone's time zone ID.
181
* @param savingsStartMonth The daylight savings starting month. Month is
182
* 0-based. eg, 0 for January.
183
* @param savingsStartDayOfWeekInMonth The daylight savings starting
184
* day-of-week-in-month. See setStartRule() for a
185
* complete explanation.
186
* @param savingsStartDayOfWeek The daylight savings starting day-of-week.
187
* See setStartRule() for a complete explanation.
188
* @param savingsStartTime The daylight savings starting time, expressed as the
189
* number of milliseconds after midnight.
190
* @param savingsEndMonth The daylight savings ending month. Month is
191
* 0-based. eg, 0 for January.
192
* @param savingsEndDayOfWeekInMonth The daylight savings ending day-of-week-in-month.
193
* See setStartRule() for a complete explanation.
194
* @param savingsEndDayOfWeek The daylight savings ending day-of-week.
195
* See setStartRule() for a complete explanation.
196
* @param savingsEndTime The daylight savings ending time, expressed as the
197
* number of milliseconds after midnight.
198
* @param savingsDST The number of milliseconds added to standard time
199
* to get DST time. Default is one hour.
200
* @param status An UErrorCode to receive the status.
203
SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID,
204
int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth,
205
int8_t savingsStartDayOfWeek, int32_t savingsStartTime,
206
int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth,
207
int8_t savingsEndDayOfWeek, int32_t savingsEndTime,
208
int32_t savingsDST, UErrorCode& status);
211
* Construct a SimpleTimeZone with the given raw GMT offset, time zone ID,
212
* and times to start and end daylight savings time. To create a TimeZone that
213
* doesn't observe daylight savings time, don't use this constructor; use
214
* SimpleTimeZone(rawOffset, ID) instead. Normally, you should use
215
* TimeZone.createInstance() to create a TimeZone instead of creating a
216
* SimpleTimeZone directly with this constructor.
218
* Various types of daylight-savings time rules can be specfied by using different
219
* values for startDay and startDayOfWeek and endDay and endDayOfWeek. For a
220
* complete explanation of how these parameters work, see the documentation for
223
* @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset
224
* @param ID The new SimpleTimeZone's time zone ID.
225
* @param savingsStartMonth The daylight savings starting month. Month is
226
* 0-based. eg, 0 for January.
227
* @param savingsStartDayOfWeekInMonth The daylight savings starting
228
* day-of-week-in-month. See setStartRule() for a
229
* complete explanation.
230
* @param savingsStartDayOfWeek The daylight savings starting day-of-week.
231
* See setStartRule() for a complete explanation.
232
* @param savingsStartTime The daylight savings starting time, expressed as the
233
* number of milliseconds after midnight.
234
* @param savingsStartTimeMode Whether the start time is local wall time, local
235
* standard time, or UTC time. Default is local wall time.
236
* @param savingsEndMonth The daylight savings ending month. Month is
237
* 0-based. eg, 0 for January.
238
* @param savingsEndDayOfWeekInMonth The daylight savings ending day-of-week-in-month.
239
* See setStartRule() for a complete explanation.
240
* @param savingsEndDayOfWeek The daylight savings ending day-of-week.
241
* See setStartRule() for a complete explanation.
242
* @param savingsEndTime The daylight savings ending time, expressed as the
243
* number of milliseconds after midnight.
244
* @param savingsEndTimeMode Whether the end time is local wall time, local
245
* standard time, or UTC time. Default is local wall time.
246
* @param savingsDST The number of milliseconds added to standard time
247
* to get DST time. Default is one hour.
248
* @param status An UErrorCode to receive the status.
251
SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID,
252
int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth,
253
int8_t savingsStartDayOfWeek, int32_t savingsStartTime,
254
TimeMode savingsStartTimeMode,
255
int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth,
256
int8_t savingsEndDayOfWeek, int32_t savingsEndTime, TimeMode savingsEndTimeMode,
257
int32_t savingsDST, UErrorCode& status);
260
* Sets the daylight savings starting year, that is, the year this time zone began
261
* observing its specified daylight savings time rules. The time zone is considered
262
* not to observe daylight savings time prior to that year; SimpleTimeZone doesn't
263
* support historical daylight-savings-time rules.
264
* @param year the daylight savings starting year.
267
void setStartYear(int32_t year);
270
* Sets the daylight savings starting rule. For example, in the U.S., Daylight Savings
271
* Time starts at the second Sunday in March, at 2 AM in standard time.
272
* Therefore, you can set the start rule by calling:
273
* setStartRule(UCAL_MARCH, 2, UCAL_SUNDAY, 2*60*60*1000);
274
* The dayOfWeekInMonth and dayOfWeek parameters together specify how to calculate
275
* the exact starting date. Their exact meaning depend on their respective signs,
276
* allowing various types of rules to be constructed, as follows:
278
* <li>If both dayOfWeekInMonth and dayOfWeek are positive, they specify the
279
* day of week in the month (e.g., (2, WEDNESDAY) is the second Wednesday
280
* of the month).</li>
281
* <li>If dayOfWeek is positive and dayOfWeekInMonth is negative, they specify
282
* the day of week in the month counting backward from the end of the month.
283
* (e.g., (-1, MONDAY) is the last Monday in the month)</li>
284
* <li>If dayOfWeek is zero and dayOfWeekInMonth is positive, dayOfWeekInMonth
285
* specifies the day of the month, regardless of what day of the week it is.
286
* (e.g., (10, 0) is the tenth day of the month)</li>
287
* <li>If dayOfWeek is zero and dayOfWeekInMonth is negative, dayOfWeekInMonth
288
* specifies the day of the month counting backward from the end of the
289
* month, regardless of what day of the week it is (e.g., (-2, 0) is the
290
* next-to-last day of the month).</li>
291
* <li>If dayOfWeek is negative and dayOfWeekInMonth is positive, they specify the
292
* first specified day of the week on or after the specfied day of the month.
293
* (e.g., (15, -SUNDAY) is the first Sunday after the 15th of the month
294
* [or the 15th itself if the 15th is a Sunday].)</li>
295
* <li>If dayOfWeek and DayOfWeekInMonth are both negative, they specify the
296
* last specified day of the week on or before the specified day of the month.
297
* (e.g., (-20, -TUESDAY) is the last Tuesday before the 20th of the month
298
* [or the 20th itself if the 20th is a Tuesday].)</li>
300
* @param month the daylight savings starting month. Month is 0-based.
302
* @param dayOfWeekInMonth the daylight savings starting
303
* day-of-week-in-month. Please see the member description for an example.
304
* @param dayOfWeek the daylight savings starting day-of-week. Please see
305
* the member description for an example.
306
* @param time the daylight savings starting time. Please see the member
307
* description for an example.
308
* @param status An UErrorCode
311
void setStartRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
312
int32_t time, UErrorCode& status);
314
* Sets the daylight savings starting rule. For example, in the U.S., Daylight Savings
315
* Time starts at the second Sunday in March, at 2 AM in standard time.
316
* Therefore, you can set the start rule by calling:
317
* setStartRule(UCAL_MARCH, 2, UCAL_SUNDAY, 2*60*60*1000);
318
* The dayOfWeekInMonth and dayOfWeek parameters together specify how to calculate
319
* the exact starting date. Their exact meaning depend on their respective signs,
320
* allowing various types of rules to be constructed, as follows:
322
* <li>If both dayOfWeekInMonth and dayOfWeek are positive, they specify the
323
* day of week in the month (e.g., (2, WEDNESDAY) is the second Wednesday
324
* of the month).</li>
325
* <li>If dayOfWeek is positive and dayOfWeekInMonth is negative, they specify
326
* the day of week in the month counting backward from the end of the month.
327
* (e.g., (-1, MONDAY) is the last Monday in the month)</li>
328
* <li>If dayOfWeek is zero and dayOfWeekInMonth is positive, dayOfWeekInMonth
329
* specifies the day of the month, regardless of what day of the week it is.
330
* (e.g., (10, 0) is the tenth day of the month)</li>
331
* <li>If dayOfWeek is zero and dayOfWeekInMonth is negative, dayOfWeekInMonth
332
* specifies the day of the month counting backward from the end of the
333
* month, regardless of what day of the week it is (e.g., (-2, 0) is the
334
* next-to-last day of the month).</li>
335
* <li>If dayOfWeek is negative and dayOfWeekInMonth is positive, they specify the
336
* first specified day of the week on or after the specfied day of the month.
337
* (e.g., (15, -SUNDAY) is the first Sunday after the 15th of the month
338
* [or the 15th itself if the 15th is a Sunday].)</li>
339
* <li>If dayOfWeek and DayOfWeekInMonth are both negative, they specify the
340
* last specified day of the week on or before the specified day of the month.
341
* (e.g., (-20, -TUESDAY) is the last Tuesday before the 20th of the month
342
* [or the 20th itself if the 20th is a Tuesday].)</li>
344
* @param month the daylight savings starting month. Month is 0-based.
346
* @param dayOfWeekInMonth the daylight savings starting
347
* day-of-week-in-month. Please see the member description for an example.
348
* @param dayOfWeek the daylight savings starting day-of-week. Please see
349
* the member description for an example.
350
* @param time the daylight savings starting time. Please see the member
351
* description for an example.
352
* @param mode whether the time is local wall time, local standard time,
353
* or UTC time. Default is local wall time.
354
* @param status An UErrorCode
357
void setStartRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
358
int32_t time, TimeMode mode, UErrorCode& status);
361
* Sets the DST start rule to a fixed date within a month.
363
* @param month The month in which this rule occurs (0-based).
364
* @param dayOfMonth The date in that month (1-based).
365
* @param time The time of that day (number of millis after midnight)
366
* when DST takes effect in local wall time, which is
367
* standard time in this case.
368
* @param status An UErrorCode
371
void setStartRule(int32_t month, int32_t dayOfMonth, int32_t time,
374
* Sets the DST start rule to a fixed date within a month.
376
* @param month The month in which this rule occurs (0-based).
377
* @param dayOfMonth The date in that month (1-based).
378
* @param time The time of that day (number of millis after midnight)
379
* when DST takes effect in local wall time, which is
380
* standard time in this case.
381
* @param mode whether the time is local wall time, local standard time,
382
* or UTC time. Default is local wall time.
383
* @param status An UErrorCode
386
void setStartRule(int32_t month, int32_t dayOfMonth, int32_t time,
387
TimeMode mode, UErrorCode& status);
390
* Sets the DST start rule to a weekday before or after a give date within
391
* a month, e.g., the first Monday on or after the 8th.
393
* @param month The month in which this rule occurs (0-based).
394
* @param dayOfMonth A date within that month (1-based).
395
* @param dayOfWeek The day of the week on which this rule occurs.
396
* @param time The time of that day (number of millis after midnight)
397
* when DST takes effect in local wall time, which is
398
* standard time in this case.
399
* @param after If true, this rule selects the first dayOfWeek on
400
* or after dayOfMonth. If false, this rule selects
401
* the last dayOfWeek on or before dayOfMonth.
402
* @param status An UErrorCode
405
void setStartRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
406
int32_t time, UBool after, UErrorCode& status);
408
* Sets the DST start rule to a weekday before or after a give date within
409
* a month, e.g., the first Monday on or after the 8th.
411
* @param month The month in which this rule occurs (0-based).
412
* @param dayOfMonth A date within that month (1-based).
413
* @param dayOfWeek The day of the week on which this rule occurs.
414
* @param time The time of that day (number of millis after midnight)
415
* when DST takes effect in local wall time, which is
416
* standard time in this case.
417
* @param mode whether the time is local wall time, local standard time,
418
* or UTC time. Default is local wall time.
419
* @param after If true, this rule selects the first dayOfWeek on
420
* or after dayOfMonth. If false, this rule selects
421
* the last dayOfWeek on or before dayOfMonth.
422
* @param status An UErrorCode
425
void setStartRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
426
int32_t time, TimeMode mode, UBool after, UErrorCode& status);
429
* Sets the daylight savings ending rule. For example, if Daylight
430
* Savings Time ends at the last (-1) Sunday in October, at 2 AM in standard time.
431
* Therefore, you can set the end rule by calling:
433
* setEndRule(UCAL_OCTOBER, -1, UCAL_SUNDAY, 2*60*60*1000);
435
* Various other types of rules can be specified by manipulating the dayOfWeek
436
* and dayOfWeekInMonth parameters. For complete details, see the documentation
437
* for setStartRule().
439
* @param month the daylight savings ending month. Month is 0-based.
441
* @param dayOfWeekInMonth the daylight savings ending
442
* day-of-week-in-month. See setStartRule() for a complete explanation.
443
* @param dayOfWeek the daylight savings ending day-of-week. See setStartRule()
444
* for a complete explanation.
445
* @param time the daylight savings ending time. Please see the member
446
* description for an example.
447
* @param status An UErrorCode
450
void setEndRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
451
int32_t time, UErrorCode& status);
454
* Sets the daylight savings ending rule. For example, if Daylight
455
* Savings Time ends at the last (-1) Sunday in October, at 2 AM in standard time.
456
* Therefore, you can set the end rule by calling:
458
* setEndRule(UCAL_OCTOBER, -1, UCAL_SUNDAY, 2*60*60*1000);
460
* Various other types of rules can be specified by manipulating the dayOfWeek
461
* and dayOfWeekInMonth parameters. For complete details, see the documentation
462
* for setStartRule().
464
* @param month the daylight savings ending month. Month is 0-based.
466
* @param dayOfWeekInMonth the daylight savings ending
467
* day-of-week-in-month. See setStartRule() for a complete explanation.
468
* @param dayOfWeek the daylight savings ending day-of-week. See setStartRule()
469
* for a complete explanation.
470
* @param time the daylight savings ending time. Please see the member
471
* description for an example.
472
* @param mode whether the time is local wall time, local standard time,
473
* or UTC time. Default is local wall time.
474
* @param status An UErrorCode
477
void setEndRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
478
int32_t time, TimeMode mode, UErrorCode& status);
481
* Sets the DST end rule to a fixed date within a month.
483
* @param month The month in which this rule occurs (0-based).
484
* @param dayOfMonth The date in that month (1-based).
485
* @param time The time of that day (number of millis after midnight)
486
* when DST ends in local wall time, which is daylight
488
* @param status An UErrorCode
491
void setEndRule(int32_t month, int32_t dayOfMonth, int32_t time, UErrorCode& status);
494
* Sets the DST end rule to a fixed date within a month.
496
* @param month The month in which this rule occurs (0-based).
497
* @param dayOfMonth The date in that month (1-based).
498
* @param time The time of that day (number of millis after midnight)
499
* when DST ends in local wall time, which is daylight
501
* @param mode whether the time is local wall time, local standard time,
502
* or UTC time. Default is local wall time.
503
* @param status An UErrorCode
506
void setEndRule(int32_t month, int32_t dayOfMonth, int32_t time,
507
TimeMode mode, UErrorCode& status);
510
* Sets the DST end rule to a weekday before or after a give date within
511
* a month, e.g., the first Monday on or after the 8th.
513
* @param month The month in which this rule occurs (0-based).
514
* @param dayOfMonth A date within that month (1-based).
515
* @param dayOfWeek The day of the week on which this rule occurs.
516
* @param time The time of that day (number of millis after midnight)
517
* when DST ends in local wall time, which is daylight
519
* @param after If true, this rule selects the first dayOfWeek on
520
* or after dayOfMonth. If false, this rule selects
521
* the last dayOfWeek on or before dayOfMonth.
522
* @param status An UErrorCode
525
void setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
526
int32_t time, UBool after, UErrorCode& status);
529
* Sets the DST end rule to a weekday before or after a give date within
530
* a month, e.g., the first Monday on or after the 8th.
532
* @param month The month in which this rule occurs (0-based).
533
* @param dayOfMonth A date within that month (1-based).
534
* @param dayOfWeek The day of the week on which this rule occurs.
535
* @param time The time of that day (number of millis after midnight)
536
* when DST ends in local wall time, which is daylight
538
* @param mode whether the time is local wall time, local standard time,
539
* or UTC time. Default is local wall time.
540
* @param after If true, this rule selects the first dayOfWeek on
541
* or after dayOfMonth. If false, this rule selects
542
* the last dayOfWeek on or before dayOfMonth.
543
* @param status An UErrorCode
546
void setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
547
int32_t time, TimeMode mode, UBool after, UErrorCode& status);
550
* Returns the TimeZone's adjusted GMT offset (i.e., the number of milliseconds to add
551
* to GMT to get local time in this time zone, taking daylight savings time into
552
* account) as of a particular reference date. The reference date is used to determine
553
* whether daylight savings time is in effect and needs to be figured into the offset
554
* that is returned (in other words, what is the adjusted GMT offset in this time zone
555
* at this particular date and time?). For the time zones produced by createTimeZone(),
556
* the reference data is specified according to the Gregorian calendar, and the date
557
* and time fields are in GMT, NOT local time.
559
* @param era The reference date's era
560
* @param year The reference date's year
561
* @param month The reference date's month (0-based; 0 is January)
562
* @param day The reference date's day-in-month (1-based)
563
* @param dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday)
564
* @param millis The reference date's milliseconds in day, UTT (NOT local time).
565
* @param status An UErrorCode to receive the status.
566
* @return The offset in milliseconds to add to GMT to get local time.
569
virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
570
uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const;
573
* Gets the time zone offset, for current date, modified in case of
574
* daylight savings. This is the offset to add *to* UTC to get local time.
575
* @param era the era of the given date.
576
* @param year the year in the given date.
577
* @param month the month in the given date.
578
* Month is 0-based. e.g., 0 for January.
579
* @param day the day-in-month of the given date.
580
* @param dayOfWeek the day-of-week of the given date.
581
* @param milliseconds the millis in day in <em>standard</em> local time.
582
* @param monthLength the length of the given month in days.
583
* @param status An UErrorCode to receive the status.
584
* @return the offset to add *to* GMT to get local time.
587
virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
588
uint8_t dayOfWeek, int32_t milliseconds,
589
int32_t monthLength, UErrorCode& status) const;
591
* Gets the time zone offset, for current date, modified in case of
592
* daylight savings. This is the offset to add *to* UTC to get local time.
593
* @param era the era of the given date.
594
* @param year the year in the given date.
595
* @param month the month in the given date.
596
* Month is 0-based. e.g., 0 for January.
597
* @param day the day-in-month of the given date.
598
* @param dayOfWeek the day-of-week of the given date.
599
* @param milliseconds the millis in day in <em>standard</em> local time.
600
* @param monthLength the length of the given month in days.
601
* @param prevMonthLength length of the previous month in days.
602
* @param status An UErrorCode to receive the status.
603
* @return the offset to add *to* GMT to get local time.
606
virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
607
uint8_t dayOfWeek, int32_t milliseconds,
608
int32_t monthLength, int32_t prevMonthLength,
609
UErrorCode& status) const;
612
* Redeclared TimeZone method. This implementation simply calls
613
* the base class method, which otherwise would be hidden.
616
virtual void getOffset(UDate date, UBool local, int32_t& rawOffset,
617
int32_t& dstOffset, UErrorCode& ec) const;
620
* Get time zone offsets from local wall time.
623
virtual void getOffsetFromLocal(UDate date, int32_t nonExistingTimeOpt, int32_t duplicatedTimeOpt,
624
int32_t& rawOffset, int32_t& dstOffset, UErrorCode& status) /*const*/;
627
* Returns the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
628
* to GMT to get local time, before taking daylight savings time into account).
630
* @return The TimeZone's raw GMT offset.
633
virtual int32_t getRawOffset(void) const;
636
* Sets the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
637
* to GMT to get local time, before taking daylight savings time into account).
639
* @param offsetMillis The new raw GMT offset for this time zone.
642
virtual void setRawOffset(int32_t offsetMillis);
645
* Sets the amount of time in ms that the clock is advanced during DST.
646
* @param millisSavedDuringDST the number of milliseconds the time is
647
* advanced with respect to standard time when the daylight savings rules
648
* are in effect. A positive number, typically one hour (3600000).
649
* @param status An UErrorCode to receive the status.
652
void setDSTSavings(int32_t millisSavedDuringDST, UErrorCode& status);
655
* Returns the amount of time in ms that the clock is advanced during DST.
656
* @return the number of milliseconds the time is
657
* advanced with respect to standard time when the daylight savings rules
658
* are in effect. A positive number, typically one hour (3600000).
661
virtual int32_t getDSTSavings(void) const;
664
* Queries if this TimeZone uses Daylight Savings Time.
666
* @return True if this TimeZone uses Daylight Savings Time; false otherwise.
669
virtual UBool useDaylightTime(void) const;
672
* Returns true if the given date is within the period when daylight savings time
673
* is in effect; false otherwise. If the TimeZone doesn't observe daylight savings
674
* time, this functions always returns false.
675
* This method is wasteful since it creates a new GregorianCalendar and
676
* deletes it each time it is called. This is a deprecated method
677
* and provided only for Java compatibility.
679
* @param date The date to test.
680
* @param status An UErrorCode to receive the status.
681
* @return true if the given date is in Daylight Savings Time;
683
* @deprecated ICU 2.4. Use Calendar::inDaylightTime() instead.
685
virtual UBool inDaylightTime(UDate date, UErrorCode& status) const;
688
* Return true if this zone has the same rules and offset as another zone.
689
* @param other the TimeZone object to be compared with
690
* @return true if the given zone has the same rules and offset as this one
693
UBool hasSameRules(const TimeZone& other) const;
696
* Clones TimeZone objects polymorphically. Clients are responsible for deleting
697
* the TimeZone object cloned.
699
* @return A new copy of this TimeZone object.
702
virtual TimeZone* clone(void) const;
705
* Gets the first time zone transition after the base time.
706
* @param base The base time.
707
* @param inclusive Whether the base time is inclusive or not.
708
* @param result Receives the first transition after the base time.
709
* @return TRUE if the transition is found.
712
virtual UBool getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) /*const*/;
715
* Gets the most recent time zone transition before the base time.
716
* @param base The base time.
717
* @param inclusive Whether the base time is inclusive or not.
718
* @param result Receives the most recent transition before the base time.
719
* @return TRUE if the transition is found.
722
virtual UBool getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) /*const*/;
725
* Returns the number of <code>TimeZoneRule</code>s which represents time transitions,
726
* for this time zone, that is, all <code>TimeZoneRule</code>s for this time zone except
727
* <code>InitialTimeZoneRule</code>. The return value range is 0 or any positive value.
728
* @param status Receives error status code.
729
* @return The number of <code>TimeZoneRule</code>s representing time transitions.
732
virtual int32_t countTransitionRules(UErrorCode& status) /*const*/;
735
* Gets the <code>InitialTimeZoneRule</code> and the set of <code>TimeZoneRule</code>
736
* which represent time transitions for this time zone. On successful return,
737
* the argument initial points to non-NULL <code>InitialTimeZoneRule</code> and
738
* the array trsrules is filled with 0 or multiple <code>TimeZoneRule</code>
739
* instances up to the size specified by trscount. The results are referencing the
740
* rule instance held by this time zone instance. Therefore, after this time zone
741
* is destructed, they are no longer available.
742
* @param initial Receives the initial timezone rule
743
* @param trsrules Receives the timezone transition rules
744
* @param trscount On input, specify the size of the array 'transitions' receiving
745
* the timezone transition rules. On output, actual number of
746
* rules filled in the array will be set.
747
* @param status Receives error status code.
750
virtual void getTimeZoneRules(const InitialTimeZoneRule*& initial,
751
const TimeZoneRule* trsrules[], int32_t& trscount, UErrorCode& status) /*const*/;
757
* Override TimeZone Returns a unique class ID POLYMORPHICALLY. Pure virtual
758
* override. This method is to implement a simple version of RTTI, since not all C++
759
* compilers support genuine RTTI. Polymorphic operator==() and clone() methods call
762
* @return The class ID for this object. All objects of a given class have the
763
* same class ID. Objects of other classes have different class IDs.
766
virtual UClassID getDynamicClassID(void) const;
769
* Return the class ID for this class. This is useful only for comparing to a return
770
* value from getDynamicClassID(). For example:
772
* . Base* polymorphic_pointer = createPolymorphicObject();
773
* . if (polymorphic_pointer->getDynamicClassID() ==
774
* . Derived::getStaticClassID()) ...
776
* @return The class ID for all objects of this class.
779
static UClassID U_EXPORT2 getStaticClassID(void);
783
* Constants specifying values of startMode and endMode.
793
SimpleTimeZone(); // default constructor not implemented
796
* Internal construction method.
797
* @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset
798
* @param startMonth the month DST starts
799
* @param startDay the day DST starts
800
* @param startDayOfWeek the DOW DST starts
801
* @param startTime the time DST starts
802
* @param startTimeMode Whether the start time is local wall time, local
803
* standard time, or UTC time. Default is local wall time.
804
* @param endMonth the month DST ends
805
* @param endDay the day DST ends
806
* @param endDayOfWeek the DOW DST ends
807
* @param endTime the time DST ends
808
* @param endTimeMode Whether the end time is local wall time, local
809
* standard time, or UTC time. Default is local wall time.
810
* @param savingsDST The number of milliseconds added to standard time
811
* to get DST time. Default is one hour.
812
* @param status An UErrorCode to receive the status.
814
void construct(int32_t rawOffsetGMT,
815
int8_t startMonth, int8_t startDay, int8_t startDayOfWeek,
816
int32_t startTime, TimeMode startTimeMode,
817
int8_t endMonth, int8_t endDay, int8_t endDayOfWeek,
818
int32_t endTime, TimeMode endTimeMode,
819
int32_t dstSavings, UErrorCode& status);
822
* Compare a given date in the year to a rule. Return 1, 0, or -1, depending
823
* on whether the date is after, equal to, or before the rule date. The
824
* millis are compared directly against the ruleMillis, so any
825
* standard-daylight adjustments must be handled by the caller.
827
* @return 1 if the date is after the rule date, -1 if the date is before
828
* the rule date, or 0 if the date is equal to the rule date.
830
static int32_t compareToRule(int8_t month, int8_t monthLen, int8_t prevMonthLen,
832
int8_t dayOfWeek, int32_t millis, int32_t millisDelta,
833
EMode ruleMode, int8_t ruleMonth, int8_t ruleDayOfWeek,
834
int8_t ruleDay, int32_t ruleMillis);
837
* Given a set of encoded rules in startDay and startDayOfMonth, decode
838
* them and set the startMode appropriately. Do the same for endDay and
841
* Upon entry, the day of week variables may be zero or
842
* negative, in order to indicate special modes. The day of month
843
* variables may also be negative.
845
* Upon exit, the mode variables will be
846
* set, and the day of week and day of month variables will be positive.
848
* This method also recognizes a startDay or endDay of zero as indicating
851
void decodeRules(UErrorCode& status);
852
void decodeStartRule(UErrorCode& status);
853
void decodeEndRule(UErrorCode& status);
855
int8_t startMonth, startDay, startDayOfWeek; // the month, day, DOW, and time DST starts
857
TimeMode startTimeMode, endTimeMode; // Mode for startTime, endTime; see TimeMode
858
int8_t endMonth, endDay, endDayOfWeek; // the month, day, DOW, and time DST ends
860
int32_t startYear; // the year these DST rules took effect
861
int32_t rawOffset; // the TimeZone's raw GMT offset
862
UBool useDaylight; // flag indicating whether this TimeZone uses DST
863
static const int8_t STATICMONTHLENGTH[12]; // lengths of the months
864
EMode startMode, endMode; // flags indicating what kind of rules the DST rules are
867
* A positive value indicating the amount of time saved during DST in ms.
868
* Typically one hour; sometimes 30 minutes.
872
/* Private for BasicTimeZone implementation */
873
void initTransitionRules(UErrorCode& status);
874
void clearTransitionRules(void);
875
void deleteTransitionRules(void);
876
UBool transitionRulesInitialized;
877
InitialTimeZoneRule* initialRule;
878
TimeZoneTransition* firstTransition;
879
AnnualTimeZoneRule* stdRule;
880
AnnualTimeZoneRule* dstRule;
883
inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfWeekInMonth,
885
int32_t time, UErrorCode& status) {
886
setStartRule(month, dayOfWeekInMonth, dayOfWeek, time, WALL_TIME, status);
889
inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfMonth,
891
UErrorCode& status) {
892
setStartRule(month, dayOfMonth, time, WALL_TIME, status);
895
inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfMonth,
897
int32_t time, UBool after, UErrorCode& status) {
898
setStartRule(month, dayOfMonth, dayOfWeek, time, WALL_TIME, after, status);
901
inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfWeekInMonth,
903
int32_t time, UErrorCode& status) {
904
setEndRule(month, dayOfWeekInMonth, dayOfWeek, time, WALL_TIME, status);
907
inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfMonth,
908
int32_t time, UErrorCode& status) {
909
setEndRule(month, dayOfMonth, time, WALL_TIME, status);
912
inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
913
int32_t time, UBool after, UErrorCode& status) {
914
setEndRule(month, dayOfMonth, dayOfWeek, time, WALL_TIME, after, status);
918
SimpleTimeZone::getOffset(UDate date, UBool local, int32_t& rawOffsetRef,
919
int32_t& dstOffsetRef, UErrorCode& ec) const {
920
TimeZone::getOffset(date, local, rawOffsetRef, dstOffsetRef, ec);
925
#endif /* #if !UCONFIG_NO_FORMATTING */