1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 ********************************************************************************
5 * Copyright (C) 1997-2013, International Business Machines *
6 * Corporation and others. All Rights Reserved. *
7 ********************************************************************************
11 * Modification History:
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 ********************************************************************************
29 #include "unicode/utypes.h"
33 * \brief C++ API: SimpleTimeZone is a concrete subclass of TimeZone.
36 #if !UCONFIG_NO_FORMATTING
38 #include "unicode/basictz.h"
40 #if U_SHOW_CPLUSPLUS_API
43 // forward declaration
44 class InitialTimeZoneRule
;
45 class TimeZoneTransition
;
46 class AnnualTimeZoneRule
;
49 * <code>SimpleTimeZone</code> is a concrete subclass of <code>TimeZone</code>
50 * that represents a time zone for use with a Gregorian calendar. This
51 * class does not handle historical changes.
53 * When specifying daylight-savings-time begin and end dates, use a negative value for
54 * <code>dayOfWeekInMonth</code> to indicate that <code>SimpleTimeZone</code> should
55 * count from the end of the month backwards. For example, if Daylight Savings
56 * Time starts or ends at the last Sunday a month, use <code>dayOfWeekInMonth = -1</code>
57 * along with <code>dayOfWeek = UCAL_SUNDAY</code> to specify the rule.
60 * @see GregorianCalendar
62 * @author D. Goldsmith, Mark Davis, Chen-Lieh Huang, Alan Liu
64 class U_I18N_API SimpleTimeZone
: public BasicTimeZone
{
68 * TimeMode is used, together with a millisecond offset after
69 * midnight, to specify a rule transition time. Most rules
70 * transition at a local wall time, that is, according to the
71 * current time in effect, either standard, or DST. However, some
72 * rules transition at local standard time, and some at a specific
73 * UTC time. Although it might seem that all times could be
74 * converted to wall time, thus eliminating the need for this
75 * parameter, this is not the case.
86 * @param source the object to be copied.
89 SimpleTimeZone(const SimpleTimeZone
& source
);
92 * Default assignment operator
93 * @param right the object to be copied.
96 SimpleTimeZone
& operator=(const SimpleTimeZone
& right
);
102 virtual ~SimpleTimeZone();
105 * Returns true if the two TimeZone objects are equal; that is, they have
106 * the same ID, raw GMT offset, and DST rules.
108 * @param that The SimpleTimeZone object to be compared with.
109 * @return True if the given time zone is equal to this time zone; false
113 virtual UBool
operator==(const TimeZone
& that
) const;
116 * Constructs a SimpleTimeZone with the given raw GMT offset and time zone ID,
117 * and which doesn't observe daylight savings time. Normally you should use
118 * TimeZone::createInstance() to create a TimeZone instead of creating a
119 * SimpleTimeZone directly with this constructor.
121 * @param rawOffsetGMT The given base time zone offset to GMT.
122 * @param ID The timezone ID which is obtained from
123 * TimeZone.getAvailableIDs.
126 SimpleTimeZone(int32_t rawOffsetGMT
, const UnicodeString
& ID
);
129 * Construct a SimpleTimeZone with the given raw GMT offset, time zone ID,
130 * and times to start and end daylight savings time. To create a TimeZone that
131 * doesn't observe daylight savings time, don't use this constructor; use
132 * SimpleTimeZone(rawOffset, ID) instead. Normally, you should use
133 * TimeZone.createInstance() to create a TimeZone instead of creating a
134 * SimpleTimeZone directly with this constructor.
136 * Various types of daylight-savings time rules can be specfied by using different
137 * values for startDay and startDayOfWeek and endDay and endDayOfWeek. For a
138 * complete explanation of how these parameters work, see the documentation for
141 * @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset
142 * @param ID The new SimpleTimeZone's time zone ID.
143 * @param savingsStartMonth The daylight savings starting month. Month is
144 * 0-based. eg, 0 for January.
145 * @param savingsStartDayOfWeekInMonth The daylight savings starting
146 * day-of-week-in-month. See setStartRule() for a
147 * complete explanation.
148 * @param savingsStartDayOfWeek The daylight savings starting day-of-week.
149 * See setStartRule() for a complete explanation.
150 * @param savingsStartTime The daylight savings starting time, expressed as the
151 * number of milliseconds after midnight.
152 * @param savingsEndMonth The daylight savings ending month. Month is
153 * 0-based. eg, 0 for January.
154 * @param savingsEndDayOfWeekInMonth The daylight savings ending day-of-week-in-month.
155 * See setStartRule() for a complete explanation.
156 * @param savingsEndDayOfWeek The daylight savings ending day-of-week.
157 * See setStartRule() for a complete explanation.
158 * @param savingsEndTime The daylight savings ending time, expressed as the
159 * number of milliseconds after midnight.
160 * @param status An UErrorCode to receive the status.
163 SimpleTimeZone(int32_t rawOffsetGMT
, const UnicodeString
& ID
,
164 int8_t savingsStartMonth
, int8_t savingsStartDayOfWeekInMonth
,
165 int8_t savingsStartDayOfWeek
, int32_t savingsStartTime
,
166 int8_t savingsEndMonth
, int8_t savingsEndDayOfWeekInMonth
,
167 int8_t savingsEndDayOfWeek
, int32_t savingsEndTime
,
170 * Construct a SimpleTimeZone with the given raw GMT offset, time zone ID,
171 * and times to start and end daylight savings time. To create a TimeZone that
172 * doesn't observe daylight savings time, don't use this constructor; use
173 * SimpleTimeZone(rawOffset, ID) instead. Normally, you should use
174 * TimeZone.createInstance() to create a TimeZone instead of creating a
175 * SimpleTimeZone directly with this constructor.
177 * Various types of daylight-savings time rules can be specfied by using different
178 * values for startDay and startDayOfWeek and endDay and endDayOfWeek. For a
179 * complete explanation of how these parameters work, see the documentation for
182 * @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset
183 * @param ID The new SimpleTimeZone's time zone ID.
184 * @param savingsStartMonth The daylight savings starting month. Month is
185 * 0-based. eg, 0 for January.
186 * @param savingsStartDayOfWeekInMonth The daylight savings starting
187 * day-of-week-in-month. See setStartRule() for a
188 * complete explanation.
189 * @param savingsStartDayOfWeek The daylight savings starting day-of-week.
190 * See setStartRule() for a complete explanation.
191 * @param savingsStartTime The daylight savings starting time, expressed as the
192 * number of milliseconds after midnight.
193 * @param savingsEndMonth The daylight savings ending month. Month is
194 * 0-based. eg, 0 for January.
195 * @param savingsEndDayOfWeekInMonth The daylight savings ending day-of-week-in-month.
196 * See setStartRule() for a complete explanation.
197 * @param savingsEndDayOfWeek The daylight savings ending day-of-week.
198 * See setStartRule() for a complete explanation.
199 * @param savingsEndTime The daylight savings ending time, expressed as the
200 * number of milliseconds after midnight.
201 * @param savingsDST The number of milliseconds added to standard time
202 * to get DST time. Default is one hour.
203 * @param status An UErrorCode to receive the status.
206 SimpleTimeZone(int32_t rawOffsetGMT
, const UnicodeString
& ID
,
207 int8_t savingsStartMonth
, int8_t savingsStartDayOfWeekInMonth
,
208 int8_t savingsStartDayOfWeek
, int32_t savingsStartTime
,
209 int8_t savingsEndMonth
, int8_t savingsEndDayOfWeekInMonth
,
210 int8_t savingsEndDayOfWeek
, int32_t savingsEndTime
,
211 int32_t savingsDST
, UErrorCode
& status
);
214 * Construct a SimpleTimeZone with the given raw GMT offset, time zone ID,
215 * and times to start and end daylight savings time. To create a TimeZone that
216 * doesn't observe daylight savings time, don't use this constructor; use
217 * SimpleTimeZone(rawOffset, ID) instead. Normally, you should use
218 * TimeZone.createInstance() to create a TimeZone instead of creating a
219 * SimpleTimeZone directly with this constructor.
221 * Various types of daylight-savings time rules can be specfied by using different
222 * values for startDay and startDayOfWeek and endDay and endDayOfWeek. For a
223 * complete explanation of how these parameters work, see the documentation for
226 * @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset
227 * @param ID The new SimpleTimeZone's time zone ID.
228 * @param savingsStartMonth The daylight savings starting month. Month is
229 * 0-based. eg, 0 for January.
230 * @param savingsStartDayOfWeekInMonth The daylight savings starting
231 * day-of-week-in-month. See setStartRule() for a
232 * complete explanation.
233 * @param savingsStartDayOfWeek The daylight savings starting day-of-week.
234 * See setStartRule() for a complete explanation.
235 * @param savingsStartTime The daylight savings starting time, expressed as the
236 * number of milliseconds after midnight.
237 * @param savingsStartTimeMode Whether the start time is local wall time, local
238 * standard time, or UTC time. Default is local wall time.
239 * @param savingsEndMonth The daylight savings ending month. Month is
240 * 0-based. eg, 0 for January.
241 * @param savingsEndDayOfWeekInMonth The daylight savings ending day-of-week-in-month.
242 * See setStartRule() for a complete explanation.
243 * @param savingsEndDayOfWeek The daylight savings ending day-of-week.
244 * See setStartRule() for a complete explanation.
245 * @param savingsEndTime The daylight savings ending time, expressed as the
246 * number of milliseconds after midnight.
247 * @param savingsEndTimeMode Whether the end time is local wall time, local
248 * standard time, or UTC time. Default is local wall time.
249 * @param savingsDST The number of milliseconds added to standard time
250 * to get DST time. Default is one hour.
251 * @param status An UErrorCode to receive the status.
254 SimpleTimeZone(int32_t rawOffsetGMT
, const UnicodeString
& ID
,
255 int8_t savingsStartMonth
, int8_t savingsStartDayOfWeekInMonth
,
256 int8_t savingsStartDayOfWeek
, int32_t savingsStartTime
,
257 TimeMode savingsStartTimeMode
,
258 int8_t savingsEndMonth
, int8_t savingsEndDayOfWeekInMonth
,
259 int8_t savingsEndDayOfWeek
, int32_t savingsEndTime
, TimeMode savingsEndTimeMode
,
260 int32_t savingsDST
, UErrorCode
& status
);
263 * Sets the daylight savings starting year, that is, the year this time zone began
264 * observing its specified daylight savings time rules. The time zone is considered
265 * not to observe daylight savings time prior to that year; SimpleTimeZone doesn't
266 * support historical daylight-savings-time rules.
267 * @param year the daylight savings starting year.
270 void setStartYear(int32_t year
);
273 * Sets the daylight savings starting rule. For example, in the U.S., Daylight Savings
274 * Time starts at the second Sunday in March, at 2 AM in standard time.
275 * Therefore, you can set the start rule by calling:
276 * setStartRule(UCAL_MARCH, 2, UCAL_SUNDAY, 2*60*60*1000);
277 * The dayOfWeekInMonth and dayOfWeek parameters together specify how to calculate
278 * the exact starting date. Their exact meaning depend on their respective signs,
279 * allowing various types of rules to be constructed, as follows:
281 * <li>If both dayOfWeekInMonth and dayOfWeek are positive, they specify the
282 * day of week in the month (e.g., (2, WEDNESDAY) is the second Wednesday
283 * of the month).</li>
284 * <li>If dayOfWeek is positive and dayOfWeekInMonth is negative, they specify
285 * the day of week in the month counting backward from the end of the month.
286 * (e.g., (-1, MONDAY) is the last Monday in the month)</li>
287 * <li>If dayOfWeek is zero and dayOfWeekInMonth is positive, dayOfWeekInMonth
288 * specifies the day of the month, regardless of what day of the week it is.
289 * (e.g., (10, 0) is the tenth day of the month)</li>
290 * <li>If dayOfWeek is zero and dayOfWeekInMonth is negative, dayOfWeekInMonth
291 * specifies the day of the month counting backward from the end of the
292 * month, regardless of what day of the week it is (e.g., (-2, 0) is the
293 * next-to-last day of the month).</li>
294 * <li>If dayOfWeek is negative and dayOfWeekInMonth is positive, they specify the
295 * first specified day of the week on or after the specfied day of the month.
296 * (e.g., (15, -SUNDAY) is the first Sunday after the 15th of the month
297 * [or the 15th itself if the 15th is a Sunday].)</li>
298 * <li>If dayOfWeek and DayOfWeekInMonth are both negative, they specify the
299 * last specified day of the week on or before the specified day of the month.
300 * (e.g., (-20, -TUESDAY) is the last Tuesday before the 20th of the month
301 * [or the 20th itself if the 20th is a Tuesday].)</li>
303 * @param month the daylight savings starting month. Month is 0-based.
305 * @param dayOfWeekInMonth the daylight savings starting
306 * day-of-week-in-month. Please see the member description for an example.
307 * @param dayOfWeek the daylight savings starting day-of-week. Please see
308 * the member description for an example.
309 * @param time the daylight savings starting time. Please see the member
310 * description for an example.
311 * @param status An UErrorCode
314 void setStartRule(int32_t month
, int32_t dayOfWeekInMonth
, int32_t dayOfWeek
,
315 int32_t time
, UErrorCode
& status
);
317 * Sets the daylight savings starting rule. For example, in the U.S., Daylight Savings
318 * Time starts at the second Sunday in March, at 2 AM in standard time.
319 * Therefore, you can set the start rule by calling:
320 * setStartRule(UCAL_MARCH, 2, UCAL_SUNDAY, 2*60*60*1000);
321 * The dayOfWeekInMonth and dayOfWeek parameters together specify how to calculate
322 * the exact starting date. Their exact meaning depend on their respective signs,
323 * allowing various types of rules to be constructed, as follows:
325 * <li>If both dayOfWeekInMonth and dayOfWeek are positive, they specify the
326 * day of week in the month (e.g., (2, WEDNESDAY) is the second Wednesday
327 * of the month).</li>
328 * <li>If dayOfWeek is positive and dayOfWeekInMonth is negative, they specify
329 * the day of week in the month counting backward from the end of the month.
330 * (e.g., (-1, MONDAY) is the last Monday in the month)</li>
331 * <li>If dayOfWeek is zero and dayOfWeekInMonth is positive, dayOfWeekInMonth
332 * specifies the day of the month, regardless of what day of the week it is.
333 * (e.g., (10, 0) is the tenth day of the month)</li>
334 * <li>If dayOfWeek is zero and dayOfWeekInMonth is negative, dayOfWeekInMonth
335 * specifies the day of the month counting backward from the end of the
336 * month, regardless of what day of the week it is (e.g., (-2, 0) is the
337 * next-to-last day of the month).</li>
338 * <li>If dayOfWeek is negative and dayOfWeekInMonth is positive, they specify the
339 * first specified day of the week on or after the specfied day of the month.
340 * (e.g., (15, -SUNDAY) is the first Sunday after the 15th of the month
341 * [or the 15th itself if the 15th is a Sunday].)</li>
342 * <li>If dayOfWeek and DayOfWeekInMonth are both negative, they specify the
343 * last specified day of the week on or before the specified day of the month.
344 * (e.g., (-20, -TUESDAY) is the last Tuesday before the 20th of the month
345 * [or the 20th itself if the 20th is a Tuesday].)</li>
347 * @param month the daylight savings starting month. Month is 0-based.
349 * @param dayOfWeekInMonth the daylight savings starting
350 * day-of-week-in-month. Please see the member description for an example.
351 * @param dayOfWeek the daylight savings starting day-of-week. Please see
352 * the member description for an example.
353 * @param time the daylight savings starting time. Please see the member
354 * description for an example.
355 * @param mode whether the time is local wall time, local standard time,
356 * or UTC time. Default is local wall time.
357 * @param status An UErrorCode
360 void setStartRule(int32_t month
, int32_t dayOfWeekInMonth
, int32_t dayOfWeek
,
361 int32_t time
, TimeMode mode
, UErrorCode
& status
);
364 * Sets the DST start rule to a fixed date within a month.
366 * @param month The month in which this rule occurs (0-based).
367 * @param dayOfMonth The date in that month (1-based).
368 * @param time The time of that day (number of millis after midnight)
369 * when DST takes effect in local wall time, which is
370 * standard time in this case.
371 * @param status An UErrorCode
374 void setStartRule(int32_t month
, int32_t dayOfMonth
, int32_t time
,
377 * Sets the DST start rule to a fixed date within a month.
379 * @param month The month in which this rule occurs (0-based).
380 * @param dayOfMonth The date in that month (1-based).
381 * @param time The time of that day (number of millis after midnight)
382 * when DST takes effect in local wall time, which is
383 * standard time in this case.
384 * @param mode whether the time is local wall time, local standard time,
385 * or UTC time. Default is local wall time.
386 * @param status An UErrorCode
389 void setStartRule(int32_t month
, int32_t dayOfMonth
, int32_t time
,
390 TimeMode mode
, UErrorCode
& status
);
393 * Sets the DST start rule to a weekday before or after a give date within
394 * a month, e.g., the first Monday on or after the 8th.
396 * @param month The month in which this rule occurs (0-based).
397 * @param dayOfMonth A date within that month (1-based).
398 * @param dayOfWeek The day of the week on which this rule occurs.
399 * @param time The time of that day (number of millis after midnight)
400 * when DST takes effect in local wall time, which is
401 * standard time in this case.
402 * @param after If true, this rule selects the first dayOfWeek on
403 * or after dayOfMonth. If false, this rule selects
404 * the last dayOfWeek on or before dayOfMonth.
405 * @param status An UErrorCode
408 void setStartRule(int32_t month
, int32_t dayOfMonth
, int32_t dayOfWeek
,
409 int32_t time
, UBool after
, UErrorCode
& status
);
411 * Sets the DST start rule to a weekday before or after a give date within
412 * a month, e.g., the first Monday on or after the 8th.
414 * @param month The month in which this rule occurs (0-based).
415 * @param dayOfMonth A date within that month (1-based).
416 * @param dayOfWeek The day of the week on which this rule occurs.
417 * @param time The time of that day (number of millis after midnight)
418 * when DST takes effect in local wall time, which is
419 * standard time in this case.
420 * @param mode whether the time is local wall time, local standard time,
421 * or UTC time. Default is local wall time.
422 * @param after If true, this rule selects the first dayOfWeek on
423 * or after dayOfMonth. If false, this rule selects
424 * the last dayOfWeek on or before dayOfMonth.
425 * @param status An UErrorCode
428 void setStartRule(int32_t month
, int32_t dayOfMonth
, int32_t dayOfWeek
,
429 int32_t time
, TimeMode mode
, UBool after
, UErrorCode
& status
);
432 * Sets the daylight savings ending rule. For example, if Daylight
433 * Savings Time ends at the last (-1) Sunday in October, at 2 AM in standard time.
434 * Therefore, you can set the end rule by calling:
436 * setEndRule(UCAL_OCTOBER, -1, UCAL_SUNDAY, 2*60*60*1000);
438 * Various other types of rules can be specified by manipulating the dayOfWeek
439 * and dayOfWeekInMonth parameters. For complete details, see the documentation
440 * for setStartRule().
442 * @param month the daylight savings ending month. Month is 0-based.
444 * @param dayOfWeekInMonth the daylight savings ending
445 * day-of-week-in-month. See setStartRule() for a complete explanation.
446 * @param dayOfWeek the daylight savings ending day-of-week. See setStartRule()
447 * for a complete explanation.
448 * @param time the daylight savings ending time. Please see the member
449 * description for an example.
450 * @param status An UErrorCode
453 void setEndRule(int32_t month
, int32_t dayOfWeekInMonth
, int32_t dayOfWeek
,
454 int32_t time
, UErrorCode
& status
);
457 * Sets the daylight savings ending rule. For example, if Daylight
458 * Savings Time ends at the last (-1) Sunday in October, at 2 AM in standard time.
459 * Therefore, you can set the end rule by calling:
461 * setEndRule(UCAL_OCTOBER, -1, UCAL_SUNDAY, 2*60*60*1000);
463 * Various other types of rules can be specified by manipulating the dayOfWeek
464 * and dayOfWeekInMonth parameters. For complete details, see the documentation
465 * for setStartRule().
467 * @param month the daylight savings ending month. Month is 0-based.
469 * @param dayOfWeekInMonth the daylight savings ending
470 * day-of-week-in-month. See setStartRule() for a complete explanation.
471 * @param dayOfWeek the daylight savings ending day-of-week. See setStartRule()
472 * for a complete explanation.
473 * @param time the daylight savings ending time. Please see the member
474 * description for an example.
475 * @param mode whether the time is local wall time, local standard time,
476 * or UTC time. Default is local wall time.
477 * @param status An UErrorCode
480 void setEndRule(int32_t month
, int32_t dayOfWeekInMonth
, int32_t dayOfWeek
,
481 int32_t time
, TimeMode mode
, UErrorCode
& status
);
484 * Sets the DST end rule to a fixed date within a month.
486 * @param month The month in which this rule occurs (0-based).
487 * @param dayOfMonth The date in that month (1-based).
488 * @param time The time of that day (number of millis after midnight)
489 * when DST ends in local wall time, which is daylight
491 * @param status An UErrorCode
494 void setEndRule(int32_t month
, int32_t dayOfMonth
, int32_t time
, UErrorCode
& status
);
497 * Sets the DST end rule to a fixed date within a month.
499 * @param month The month in which this rule occurs (0-based).
500 * @param dayOfMonth The date in that month (1-based).
501 * @param time The time of that day (number of millis after midnight)
502 * when DST ends in local wall time, which is daylight
504 * @param mode whether the time is local wall time, local standard time,
505 * or UTC time. Default is local wall time.
506 * @param status An UErrorCode
509 void setEndRule(int32_t month
, int32_t dayOfMonth
, int32_t time
,
510 TimeMode mode
, UErrorCode
& status
);
513 * Sets the DST end rule to a weekday before or after a give date within
514 * a month, e.g., the first Monday on or after the 8th.
516 * @param month The month in which this rule occurs (0-based).
517 * @param dayOfMonth A date within that month (1-based).
518 * @param dayOfWeek The day of the week on which this rule occurs.
519 * @param time The time of that day (number of millis after midnight)
520 * when DST ends in local wall time, which is daylight
522 * @param after If true, this rule selects the first dayOfWeek on
523 * or after dayOfMonth. If false, this rule selects
524 * the last dayOfWeek on or before dayOfMonth.
525 * @param status An UErrorCode
528 void setEndRule(int32_t month
, int32_t dayOfMonth
, int32_t dayOfWeek
,
529 int32_t time
, UBool after
, UErrorCode
& status
);
532 * Sets the DST end rule to a weekday before or after a give date within
533 * a month, e.g., the first Monday on or after the 8th.
535 * @param month The month in which this rule occurs (0-based).
536 * @param dayOfMonth A date within that month (1-based).
537 * @param dayOfWeek The day of the week on which this rule occurs.
538 * @param time The time of that day (number of millis after midnight)
539 * when DST ends in local wall time, which is daylight
541 * @param mode whether the time is local wall time, local standard time,
542 * or UTC time. Default is local wall time.
543 * @param after If true, this rule selects the first dayOfWeek on
544 * or after dayOfMonth. If false, this rule selects
545 * the last dayOfWeek on or before dayOfMonth.
546 * @param status An UErrorCode
549 void setEndRule(int32_t month
, int32_t dayOfMonth
, int32_t dayOfWeek
,
550 int32_t time
, TimeMode mode
, UBool after
, UErrorCode
& status
);
553 * Returns the TimeZone's adjusted GMT offset (i.e., the number of milliseconds to add
554 * to GMT to get local time in this time zone, taking daylight savings time into
555 * account) as of a particular reference date. The reference date is used to determine
556 * whether daylight savings time is in effect and needs to be figured into the offset
557 * that is returned (in other words, what is the adjusted GMT offset in this time zone
558 * at this particular date and time?). For the time zones produced by createTimeZone(),
559 * the reference data is specified according to the Gregorian calendar, and the date
560 * and time fields are in GMT, NOT local time.
562 * @param era The reference date's era
563 * @param year The reference date's year
564 * @param month The reference date's month (0-based; 0 is January)
565 * @param day The reference date's day-in-month (1-based)
566 * @param dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday)
567 * @param millis The reference date's milliseconds in day, UTT (NOT local time).
568 * @param status An UErrorCode to receive the status.
569 * @return The offset in milliseconds to add to GMT to get local time.
572 virtual int32_t getOffset(uint8_t era
, int32_t year
, int32_t month
, int32_t day
,
573 uint8_t dayOfWeek
, int32_t millis
, UErrorCode
& status
) const;
576 * Gets the time zone offset, for current date, modified in case of
577 * daylight savings. This is the offset to add *to* UTC to get local time.
578 * @param era the era of the given date.
579 * @param year the year in the given date.
580 * @param month the month in the given date.
581 * Month is 0-based. e.g., 0 for January.
582 * @param day the day-in-month of the given date.
583 * @param dayOfWeek the day-of-week of the given date.
584 * @param milliseconds the millis in day in <em>standard</em> local time.
585 * @param monthLength the length of the given month in days.
586 * @param status An UErrorCode to receive the status.
587 * @return the offset to add *to* GMT to get local time.
590 virtual int32_t getOffset(uint8_t era
, int32_t year
, int32_t month
, int32_t day
,
591 uint8_t dayOfWeek
, int32_t milliseconds
,
592 int32_t monthLength
, UErrorCode
& status
) const;
594 * Gets the time zone offset, for current date, modified in case of
595 * daylight savings. This is the offset to add *to* UTC to get local time.
596 * @param era the era of the given date.
597 * @param year the year in the given date.
598 * @param month the month in the given date.
599 * Month is 0-based. e.g., 0 for January.
600 * @param day the day-in-month of the given date.
601 * @param dayOfWeek the day-of-week of the given date.
602 * @param milliseconds the millis in day in <em>standard</em> local time.
603 * @param monthLength the length of the given month in days.
604 * @param prevMonthLength length of the previous month in days.
605 * @param status An UErrorCode to receive the status.
606 * @return the offset to add *to* GMT to get local time.
609 virtual int32_t getOffset(uint8_t era
, int32_t year
, int32_t month
, int32_t day
,
610 uint8_t dayOfWeek
, int32_t milliseconds
,
611 int32_t monthLength
, int32_t prevMonthLength
,
612 UErrorCode
& status
) const;
615 * Redeclared TimeZone method. This implementation simply calls
616 * the base class method, which otherwise would be hidden.
619 virtual void getOffset(UDate date
, UBool local
, int32_t& rawOffset
,
620 int32_t& dstOffset
, UErrorCode
& ec
) const;
623 * Get time zone offsets from local wall time.
626 virtual void getOffsetFromLocal(UDate date
, int32_t nonExistingTimeOpt
, int32_t duplicatedTimeOpt
,
627 int32_t& rawOffset
, int32_t& dstOffset
, UErrorCode
& status
) const;
630 * Returns the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
631 * to GMT to get local time, before taking daylight savings time into account).
633 * @return The TimeZone's raw GMT offset.
636 virtual int32_t getRawOffset(void) const;
639 * Sets the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
640 * to GMT to get local time, before taking daylight savings time into account).
642 * @param offsetMillis The new raw GMT offset for this time zone.
645 virtual void setRawOffset(int32_t offsetMillis
);
648 * Sets the amount of time in ms that the clock is advanced during DST.
649 * @param millisSavedDuringDST the number of milliseconds the time is
650 * advanced with respect to standard time when the daylight savings rules
651 * are in effect. Typically one hour (+3600000). The amount could be negative,
653 * @param status An UErrorCode to receive the status.
656 void setDSTSavings(int32_t millisSavedDuringDST
, UErrorCode
& status
);
659 * Returns the amount of time in ms that the clock is advanced during DST.
660 * @return the number of milliseconds the time is
661 * advanced with respect to standard time when the daylight savings rules
662 * are in effect. Typically one hour (+3600000). The amount could be negative,
666 virtual int32_t getDSTSavings(void) const;
669 * Queries if this TimeZone uses Daylight Savings Time.
671 * @return True if this TimeZone uses Daylight Savings Time; false otherwise.
674 virtual UBool
useDaylightTime(void) const;
677 * Returns true if the given date is within the period when daylight savings time
678 * is in effect; false otherwise. If the TimeZone doesn't observe daylight savings
679 * time, this functions always returns false.
680 * This method is wasteful since it creates a new GregorianCalendar and
681 * deletes it each time it is called. This is a deprecated method
682 * and provided only for Java compatibility.
684 * @param date The date to test.
685 * @param status An UErrorCode to receive the status.
686 * @return true if the given date is in Daylight Savings Time;
688 * @deprecated ICU 2.4. Use Calendar::inDaylightTime() instead.
690 virtual UBool
inDaylightTime(UDate date
, UErrorCode
& status
) const;
693 * Return true if this zone has the same rules and offset as another zone.
694 * @param other the TimeZone object to be compared with
695 * @return true if the given zone has the same rules and offset as this one
698 UBool
hasSameRules(const TimeZone
& other
) const;
701 * Clones TimeZone objects polymorphically. Clients are responsible for deleting
702 * the TimeZone object cloned.
704 * @return A new copy of this TimeZone object.
707 virtual TimeZone
* clone(void) const;
710 * Gets the first time zone transition after the base time.
711 * @param base The base time.
712 * @param inclusive Whether the base time is inclusive or not.
713 * @param result Receives the first transition after the base time.
714 * @return TRUE if the transition is found.
717 virtual UBool
getNextTransition(UDate base
, UBool inclusive
, TimeZoneTransition
& result
) const;
720 * Gets the most recent time zone transition before the base time.
721 * @param base The base time.
722 * @param inclusive Whether the base time is inclusive or not.
723 * @param result Receives the most recent transition before the base time.
724 * @return TRUE if the transition is found.
727 virtual UBool
getPreviousTransition(UDate base
, UBool inclusive
, TimeZoneTransition
& result
) const;
730 * Returns the number of <code>TimeZoneRule</code>s which represents time transitions,
731 * for this time zone, that is, all <code>TimeZoneRule</code>s for this time zone except
732 * <code>InitialTimeZoneRule</code>. The return value range is 0 or any positive value.
733 * @param status Receives error status code.
734 * @return The number of <code>TimeZoneRule</code>s representing time transitions.
737 virtual int32_t countTransitionRules(UErrorCode
& status
) const;
740 * Gets the <code>InitialTimeZoneRule</code> and the set of <code>TimeZoneRule</code>
741 * which represent time transitions for this time zone. On successful return,
742 * the argument initial points to non-NULL <code>InitialTimeZoneRule</code> and
743 * the array trsrules is filled with 0 or multiple <code>TimeZoneRule</code>
744 * instances up to the size specified by trscount. The results are referencing the
745 * rule instance held by this time zone instance. Therefore, after this time zone
746 * is destructed, they are no longer available.
747 * @param initial Receives the initial timezone rule
748 * @param trsrules Receives the timezone transition rules
749 * @param trscount On input, specify the size of the array 'transitions' receiving
750 * the timezone transition rules. On output, actual number of
751 * rules filled in the array will be set.
752 * @param status Receives error status code.
755 virtual void getTimeZoneRules(const InitialTimeZoneRule
*& initial
,
756 const TimeZoneRule
* trsrules
[], int32_t& trscount
, UErrorCode
& status
) const;
762 * Override TimeZone Returns a unique class ID POLYMORPHICALLY. Pure virtual
763 * override. This method is to implement a simple version of RTTI, since not all C++
764 * compilers support genuine RTTI. Polymorphic operator==() and clone() methods call
767 * @return The class ID for this object. All objects of a given class have the
768 * same class ID. Objects of other classes have different class IDs.
771 virtual UClassID
getDynamicClassID(void) const;
774 * Return the class ID for this class. This is useful only for comparing to a return
775 * value from getDynamicClassID(). For example:
777 * . Base* polymorphic_pointer = createPolymorphicObject();
778 * . if (polymorphic_pointer->getDynamicClassID() ==
779 * . Derived::getStaticClassID()) ...
781 * @return The class ID for all objects of this class.
784 static UClassID U_EXPORT2
getStaticClassID(void);
788 * Constants specifying values of startMode and endMode.
798 SimpleTimeZone(); // default constructor not implemented
801 * Internal construction method.
802 * @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset
803 * @param startMonth the month DST starts
804 * @param startDay the day DST starts
805 * @param startDayOfWeek the DOW DST starts
806 * @param startTime the time DST starts
807 * @param startTimeMode Whether the start time is local wall time, local
808 * standard time, or UTC time. Default is local wall time.
809 * @param endMonth the month DST ends
810 * @param endDay the day DST ends
811 * @param endDayOfWeek the DOW DST ends
812 * @param endTime the time DST ends
813 * @param endTimeMode Whether the end time is local wall time, local
814 * standard time, or UTC time. Default is local wall time.
815 * @param dstSavings The number of milliseconds added to standard time
816 * to get DST time. Default is one hour.
817 * @param status An UErrorCode to receive the status.
819 void construct(int32_t rawOffsetGMT
,
820 int8_t startMonth
, int8_t startDay
, int8_t startDayOfWeek
,
821 int32_t startTime
, TimeMode startTimeMode
,
822 int8_t endMonth
, int8_t endDay
, int8_t endDayOfWeek
,
823 int32_t endTime
, TimeMode endTimeMode
,
824 int32_t dstSavings
, UErrorCode
& status
);
827 * Compare a given date in the year to a rule. Return 1, 0, or -1, depending
828 * on whether the date is after, equal to, or before the rule date. The
829 * millis are compared directly against the ruleMillis, so any
830 * standard-daylight adjustments must be handled by the caller.
832 * @return 1 if the date is after the rule date, -1 if the date is before
833 * the rule date, or 0 if the date is equal to the rule date.
835 static int32_t compareToRule(int8_t month
, int8_t monthLen
, int8_t prevMonthLen
,
837 int8_t dayOfWeek
, int32_t millis
, int32_t millisDelta
,
838 EMode ruleMode
, int8_t ruleMonth
, int8_t ruleDayOfWeek
,
839 int8_t ruleDay
, int32_t ruleMillis
);
842 * Given a set of encoded rules in startDay and startDayOfMonth, decode
843 * them and set the startMode appropriately. Do the same for endDay and
846 * Upon entry, the day of week variables may be zero or
847 * negative, in order to indicate special modes. The day of month
848 * variables may also be negative.
850 * Upon exit, the mode variables will be
851 * set, and the day of week and day of month variables will be positive.
853 * This method also recognizes a startDay or endDay of zero as indicating
856 void decodeRules(UErrorCode
& status
);
857 void decodeStartRule(UErrorCode
& status
);
858 void decodeEndRule(UErrorCode
& status
);
860 int8_t startMonth
, startDay
, startDayOfWeek
; // the month, day, DOW, and time DST starts
862 TimeMode startTimeMode
, endTimeMode
; // Mode for startTime, endTime; see TimeMode
863 int8_t endMonth
, endDay
, endDayOfWeek
; // the month, day, DOW, and time DST ends
865 int32_t startYear
; // the year these DST rules took effect
866 int32_t rawOffset
; // the TimeZone's raw GMT offset
867 UBool useDaylight
; // flag indicating whether this TimeZone uses DST
868 static const int8_t STATICMONTHLENGTH
[12]; // lengths of the months
869 EMode startMode
, endMode
; // flags indicating what kind of rules the DST rules are
872 * A positive value indicating the amount of time saved during DST in ms.
873 * Typically one hour; sometimes 30 minutes.
877 /* Private for BasicTimeZone implementation */
878 void checkTransitionRules(UErrorCode
& status
) const;
879 void initTransitionRules(UErrorCode
& status
);
880 void clearTransitionRules(void);
881 void deleteTransitionRules(void);
882 UBool transitionRulesInitialized
;
883 InitialTimeZoneRule
* initialRule
;
884 TimeZoneTransition
* firstTransition
;
885 AnnualTimeZoneRule
* stdRule
;
886 AnnualTimeZoneRule
* dstRule
;
889 inline void SimpleTimeZone::setStartRule(int32_t month
, int32_t dayOfWeekInMonth
,
891 int32_t time
, UErrorCode
& status
) {
892 setStartRule(month
, dayOfWeekInMonth
, dayOfWeek
, time
, WALL_TIME
, status
);
895 inline void SimpleTimeZone::setStartRule(int32_t month
, int32_t dayOfMonth
,
897 UErrorCode
& status
) {
898 setStartRule(month
, dayOfMonth
, time
, WALL_TIME
, status
);
901 inline void SimpleTimeZone::setStartRule(int32_t month
, int32_t dayOfMonth
,
903 int32_t time
, UBool after
, UErrorCode
& status
) {
904 setStartRule(month
, dayOfMonth
, dayOfWeek
, time
, WALL_TIME
, after
, status
);
907 inline void SimpleTimeZone::setEndRule(int32_t month
, int32_t dayOfWeekInMonth
,
909 int32_t time
, UErrorCode
& status
) {
910 setEndRule(month
, dayOfWeekInMonth
, dayOfWeek
, time
, WALL_TIME
, status
);
913 inline void SimpleTimeZone::setEndRule(int32_t month
, int32_t dayOfMonth
,
914 int32_t time
, UErrorCode
& status
) {
915 setEndRule(month
, dayOfMonth
, time
, WALL_TIME
, status
);
918 inline void SimpleTimeZone::setEndRule(int32_t month
, int32_t dayOfMonth
, int32_t dayOfWeek
,
919 int32_t time
, UBool after
, UErrorCode
& status
) {
920 setEndRule(month
, dayOfMonth
, dayOfWeek
, time
, WALL_TIME
, after
, status
);
924 SimpleTimeZone::getOffset(UDate date
, UBool local
, int32_t& rawOffsetRef
,
925 int32_t& dstOffsetRef
, UErrorCode
& ec
) const {
926 TimeZone::getOffset(date
, local
, rawOffsetRef
, dstOffsetRef
, ec
);
930 #endif // U_SHOW_CPLUSPLUS_API
932 #endif /* #if !UCONFIG_NO_FORMATTING */