2 * Copyright (C) {1997-2004}, International Business Machines Corporation and others. All Rights Reserved.
4 ********************************************************************************
8 * Modification History:
10 * Date Name Description
11 * 04/21/97 aliu Overhauled header.
12 * 08/10/98 stephen JDK 1.2 sync
13 * Added setStartRule() / setEndRule() overloads
14 * Added hasSameRules()
15 * 09/02/98 stephen Added getOffset(monthLen)
16 * Changed getOffset() to take UErrorCode
17 * 07/09/99 stephen Removed millisPerHour (unused, for HP compiler)
18 * 12/02/99 aliu Added TimeMode and constructor and setStart/EndRule
19 * methods that take TimeMode. Added to docs.
20 ********************************************************************************
26 #include "unicode/utypes.h"
28 #if !UCONFIG_NO_FORMATTING
30 #include "unicode/timezone.h"
35 * <code>SimpleTimeZone</code> is a concrete subclass of <code>TimeZone</code>
36 * that represents a time zone for use with a Gregorian calendar. This
37 * class does not handle historical changes.
39 * When specifying daylight-savings-time begin and end dates, use a negative value for
40 * <code>dayOfWeekInMonth</code> to indicate that <code>SimpleTimeZone</code> should
41 * count from the end of the month backwards. For example, in the U.S., Daylight Savings
42 * Time ends at the last (dayOfWeekInMonth = -1) Sunday in October, at 2 AM in standard
46 * @see GregorianCalendar
48 * @author D. Goldsmith, Mark Davis, Chen-Lieh Huang, Alan Liu
50 class U_I18N_API SimpleTimeZone
: public TimeZone
{
54 * TimeMode is used, together with a millisecond offset after
55 * midnight, to specify a rule transition time. Most rules
56 * transition at a local wall time, that is, according to the
57 * current time in effect, either standard, or DST. However, some
58 * rules transition at local standard time, and some at a specific
59 * UTC time. Although it might seem that all times could be
60 * converted to wall time, thus eliminating the need for this
61 * parameter, this is not the case.
72 * @param source the object to be copied.
75 SimpleTimeZone(const SimpleTimeZone
& source
);
78 * Default assignment operator
79 * @param right the object to be copied.
82 SimpleTimeZone
& operator=(const SimpleTimeZone
& right
);
88 virtual ~SimpleTimeZone();
91 * Returns true if the two TimeZone objects are equal; that is, they have
92 * the same ID, raw GMT offset, and DST rules.
94 * @param that The SimpleTimeZone object to be compared with.
95 * @return True if the given time zone is equal to this time zone; false
99 virtual UBool
operator==(const TimeZone
& that
) const;
102 * Constructs a SimpleTimeZone with the given raw GMT offset and time zone ID,
103 * and which doesn't observe daylight savings time. Normally you should use
104 * TimeZone::createInstance() to create a TimeZone instead of creating a
105 * SimpleTimeZone directly with this constructor.
107 * @param rawOffsetGMT The given base time zone offset to GMT.
108 * @param ID The timezone ID which is obtained from
109 * TimeZone.getAvailableIDs.
112 SimpleTimeZone(int32_t rawOffsetGMT
, const UnicodeString
& ID
);
115 * Construct a SimpleTimeZone with the given raw GMT offset, time zone ID,
116 * and times to start and end daylight savings time. To create a TimeZone that
117 * doesn't observe daylight savings time, don't use this constructor; use
118 * SimpleTimeZone(rawOffset, ID) instead. Normally, you should use
119 * TimeZone.createInstance() to create a TimeZone instead of creating a
120 * SimpleTimeZone directly with this constructor.
122 * Various types of daylight-savings time rules can be specfied by using different
123 * values for startDay and startDayOfWeek and endDay and endDayOfWeek. For a
124 * complete explanation of how these parameters work, see the documentation for
127 * @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset
128 * @param ID The new SimpleTimeZone's time zone ID.
129 * @param savingsStartMonth The daylight savings starting month. Month is
130 * 0-based. eg, 0 for January.
131 * @param savingsStartDayOfWeekInMonth The daylight savings starting
132 * day-of-week-in-month. See setStartRule() for a
133 * complete explanation.
134 * @param savingsStartDayOfWeek The daylight savings starting day-of-week.
135 * See setStartRule() for a complete explanation.
136 * @param savingsStartTime The daylight savings starting time, expressed as the
137 * number of milliseconds after midnight.
138 * @param savingsEndMonth The daylight savings ending month. Month is
139 * 0-based. eg, 0 for January.
140 * @param savingsEndDayOfWeekInMonth The daylight savings ending day-of-week-in-month.
141 * See setStartRule() for a complete explanation.
142 * @param savingsEndDayOfWeek The daylight savings ending day-of-week.
143 * See setStartRule() for a complete explanation.
144 * @param savingsEndTime The daylight savings ending time, expressed as the
145 * number of milliseconds after midnight.
146 * @param status An UErrorCode to receive the status.
149 SimpleTimeZone(int32_t rawOffsetGMT
, const UnicodeString
& ID
,
150 int8_t savingsStartMonth
, int8_t savingsStartDayOfWeekInMonth
,
151 int8_t savingsStartDayOfWeek
, int32_t savingsStartTime
,
152 int8_t savingsEndMonth
, int8_t savingsEndDayOfWeekInMonth
,
153 int8_t savingsEndDayOfWeek
, int32_t savingsEndTime
,
156 * Construct a SimpleTimeZone with the given raw GMT offset, time zone ID,
157 * and times to start and end daylight savings time. To create a TimeZone that
158 * doesn't observe daylight savings time, don't use this constructor; use
159 * SimpleTimeZone(rawOffset, ID) instead. Normally, you should use
160 * TimeZone.createInstance() to create a TimeZone instead of creating a
161 * SimpleTimeZone directly with this constructor.
163 * Various types of daylight-savings time rules can be specfied by using different
164 * values for startDay and startDayOfWeek and endDay and endDayOfWeek. For a
165 * complete explanation of how these parameters work, see the documentation for
168 * @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset
169 * @param ID The new SimpleTimeZone's time zone ID.
170 * @param savingsStartMonth The daylight savings starting month. Month is
171 * 0-based. eg, 0 for January.
172 * @param savingsStartDayOfWeekInMonth The daylight savings starting
173 * day-of-week-in-month. See setStartRule() for a
174 * complete explanation.
175 * @param savingsStartDayOfWeek The daylight savings starting day-of-week.
176 * See setStartRule() for a complete explanation.
177 * @param savingsStartTime The daylight savings starting time, expressed as the
178 * number of milliseconds after midnight.
179 * @param savingsEndMonth The daylight savings ending month. Month is
180 * 0-based. eg, 0 for January.
181 * @param savingsEndDayOfWeekInMonth The daylight savings ending day-of-week-in-month.
182 * See setStartRule() for a complete explanation.
183 * @param savingsEndDayOfWeek The daylight savings ending day-of-week.
184 * See setStartRule() for a complete explanation.
185 * @param savingsEndTime The daylight savings ending time, expressed as the
186 * number of milliseconds after midnight.
187 * @param savingsDST The number of milliseconds added to standard time
188 * to get DST time. Default is one hour.
189 * @param status An UErrorCode to receive the status.
192 SimpleTimeZone(int32_t rawOffsetGMT
, const UnicodeString
& ID
,
193 int8_t savingsStartMonth
, int8_t savingsStartDayOfWeekInMonth
,
194 int8_t savingsStartDayOfWeek
, int32_t savingsStartTime
,
195 int8_t savingsEndMonth
, int8_t savingsEndDayOfWeekInMonth
,
196 int8_t savingsEndDayOfWeek
, int32_t savingsEndTime
,
197 int32_t savingsDST
, UErrorCode
& status
);
200 * Construct a SimpleTimeZone with the given raw GMT offset, time zone ID,
201 * and times to start and end daylight savings time. To create a TimeZone that
202 * doesn't observe daylight savings time, don't use this constructor; use
203 * SimpleTimeZone(rawOffset, ID) instead. Normally, you should use
204 * TimeZone.createInstance() to create a TimeZone instead of creating a
205 * SimpleTimeZone directly with this constructor.
207 * Various types of daylight-savings time rules can be specfied by using different
208 * values for startDay and startDayOfWeek and endDay and endDayOfWeek. For a
209 * complete explanation of how these parameters work, see the documentation for
212 * @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset
213 * @param ID The new SimpleTimeZone's time zone ID.
214 * @param savingsStartMonth The daylight savings starting month. Month is
215 * 0-based. eg, 0 for January.
216 * @param savingsStartDayOfWeekInMonth The daylight savings starting
217 * day-of-week-in-month. See setStartRule() for a
218 * complete explanation.
219 * @param savingsStartDayOfWeek The daylight savings starting day-of-week.
220 * See setStartRule() for a complete explanation.
221 * @param savingsStartTime The daylight savings starting time, expressed as the
222 * number of milliseconds after midnight.
223 * @param savingsStartTimeMode Whether the start time is local wall time, local
224 * standard time, or UTC time. Default is local wall time.
225 * @param savingsEndMonth The daylight savings ending month. Month is
226 * 0-based. eg, 0 for January.
227 * @param savingsEndDayOfWeekInMonth The daylight savings ending day-of-week-in-month.
228 * See setStartRule() for a complete explanation.
229 * @param savingsEndDayOfWeek The daylight savings ending day-of-week.
230 * See setStartRule() for a complete explanation.
231 * @param savingsEndTime The daylight savings ending time, expressed as the
232 * number of milliseconds after midnight.
233 * @param savingsEndTimeMode Whether the end time is local wall time, local
234 * standard time, or UTC time. Default is local wall time.
235 * @param savingsDST The number of milliseconds added to standard time
236 * to get DST time. Default is one hour.
237 * @param status An UErrorCode to receive the status.
240 SimpleTimeZone(int32_t rawOffsetGMT
, const UnicodeString
& ID
,
241 int8_t savingsStartMonth
, int8_t savingsStartDayOfWeekInMonth
,
242 int8_t savingsStartDayOfWeek
, int32_t savingsStartTime
,
243 TimeMode savingsStartTimeMode
,
244 int8_t savingsEndMonth
, int8_t savingsEndDayOfWeekInMonth
,
245 int8_t savingsEndDayOfWeek
, int32_t savingsEndTime
, TimeMode savingsEndTimeMode
,
246 int32_t savingsDST
, UErrorCode
& status
);
249 * Sets the daylight savings starting year, that is, the year this time zone began
250 * observing its specified daylight savings time rules. The time zone is considered
251 * not to observe daylight savings time prior to that year; SimpleTimeZone doesn't
252 * support historical daylight-savings-time rules.
253 * @param year the daylight savings starting year.
256 void setStartYear(int32_t year
);
259 * Sets the daylight savings starting rule. For example, in the U.S., Daylight Savings
260 * Time starts at the first Sunday in April, at 2 AM in standard time.
261 * Therefore, you can set the start rule by calling:
262 * setStartRule(TimeFields.APRIL, 1, TimeFields.SUNDAY, 2*60*60*1000);
263 * The dayOfWeekInMonth and dayOfWeek parameters together specify how to calculate
264 * the exact starting date. Their exact meaning depend on their respective signs,
265 * allowing various types of rules to be constructed, as follows:
267 * <li>If both dayOfWeekInMonth and dayOfWeek are positive, they specify the
268 * day of week in the month (e.g., (2, WEDNESDAY) is the second Wednesday
269 * of the month).</li>
270 * <li>If dayOfWeek is positive and dayOfWeekInMonth is negative, they specify
271 * the day of week in the month counting backward from the end of the month.
272 * (e.g., (-1, MONDAY) is the last Monday in the month)</li>
273 * <li>If dayOfWeek is zero and dayOfWeekInMonth is positive, dayOfWeekInMonth
274 * specifies the day of the month, regardless of what day of the week it is.
275 * (e.g., (10, 0) is the tenth day of the month)</li>
276 * <li>If dayOfWeek is zero and dayOfWeekInMonth is negative, dayOfWeekInMonth
277 * specifies the day of the month counting backward from the end of the
278 * month, regardless of what day of the week it is (e.g., (-2, 0) is the
279 * next-to-last day of the month).</li>
280 * <li>If dayOfWeek is negative and dayOfWeekInMonth is positive, they specify the
281 * first specified day of the week on or after the specfied day of the month.
282 * (e.g., (15, -SUNDAY) is the first Sunday after the 15th of the month
283 * [or the 15th itself if the 15th is a Sunday].)</li>
284 * <li>If dayOfWeek and DayOfWeekInMonth are both negative, they specify the
285 * last specified day of the week on or before the specified day of the month.
286 * (e.g., (-20, -TUESDAY) is the last Tuesday before the 20th of the month
287 * [or the 20th itself if the 20th is a Tuesday].)</li>
289 * @param month the daylight savings starting month. Month is 0-based.
291 * @param dayOfWeekInMonth the daylight savings starting
292 * day-of-week-in-month. Please see the member description for an example.
293 * @param dayOfWeek the daylight savings starting day-of-week. Please see
294 * the member description for an example.
295 * @param time the daylight savings starting time. Please see the member
296 * description for an example.
297 * @param status An UErrorCode
300 void setStartRule(int32_t month
, int32_t dayOfWeekInMonth
, int32_t dayOfWeek
,
301 int32_t time
, UErrorCode
& status
);
303 * Sets the daylight savings starting rule. For example, in the U.S., Daylight Savings
304 * Time starts at the first Sunday in April, at 2 AM in standard time.
305 * Therefore, you can set the start rule by calling:
306 * setStartRule(TimeFields.APRIL, 1, TimeFields.SUNDAY, 2*60*60*1000);
307 * The dayOfWeekInMonth and dayOfWeek parameters together specify how to calculate
308 * the exact starting date. Their exact meaning depend on their respective signs,
309 * allowing various types of rules to be constructed, as follows:
311 * <li>If both dayOfWeekInMonth and dayOfWeek are positive, they specify the
312 * day of week in the month (e.g., (2, WEDNESDAY) is the second Wednesday
313 * of the month).</li>
314 * <li>If dayOfWeek is positive and dayOfWeekInMonth is negative, they specify
315 * the day of week in the month counting backward from the end of the month.
316 * (e.g., (-1, MONDAY) is the last Monday in the month)</li>
317 * <li>If dayOfWeek is zero and dayOfWeekInMonth is positive, dayOfWeekInMonth
318 * specifies the day of the month, regardless of what day of the week it is.
319 * (e.g., (10, 0) is the tenth day of the month)</li>
320 * <li>If dayOfWeek is zero and dayOfWeekInMonth is negative, dayOfWeekInMonth
321 * specifies the day of the month counting backward from the end of the
322 * month, regardless of what day of the week it is (e.g., (-2, 0) is the
323 * next-to-last day of the month).</li>
324 * <li>If dayOfWeek is negative and dayOfWeekInMonth is positive, they specify the
325 * first specified day of the week on or after the specfied day of the month.
326 * (e.g., (15, -SUNDAY) is the first Sunday after the 15th of the month
327 * [or the 15th itself if the 15th is a Sunday].)</li>
328 * <li>If dayOfWeek and DayOfWeekInMonth are both negative, they specify the
329 * last specified day of the week on or before the specified day of the month.
330 * (e.g., (-20, -TUESDAY) is the last Tuesday before the 20th of the month
331 * [or the 20th itself if the 20th is a Tuesday].)</li>
333 * @param month the daylight savings starting month. Month is 0-based.
335 * @param dayOfWeekInMonth the daylight savings starting
336 * day-of-week-in-month. Please see the member description for an example.
337 * @param dayOfWeek the daylight savings starting day-of-week. Please see
338 * the member description for an example.
339 * @param time the daylight savings starting time. Please see the member
340 * description for an example.
341 * @param mode whether the time is local wall time, local standard time,
342 * or UTC time. Default is local wall time.
343 * @param status An UErrorCode
346 void setStartRule(int32_t month
, int32_t dayOfWeekInMonth
, int32_t dayOfWeek
,
347 int32_t time
, TimeMode mode
, UErrorCode
& status
);
350 * Sets the DST start rule to a fixed date within a month.
352 * @param month The month in which this rule occurs (0-based).
353 * @param dayOfMonth The date in that month (1-based).
354 * @param time The time of that day (number of millis after midnight)
355 * when DST takes effect in local wall time, which is
356 * standard time in this case.
357 * @param status An UErrorCode
360 void setStartRule(int32_t month
, int32_t dayOfMonth
, int32_t time
,
363 * Sets the DST start rule to a fixed date within a month.
365 * @param month The month in which this rule occurs (0-based).
366 * @param dayOfMonth The date in that month (1-based).
367 * @param time The time of that day (number of millis after midnight)
368 * when DST takes effect in local wall time, which is
369 * standard time in this case.
370 * @param mode whether the time is local wall time, local standard time,
371 * or UTC time. Default is local wall time.
372 * @param status An UErrorCode
375 void setStartRule(int32_t month
, int32_t dayOfMonth
, int32_t time
,
376 TimeMode mode
, UErrorCode
& status
);
379 * Sets the DST start rule to a weekday before or after a give date within
380 * a month, e.g., the first Monday on or after the 8th.
382 * @param month The month in which this rule occurs (0-based).
383 * @param dayOfMonth A date within that month (1-based).
384 * @param dayOfWeek The day of the week on which this rule occurs.
385 * @param time The time of that day (number of millis after midnight)
386 * when DST takes effect in local wall time, which is
387 * standard time in this case.
388 * @param after If true, this rule selects the first dayOfWeek on
389 * or after dayOfMonth. If false, this rule selects
390 * the last dayOfWeek on or before dayOfMonth.
391 * @param status An UErrorCode
394 void setStartRule(int32_t month
, int32_t dayOfMonth
, int32_t dayOfWeek
,
395 int32_t time
, UBool after
, UErrorCode
& status
);
397 * Sets the DST start rule to a weekday before or after a give date within
398 * a month, e.g., the first Monday on or after the 8th.
400 * @param month The month in which this rule occurs (0-based).
401 * @param dayOfMonth A date within that month (1-based).
402 * @param dayOfWeek The day of the week on which this rule occurs.
403 * @param time The time of that day (number of millis after midnight)
404 * when DST takes effect in local wall time, which is
405 * standard time in this case.
406 * @param mode whether the time is local wall time, local standard time,
407 * or UTC time. Default is local wall time.
408 * @param after If true, this rule selects the first dayOfWeek on
409 * or after dayOfMonth. If false, this rule selects
410 * the last dayOfWeek on or before dayOfMonth.
411 * @param status An UErrorCode
414 void setStartRule(int32_t month
, int32_t dayOfMonth
, int32_t dayOfWeek
,
415 int32_t time
, TimeMode mode
, UBool after
, UErrorCode
& status
);
418 * Sets the daylight savings ending rule. For example, in the U.S., Daylight
419 * Savings Time ends at the last (-1) Sunday in October, at 2 AM in standard time.
420 * Therefore, you can set the end rule by calling:
422 * . setEndRule(TimeFields.OCTOBER, -1, TimeFields.SUNDAY, 2*60*60*1000);
424 * Various other types of rules can be specified by manipulating the dayOfWeek
425 * and dayOfWeekInMonth parameters. For complete details, see the documentation
426 * for setStartRule().
428 * @param month the daylight savings ending month. Month is 0-based.
430 * @param dayOfWeekInMonth the daylight savings ending
431 * day-of-week-in-month. See setStartRule() for a complete explanation.
432 * @param dayOfWeek the daylight savings ending day-of-week. See setStartRule()
433 * for a complete explanation.
434 * @param time the daylight savings ending time. Please see the member
435 * description for an example.
436 * @param status An UErrorCode
439 void setEndRule(int32_t month
, int32_t dayOfWeekInMonth
, int32_t dayOfWeek
,
440 int32_t time
, UErrorCode
& status
);
443 * Sets the daylight savings ending rule. For example, in the U.S., Daylight
444 * Savings Time ends at the last (-1) Sunday in October, at 2 AM in standard time.
445 * Therefore, you can set the end rule by calling:
447 * . setEndRule(TimeFields.OCTOBER, -1, TimeFields.SUNDAY, 2*60*60*1000);
449 * Various other types of rules can be specified by manipulating the dayOfWeek
450 * and dayOfWeekInMonth parameters. For complete details, see the documentation
451 * for setStartRule().
453 * @param month the daylight savings ending month. Month is 0-based.
455 * @param dayOfWeekInMonth the daylight savings ending
456 * day-of-week-in-month. See setStartRule() for a complete explanation.
457 * @param dayOfWeek the daylight savings ending day-of-week. See setStartRule()
458 * for a complete explanation.
459 * @param time the daylight savings ending time. Please see the member
460 * description for an example.
461 * @param mode whether the time is local wall time, local standard time,
462 * or UTC time. Default is local wall time.
463 * @param status An UErrorCode
466 void setEndRule(int32_t month
, int32_t dayOfWeekInMonth
, int32_t dayOfWeek
,
467 int32_t time
, TimeMode mode
, UErrorCode
& status
);
470 * Sets the DST end rule to a fixed date within a month.
472 * @param month The month in which this rule occurs (0-based).
473 * @param dayOfMonth The date in that month (1-based).
474 * @param time The time of that day (number of millis after midnight)
475 * when DST ends in local wall time, which is daylight
477 * @param status An UErrorCode
480 void setEndRule(int32_t month
, int32_t dayOfMonth
, int32_t time
, UErrorCode
& status
);
483 * Sets the DST end rule to a fixed date within a month.
485 * @param month The month in which this rule occurs (0-based).
486 * @param dayOfMonth The date in that month (1-based).
487 * @param time The time of that day (number of millis after midnight)
488 * when DST ends in local wall time, which is daylight
490 * @param mode whether the time is local wall time, local standard time,
491 * or UTC time. Default is local wall time.
492 * @param status An UErrorCode
495 void setEndRule(int32_t month
, int32_t dayOfMonth
, int32_t time
,
496 TimeMode mode
, UErrorCode
& status
);
499 * Sets the DST end rule to a weekday before or after a give date within
500 * a month, e.g., the first Monday on or after the 8th.
502 * @param month The month in which this rule occurs (0-based).
503 * @param dayOfMonth A date within that month (1-based).
504 * @param dayOfWeek The day of the week on which this rule occurs.
505 * @param time The time of that day (number of millis after midnight)
506 * when DST ends in local wall time, which is daylight
508 * @param after If true, this rule selects the first dayOfWeek on
509 * or after dayOfMonth. If false, this rule selects
510 * the last dayOfWeek on or before dayOfMonth.
511 * @param status An UErrorCode
514 void setEndRule(int32_t month
, int32_t dayOfMonth
, int32_t dayOfWeek
,
515 int32_t time
, UBool after
, UErrorCode
& status
);
518 * Sets the DST end rule to a weekday before or after a give date within
519 * a month, e.g., the first Monday on or after the 8th.
521 * @param month The month in which this rule occurs (0-based).
522 * @param dayOfMonth A date within that month (1-based).
523 * @param dayOfWeek The day of the week on which this rule occurs.
524 * @param time The time of that day (number of millis after midnight)
525 * when DST ends in local wall time, which is daylight
527 * @param mode whether the time is local wall time, local standard time,
528 * or UTC time. Default is local wall time.
529 * @param after If true, this rule selects the first dayOfWeek on
530 * or after dayOfMonth. If false, this rule selects
531 * the last dayOfWeek on or before dayOfMonth.
532 * @param status An UErrorCode
535 void setEndRule(int32_t month
, int32_t dayOfMonth
, int32_t dayOfWeek
,
536 int32_t time
, TimeMode mode
, UBool after
, UErrorCode
& status
);
539 * Returns the TimeZone's adjusted GMT offset (i.e., the number of milliseconds to add
540 * to GMT to get local time in this time zone, taking daylight savings time into
541 * account) as of a particular reference date. The reference date is used to determine
542 * whether daylight savings time is in effect and needs to be figured into the offset
543 * that is returned (in other words, what is the adjusted GMT offset in this time zone
544 * at this particular date and time?). For the time zones produced by createTimeZone(),
545 * the reference data is specified according to the Gregorian calendar, and the date
546 * and time fields are in GMT, NOT local time.
548 * @param era The reference date's era
549 * @param year The reference date's year
550 * @param month The reference date's month (0-based; 0 is January)
551 * @param day The reference date's day-in-month (1-based)
552 * @param dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday)
553 * @param millis The reference date's milliseconds in day, UTT (NOT local time).
554 * @param status An UErrorCode to receive the status.
555 * @return The offset in milliseconds to add to GMT to get local time.
558 virtual int32_t getOffset(uint8_t era
, int32_t year
, int32_t month
, int32_t day
,
559 uint8_t dayOfWeek
, int32_t millis
, UErrorCode
& status
) const;
562 * Gets the time zone offset, for current date, modified in case of
563 * daylight savings. This is the offset to add *to* UTC to get local time.
564 * @param era the era of the given date.
565 * @param year the year in the given date.
566 * @param month the month in the given date.
567 * Month is 0-based. e.g., 0 for January.
568 * @param day the day-in-month of the given date.
569 * @param dayOfWeek the day-of-week of the given date.
570 * @param milliseconds the millis in day in <em>standard</em> local time.
571 * @param monthLength the length of the given month in days.
572 * @param status An UErrorCode to receive the status.
573 * @return the offset to add *to* GMT to get local time.
576 virtual int32_t getOffset(uint8_t era
, int32_t year
, int32_t month
, int32_t day
,
577 uint8_t dayOfWeek
, int32_t milliseconds
,
578 int32_t monthLength
, UErrorCode
& status
) const;
580 * Gets the time zone offset, for current date, modified in case of
581 * daylight savings. This is the offset to add *to* UTC to get local time.
582 * @param era the era of the given date.
583 * @param year the year in the given date.
584 * @param month the month in the given date.
585 * Month is 0-based. e.g., 0 for January.
586 * @param day the day-in-month of the given date.
587 * @param dayOfWeek the day-of-week of the given date.
588 * @param milliseconds the millis in day in <em>standard</em> local time.
589 * @param monthLength the length of the given month in days.
590 * @param prevMonthLength length of the previous month in days.
591 * @param status An UErrorCode to receive the status.
592 * @return the offset to add *to* GMT to get local time.
595 virtual int32_t getOffset(uint8_t era
, int32_t year
, int32_t month
, int32_t day
,
596 uint8_t dayOfWeek
, int32_t milliseconds
,
597 int32_t monthLength
, int32_t prevMonthLength
,
598 UErrorCode
& status
) const;
601 * Redeclared TimeZone method. This implementation simply calls
602 * the base class method, which otherwise would be hidden.
605 virtual void getOffset(UDate date
, UBool local
, int32_t& rawOffset
,
606 int32_t& dstOffset
, UErrorCode
& ec
) const;
609 * Returns the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
610 * to GMT to get local time, before taking daylight savings time into account).
612 * @return The TimeZone's raw GMT offset.
615 virtual int32_t getRawOffset(void) const;
618 * Sets the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
619 * to GMT to get local time, before taking daylight savings time into account).
621 * @param offsetMillis The new raw GMT offset for this time zone.
624 virtual void setRawOffset(int32_t offsetMillis
);
627 * Sets the amount of time in ms that the clock is advanced during DST.
628 * @param millisSavedDuringDST the number of milliseconds the time is
629 * advanced with respect to standard time when the daylight savings rules
630 * are in effect. A positive number, typically one hour (3600000).
631 * @param status An UErrorCode to receive the status.
634 void setDSTSavings(int32_t millisSavedDuringDST
, UErrorCode
& status
);
637 * Returns the amount of time in ms that the clock is advanced during DST.
638 * @return the number of milliseconds the time is
639 * advanced with respect to standard time when the daylight savings rules
640 * are in effect. A positive number, typically one hour (3600000).
643 int32_t getDSTSavings(void) const;
646 * Queries if this TimeZone uses Daylight Savings Time.
648 * @return True if this TimeZone uses Daylight Savings Time; false otherwise.
651 virtual UBool
useDaylightTime(void) const;
654 * Returns true if the given date is within the period when daylight savings time
655 * is in effect; false otherwise. If the TimeZone doesn't observe daylight savings
656 * time, this functions always returns false.
657 * This method is wasteful since it creates a new GregorianCalendar and
658 * deletes it each time it is called. This is a deprecated method
659 * and provided only for Java compatibility.
661 * @param date The date to test.
662 * @param status An UErrorCode to receive the status.
663 * @return true if the given date is in Daylight Savings Time;
665 * @deprecated ICU 2.4. Use Calendar::inDaylightTime() instead.
667 virtual UBool
inDaylightTime(UDate date
, UErrorCode
& status
) const;
670 * Return true if this zone has the same rules and offset as another zone.
671 * @param other the TimeZone object to be compared with
672 * @return true if the given zone has the same rules and offset as this one
675 UBool
hasSameRules(const TimeZone
& other
) const;
678 * Clones TimeZone objects polymorphically. Clients are responsible for deleting
679 * the TimeZone object cloned.
681 * @return A new copy of this TimeZone object.
684 virtual TimeZone
* clone(void) const;
689 * Override TimeZone Returns a unique class ID POLYMORPHICALLY. Pure virtual
690 * override. This method is to implement a simple version of RTTI, since not all C++
691 * compilers support genuine RTTI. Polymorphic operator==() and clone() methods call
694 * @return The class ID for this object. All objects of a given class have the
695 * same class ID. Objects of other classes have different class IDs.
698 virtual UClassID
getDynamicClassID(void) const;
701 * Return the class ID for this class. This is useful only for comparing to a return
702 * value from getDynamicClassID(). For example:
704 * . Base* polymorphic_pointer = createPolymorphicObject();
705 * . if (polymorphic_pointer->getDynamicClassID() ==
706 * . Derived::getStaticClassID()) ...
708 * @return The class ID for all objects of this class.
711 static UClassID U_EXPORT2
getStaticClassID(void);
715 * Constants specifying values of startMode and endMode.
725 SimpleTimeZone(); // default constructor not implemented
728 * Internal construction method.
729 * @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset
730 * @param startMonth the month DST starts
731 * @param startDay the day DST starts
732 * @param startDayOfWeek the DOW DST starts
733 * @param startTime the time DST starts
734 * @param startTimeMode Whether the start time is local wall time, local
735 * standard time, or UTC time. Default is local wall time.
736 * @param endMonth the month DST ends
737 * @param endDay the day DST ends
738 * @param endDayOfWeek the DOW DST ends
739 * @param endTime the time DST ends
740 * @param endTimeMode Whether the end time is local wall time, local
741 * standard time, or UTC time. Default is local wall time.
742 * @param savingsDST The number of milliseconds added to standard time
743 * to get DST time. Default is one hour.
744 * @param status An UErrorCode to receive the status.
746 void construct(int32_t rawOffsetGMT
,
747 int8_t startMonth
, int8_t startDay
, int8_t startDayOfWeek
,
748 int32_t startTime
, TimeMode startTimeMode
,
749 int8_t endMonth
, int8_t endDay
, int8_t endDayOfWeek
,
750 int32_t endTime
, TimeMode endTimeMode
,
751 int32_t dstSavings
, UErrorCode
& status
);
754 * Compare a given date in the year to a rule. Return 1, 0, or -1, depending
755 * on whether the date is after, equal to, or before the rule date. The
756 * millis are compared directly against the ruleMillis, so any
757 * standard-daylight adjustments must be handled by the caller.
759 * @return 1 if the date is after the rule date, -1 if the date is before
760 * the rule date, or 0 if the date is equal to the rule date.
762 static int32_t compareToRule(int8_t month
, int8_t monthLen
, int8_t prevMonthLen
,
764 int8_t dayOfWeek
, int32_t millis
, int32_t millisDelta
,
765 EMode ruleMode
, int8_t ruleMonth
, int8_t ruleDayOfWeek
,
766 int8_t ruleDay
, int32_t ruleMillis
);
769 * Given a set of encoded rules in startDay and startDayOfMonth, decode
770 * them and set the startMode appropriately. Do the same for endDay and
773 * Upon entry, the day of week variables may be zero or
774 * negative, in order to indicate special modes. The day of month
775 * variables may also be negative.
777 * Upon exit, the mode variables will be
778 * set, and the day of week and day of month variables will be positive.
780 * This method also recognizes a startDay or endDay of zero as indicating
783 void decodeRules(UErrorCode
& status
);
784 void decodeStartRule(UErrorCode
& status
);
785 void decodeEndRule(UErrorCode
& status
);
787 int8_t startMonth
, startDay
, startDayOfWeek
; // the month, day, DOW, and time DST starts
789 TimeMode startTimeMode
, endTimeMode
; // Mode for startTime, endTime; see TimeMode
790 int8_t endMonth
, endDay
, endDayOfWeek
; // the month, day, DOW, and time DST ends
792 int32_t startYear
; // the year these DST rules took effect
793 int32_t rawOffset
; // the TimeZone's raw GMT offset
794 UBool useDaylight
; // flag indicating whether this TimeZone uses DST
795 static const int8_t STATICMONTHLENGTH
[12]; // lengths of the months
796 EMode startMode
, endMode
; // flags indicating what kind of rules the DST rules are
799 * A positive value indicating the amount of time saved during DST in ms.
800 * Typically one hour; sometimes 30 minutes.
805 inline void SimpleTimeZone::setStartRule(int32_t month
, int32_t dayOfWeekInMonth
,
807 int32_t time
, UErrorCode
& status
) {
808 setStartRule(month
, dayOfWeekInMonth
, dayOfWeek
, time
, WALL_TIME
, status
);
811 inline void SimpleTimeZone::setStartRule(int32_t month
, int32_t dayOfMonth
,
813 UErrorCode
& status
) {
814 setStartRule(month
, dayOfMonth
, time
, WALL_TIME
, status
);
817 inline void SimpleTimeZone::setStartRule(int32_t month
, int32_t dayOfMonth
,
819 int32_t time
, UBool after
, UErrorCode
& status
) {
820 setStartRule(month
, dayOfMonth
, dayOfWeek
, time
, WALL_TIME
, after
, status
);
823 inline void SimpleTimeZone::setEndRule(int32_t month
, int32_t dayOfWeekInMonth
,
825 int32_t time
, UErrorCode
& status
) {
826 setEndRule(month
, dayOfWeekInMonth
, dayOfWeek
, time
, WALL_TIME
, status
);
829 inline void SimpleTimeZone::setEndRule(int32_t month
, int32_t dayOfMonth
,
830 int32_t time
, UErrorCode
& status
) {
831 setEndRule(month
, dayOfMonth
, time
, WALL_TIME
, status
);
834 inline void SimpleTimeZone::setEndRule(int32_t month
, int32_t dayOfMonth
, int32_t dayOfWeek
,
835 int32_t time
, UBool after
, UErrorCode
& status
) {
836 setEndRule(month
, dayOfMonth
, dayOfWeek
, time
, WALL_TIME
, after
, status
);
840 SimpleTimeZone::getOffset(UDate date
, UBool local
, int32_t& rawOffsetRef
,
841 int32_t& dstOffsetRef
, UErrorCode
& ec
) const {
842 TimeZone::getOffset(date
, local
, rawOffsetRef
, dstOffsetRef
, ec
);
847 #endif /* #if !UCONFIG_NO_FORMATTING */