Coverage Report

Created: 2023-02-22 06:51

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