46 import sun.util.calendar.CalendarUtils; |
46 import sun.util.calendar.CalendarUtils; |
47 import sun.util.calendar.BaseCalendar; |
47 import sun.util.calendar.BaseCalendar; |
48 import sun.util.calendar.Gregorian; |
48 import sun.util.calendar.Gregorian; |
49 |
49 |
50 /** |
50 /** |
51 * <code>SimpleTimeZone</code> is a concrete subclass of <code>TimeZone</code> |
51 * {@code SimpleTimeZone} is a concrete subclass of {@code TimeZone} |
52 * that represents a time zone for use with a Gregorian calendar. |
52 * that represents a time zone for use with a Gregorian calendar. |
53 * The class holds an offset from GMT, called <em>raw offset</em>, and start |
53 * The class holds an offset from GMT, called <em>raw offset</em>, and start |
54 * and end rules for a daylight saving time schedule. Since it only holds |
54 * and end rules for a daylight saving time schedule. Since it only holds |
55 * single values for each, it cannot handle historical changes in the offset |
55 * single values for each, it cannot handle historical changes in the offset |
56 * from GMT and the daylight saving schedule, except that the {@link |
56 * from GMT and the daylight saving schedule, except that the {@link |
57 * #setStartYear setStartYear} method can specify the year when the daylight |
57 * #setStartYear setStartYear} method can specify the year when the daylight |
58 * saving time schedule starts in effect. |
58 * saving time schedule starts in effect. |
59 * <p> |
59 * <p> |
60 * To construct a <code>SimpleTimeZone</code> with a daylight saving time |
60 * To construct a {@code SimpleTimeZone} with a daylight saving time |
61 * schedule, the schedule can be described with a set of rules, |
61 * schedule, the schedule can be described with a set of rules, |
62 * <em>start-rule</em> and <em>end-rule</em>. A day when daylight saving time |
62 * <em>start-rule</em> and <em>end-rule</em>. A day when daylight saving time |
63 * starts or ends is specified by a combination of <em>month</em>, |
63 * starts or ends is specified by a combination of <em>month</em>, |
64 * <em>day-of-month</em>, and <em>day-of-week</em> values. The <em>month</em> |
64 * <em>day-of-month</em>, and <em>day-of-week</em> values. The <em>month</em> |
65 * value is represented by a Calendar {@link Calendar#MONTH MONTH} field |
65 * value is represented by a Calendar {@link Calendar#MONTH MONTH} field |
79 * To specify a day of week on or after an exact day of month, set the |
79 * To specify a day of week on or after an exact day of month, set the |
80 * <em>month</em> to an exact month value, <em>day-of-month</em> to the day on |
80 * <em>month</em> to an exact month value, <em>day-of-month</em> to the day on |
81 * or after which the rule is applied, and <em>day-of-week</em> to a negative {@link |
81 * or after which the rule is applied, and <em>day-of-week</em> to a negative {@link |
82 * Calendar#DAY_OF_WEEK DAY_OF_WEEK} field value. For example, to specify the |
82 * Calendar#DAY_OF_WEEK DAY_OF_WEEK} field value. For example, to specify the |
83 * second Sunday of April, set <em>month</em> to {@link Calendar#APRIL APRIL}, |
83 * second Sunday of April, set <em>month</em> to {@link Calendar#APRIL APRIL}, |
84 * <em>day-of-month</em> to 8, and <em>day-of-week</em> to <code>-</code>{@link |
84 * <em>day-of-month</em> to 8, and <em>day-of-week</em> to {@code -}{@link |
85 * Calendar#SUNDAY SUNDAY}.</li> |
85 * Calendar#SUNDAY SUNDAY}.</li> |
86 * |
86 * |
87 * <li><b>Day of week on or before day of month</b><br> |
87 * <li><b>Day of week on or before day of month</b><br> |
88 * To specify a day of the week on or before an exact day of the month, set |
88 * To specify a day of the week on or before an exact day of the month, set |
89 * <em>day-of-month</em> and <em>day-of-week</em> to a negative value. For |
89 * <em>day-of-month</em> and <em>day-of-week</em> to a negative value. For |
90 * example, to specify the last Wednesday on or before the 21st of March, set |
90 * example, to specify the last Wednesday on or before the 21st of March, set |
91 * <em>month</em> to {@link Calendar#MARCH MARCH}, <em>day-of-month</em> is -21 |
91 * <em>month</em> to {@link Calendar#MARCH MARCH}, <em>day-of-month</em> is -21 |
92 * and <em>day-of-week</em> is <code>-</code>{@link Calendar#WEDNESDAY WEDNESDAY}. </li> |
92 * and <em>day-of-week</em> is {@code -}{@link Calendar#WEDNESDAY WEDNESDAY}. </li> |
93 * |
93 * |
94 * <li><b>Last day-of-week of month</b><br> |
94 * <li><b>Last day-of-week of month</b><br> |
95 * To specify, the last day-of-week of the month, set <em>day-of-week</em> to a |
95 * To specify, the last day-of-week of the month, set <em>day-of-week</em> to a |
96 * {@link Calendar#DAY_OF_WEEK DAY_OF_WEEK} value and <em>day-of-month</em> to |
96 * {@link Calendar#DAY_OF_WEEK DAY_OF_WEEK} value and <em>day-of-month</em> to |
97 * -1. For example, to specify the last Sunday of October, set <em>month</em> |
97 * -1. For example, to specify the last Sunday of October, set <em>month</em> |
207 * @param endDayOfWeek The daylight saving time ending day-of-week. |
207 * @param endDayOfWeek The daylight saving time ending day-of-week. |
208 * See the class description for the special cases of this parameter. |
208 * See the class description for the special cases of this parameter. |
209 * @param endTime The daylight saving ending time in local wall clock time, |
209 * @param endTime The daylight saving ending time in local wall clock time, |
210 * (in milliseconds within the day) which is local daylight |
210 * (in milliseconds within the day) which is local daylight |
211 * time in this case. |
211 * time in this case. |
212 * @exception IllegalArgumentException if the month, day, dayOfWeek, or time |
212 * @throws IllegalArgumentException if the month, day, dayOfWeek, or time |
213 * parameters are out of range for the start or end rule |
213 * parameters are out of range for the start or end rule |
214 */ |
214 */ |
215 public SimpleTimeZone(int rawOffset, String ID, |
215 public SimpleTimeZone(int rawOffset, String ID, |
216 int startMonth, int startDay, int startDayOfWeek, int startTime, |
216 int startMonth, int startDay, int startDayOfWeek, int startTime, |
217 int endMonth, int endDay, int endDayOfWeek, int endTime) |
217 int endMonth, int endDay, int endDayOfWeek, int endTime) |
264 * See the class description for the special cases of this parameter. |
264 * See the class description for the special cases of this parameter. |
265 * @param endTime The daylight saving ending time in local wall clock time, |
265 * @param endTime The daylight saving ending time in local wall clock time, |
266 * which is local daylight time in this case. |
266 * which is local daylight time in this case. |
267 * @param dstSavings The amount of time in milliseconds saved during |
267 * @param dstSavings The amount of time in milliseconds saved during |
268 * daylight saving time. |
268 * daylight saving time. |
269 * @exception IllegalArgumentException if the month, day, dayOfWeek, or time |
269 * @throws IllegalArgumentException if the month, day, dayOfWeek, or time |
270 * parameters are out of range for the start or end rule |
270 * parameters are out of range for the start or end rule |
271 * @since 1.2 |
271 * @since 1.2 |
272 */ |
272 */ |
273 public SimpleTimeZone(int rawOffset, String ID, |
273 public SimpleTimeZone(int rawOffset, String ID, |
274 int startMonth, int startDay, int startDayOfWeek, int startTime, |
274 int startMonth, int startDay, int startDayOfWeek, int startTime, |
299 * @param startDay The day of the month on which the daylight saving time starts. |
299 * @param startDay The day of the month on which the daylight saving time starts. |
300 * See the class description for the special cases of this parameter. |
300 * See the class description for the special cases of this parameter. |
301 * @param startDayOfWeek The daylight saving time starting day-of-week. |
301 * @param startDayOfWeek The daylight saving time starting day-of-week. |
302 * See the class description for the special cases of this parameter. |
302 * See the class description for the special cases of this parameter. |
303 * @param startTime The daylight saving time starting time in the time mode |
303 * @param startTime The daylight saving time starting time in the time mode |
304 * specified by <code>startTimeMode</code>. |
304 * specified by {@code startTimeMode}. |
305 * @param startTimeMode The mode of the start time specified by startTime. |
305 * @param startTimeMode The mode of the start time specified by startTime. |
306 * @param endMonth The daylight saving time ending month. Month is |
306 * @param endMonth The daylight saving time ending month. Month is |
307 * a {@link Calendar#MONTH MONTH} field |
307 * a {@link Calendar#MONTH MONTH} field |
308 * value (0-based. e.g., 9 for October). |
308 * value (0-based. e.g., 9 for October). |
309 * @param endDay The day of the month on which the daylight saving time ends. |
309 * @param endDay The day of the month on which the daylight saving time ends. |
310 * See the class description for the special cases of this parameter. |
310 * See the class description for the special cases of this parameter. |
311 * @param endDayOfWeek The daylight saving time ending day-of-week. |
311 * @param endDayOfWeek The daylight saving time ending day-of-week. |
312 * See the class description for the special cases of this parameter. |
312 * See the class description for the special cases of this parameter. |
313 * @param endTime The daylight saving ending time in time mode |
313 * @param endTime The daylight saving ending time in time mode |
314 * specified by <code>endTimeMode</code>. |
314 * specified by {@code endTimeMode}. |
315 * @param endTimeMode The mode of the end time specified by endTime |
315 * @param endTimeMode The mode of the end time specified by endTime |
316 * @param dstSavings The amount of time in milliseconds saved during |
316 * @param dstSavings The amount of time in milliseconds saved during |
317 * daylight saving time. |
317 * daylight saving time. |
318 * |
318 * |
319 * @exception IllegalArgumentException if the month, day, dayOfWeek, time more, or |
319 * @throws IllegalArgumentException if the month, day, dayOfWeek, time more, or |
320 * time parameters are out of range for the start or end rule, or if a time mode |
320 * time parameters are out of range for the start or end rule, or if a time mode |
321 * value is invalid. |
321 * value is invalid. |
322 * |
322 * |
323 * @see #WALL_TIME |
323 * @see #WALL_TIME |
324 * @see #STANDARD_TIME |
324 * @see #STANDARD_TIME |
367 |
367 |
368 /** |
368 /** |
369 * Sets the daylight saving time start rule. For example, if daylight saving |
369 * Sets the daylight saving time start rule. For example, if daylight saving |
370 * time starts on the first Sunday in April at 2 am in local wall clock |
370 * time starts on the first Sunday in April at 2 am in local wall clock |
371 * time, you can set the start rule by calling: |
371 * time, you can set the start rule by calling: |
372 * <pre><code>setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2*60*60*1000);</code></pre> |
372 * <pre>{@code setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2*60*60*1000);}</pre> |
373 * |
373 * |
374 * @param startMonth The daylight saving time starting month. Month is |
374 * @param startMonth The daylight saving time starting month. Month is |
375 * a {@link Calendar#MONTH MONTH} field |
375 * a {@link Calendar#MONTH MONTH} field |
376 * value (0-based. e.g., 0 for January). |
376 * value (0-based. e.g., 0 for January). |
377 * @param startDay The day of the month on which the daylight saving time starts. |
377 * @param startDay The day of the month on which the daylight saving time starts. |
378 * See the class description for the special cases of this parameter. |
378 * See the class description for the special cases of this parameter. |
379 * @param startDayOfWeek The daylight saving time starting day-of-week. |
379 * @param startDayOfWeek The daylight saving time starting day-of-week. |
380 * See the class description for the special cases of this parameter. |
380 * See the class description for the special cases of this parameter. |
381 * @param startTime The daylight saving time starting time in local wall clock |
381 * @param startTime The daylight saving time starting time in local wall clock |
382 * time, which is local standard time in this case. |
382 * time, which is local standard time in this case. |
383 * @exception IllegalArgumentException if the <code>startMonth</code>, <code>startDay</code>, |
383 * @throws IllegalArgumentException if the {@code startMonth}, {@code startDay}, |
384 * <code>startDayOfWeek</code>, or <code>startTime</code> parameters are out of range |
384 * {@code startDayOfWeek}, or {@code startTime} parameters are out of range |
385 */ |
385 */ |
386 public void setStartRule(int startMonth, int startDay, int startDayOfWeek, int startTime) |
386 public void setStartRule(int startMonth, int startDay, int startDayOfWeek, int startTime) |
387 { |
387 { |
388 this.startMonth = startMonth; |
388 this.startMonth = startMonth; |
389 this.startDay = startDay; |
389 this.startDay = startDay; |
395 } |
395 } |
396 |
396 |
397 /** |
397 /** |
398 * Sets the daylight saving time start rule to a fixed date within a month. |
398 * Sets the daylight saving time start rule to a fixed date within a month. |
399 * This method is equivalent to: |
399 * This method is equivalent to: |
400 * <pre><code>setStartRule(startMonth, startDay, 0, startTime)</code></pre> |
400 * <pre>{@code setStartRule(startMonth, startDay, 0, startTime)}</pre> |
401 * |
401 * |
402 * @param startMonth The daylight saving time starting month. Month is |
402 * @param startMonth The daylight saving time starting month. Month is |
403 * a {@link Calendar#MONTH MONTH} field |
403 * a {@link Calendar#MONTH MONTH} field |
404 * value (0-based. e.g., 0 for January). |
404 * value (0-based. e.g., 0 for January). |
405 * @param startDay The day of the month on which the daylight saving time starts. |
405 * @param startDay The day of the month on which the daylight saving time starts. |
406 * @param startTime The daylight saving time starting time in local wall clock |
406 * @param startTime The daylight saving time starting time in local wall clock |
407 * time, which is local standard time in this case. |
407 * time, which is local standard time in this case. |
408 * See the class description for the special cases of this parameter. |
408 * See the class description for the special cases of this parameter. |
409 * @exception IllegalArgumentException if the <code>startMonth</code>, |
409 * @throws IllegalArgumentException if the {@code startMonth}, |
410 * <code>startDayOfMonth</code>, or <code>startTime</code> parameters are out of range |
410 * {@code startDayOfMonth}, or {@code startTime} parameters are out of range |
411 * @since 1.2 |
411 * @since 1.2 |
412 */ |
412 */ |
413 public void setStartRule(int startMonth, int startDay, int startTime) { |
413 public void setStartRule(int startMonth, int startDay, int startTime) { |
414 setStartRule(startMonth, startDay, 0, startTime); |
414 setStartRule(startMonth, startDay, 0, startTime); |
415 } |
415 } |
423 * value (0-based. e.g., 0 for January). |
423 * value (0-based. e.g., 0 for January). |
424 * @param startDay The day of the month on which the daylight saving time starts. |
424 * @param startDay The day of the month on which the daylight saving time starts. |
425 * @param startDayOfWeek The daylight saving time starting day-of-week. |
425 * @param startDayOfWeek The daylight saving time starting day-of-week. |
426 * @param startTime The daylight saving time starting time in local wall clock |
426 * @param startTime The daylight saving time starting time in local wall clock |
427 * time, which is local standard time in this case. |
427 * time, which is local standard time in this case. |
428 * @param after If true, this rule selects the first <code>dayOfWeek</code> on or |
428 * @param after If true, this rule selects the first {@code dayOfWeek} on or |
429 * <em>after</em> <code>dayOfMonth</code>. If false, this rule |
429 * <em>after</em> {@code dayOfMonth}. If false, this rule |
430 * selects the last <code>dayOfWeek</code> on or <em>before</em> |
430 * selects the last {@code dayOfWeek} on or <em>before</em> |
431 * <code>dayOfMonth</code>. |
431 * {@code dayOfMonth}. |
432 * @exception IllegalArgumentException if the <code>startMonth</code>, <code>startDay</code>, |
432 * @throws IllegalArgumentException if the {@code startMonth}, {@code startDay}, |
433 * <code>startDayOfWeek</code>, or <code>startTime</code> parameters are out of range |
433 * {@code startDayOfWeek}, or {@code startTime} parameters are out of range |
434 * @since 1.2 |
434 * @since 1.2 |
435 */ |
435 */ |
436 public void setStartRule(int startMonth, int startDay, int startDayOfWeek, |
436 public void setStartRule(int startMonth, int startDay, int startDayOfWeek, |
437 int startTime, boolean after) |
437 int startTime, boolean after) |
438 { |
438 { |
446 |
446 |
447 /** |
447 /** |
448 * Sets the daylight saving time end rule. For example, if daylight saving time |
448 * Sets the daylight saving time end rule. For example, if daylight saving time |
449 * ends on the last Sunday in October at 2 am in wall clock time, |
449 * ends on the last Sunday in October at 2 am in wall clock time, |
450 * you can set the end rule by calling: |
450 * you can set the end rule by calling: |
451 * <code>setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2*60*60*1000);</code> |
451 * {@code setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2*60*60*1000);} |
452 * |
452 * |
453 * @param endMonth The daylight saving time ending month. Month is |
453 * @param endMonth The daylight saving time ending month. Month is |
454 * a {@link Calendar#MONTH MONTH} field |
454 * a {@link Calendar#MONTH MONTH} field |
455 * value (0-based. e.g., 9 for October). |
455 * value (0-based. e.g., 9 for October). |
456 * @param endDay The day of the month on which the daylight saving time ends. |
456 * @param endDay The day of the month on which the daylight saving time ends. |
458 * @param endDayOfWeek The daylight saving time ending day-of-week. |
458 * @param endDayOfWeek The daylight saving time ending day-of-week. |
459 * See the class description for the special cases of this parameter. |
459 * See the class description for the special cases of this parameter. |
460 * @param endTime The daylight saving ending time in local wall clock time, |
460 * @param endTime The daylight saving ending time in local wall clock time, |
461 * (in milliseconds within the day) which is local daylight |
461 * (in milliseconds within the day) which is local daylight |
462 * time in this case. |
462 * time in this case. |
463 * @exception IllegalArgumentException if the <code>endMonth</code>, <code>endDay</code>, |
463 * @throws IllegalArgumentException if the {@code endMonth}, {@code endDay}, |
464 * <code>endDayOfWeek</code>, or <code>endTime</code> parameters are out of range |
464 * {@code endDayOfWeek}, or {@code endTime} parameters are out of range |
465 */ |
465 */ |
466 public void setEndRule(int endMonth, int endDay, int endDayOfWeek, |
466 public void setEndRule(int endMonth, int endDay, int endDayOfWeek, |
467 int endTime) |
467 int endTime) |
468 { |
468 { |
469 this.endMonth = endMonth; |
469 this.endMonth = endMonth; |
476 } |
476 } |
477 |
477 |
478 /** |
478 /** |
479 * Sets the daylight saving time end rule to a fixed date within a month. |
479 * Sets the daylight saving time end rule to a fixed date within a month. |
480 * This method is equivalent to: |
480 * This method is equivalent to: |
481 * <pre><code>setEndRule(endMonth, endDay, 0, endTime)</code></pre> |
481 * <pre>{@code setEndRule(endMonth, endDay, 0, endTime)}</pre> |
482 * |
482 * |
483 * @param endMonth The daylight saving time ending month. Month is |
483 * @param endMonth The daylight saving time ending month. Month is |
484 * a {@link Calendar#MONTH MONTH} field |
484 * a {@link Calendar#MONTH MONTH} field |
485 * value (0-based. e.g., 9 for October). |
485 * value (0-based. e.g., 9 for October). |
486 * @param endDay The day of the month on which the daylight saving time ends. |
486 * @param endDay The day of the month on which the daylight saving time ends. |
487 * @param endTime The daylight saving ending time in local wall clock time, |
487 * @param endTime The daylight saving ending time in local wall clock time, |
488 * (in milliseconds within the day) which is local daylight |
488 * (in milliseconds within the day) which is local daylight |
489 * time in this case. |
489 * time in this case. |
490 * @exception IllegalArgumentException the <code>endMonth</code>, <code>endDay</code>, |
490 * @throws IllegalArgumentException the {@code endMonth}, {@code endDay}, |
491 * or <code>endTime</code> parameters are out of range |
491 * or {@code endTime} parameters are out of range |
492 * @since 1.2 |
492 * @since 1.2 |
493 */ |
493 */ |
494 public void setEndRule(int endMonth, int endDay, int endTime) |
494 public void setEndRule(int endMonth, int endDay, int endTime) |
495 { |
495 { |
496 setEndRule(endMonth, endDay, 0, endTime); |
496 setEndRule(endMonth, endDay, 0, endTime); |
506 * @param endDay The day of the month on which the daylight saving time ends. |
506 * @param endDay The day of the month on which the daylight saving time ends. |
507 * @param endDayOfWeek The daylight saving time ending day-of-week. |
507 * @param endDayOfWeek The daylight saving time ending day-of-week. |
508 * @param endTime The daylight saving ending time in local wall clock time, |
508 * @param endTime The daylight saving ending time in local wall clock time, |
509 * (in milliseconds within the day) which is local daylight |
509 * (in milliseconds within the day) which is local daylight |
510 * time in this case. |
510 * time in this case. |
511 * @param after If true, this rule selects the first <code>endDayOfWeek</code> on |
511 * @param after If true, this rule selects the first {@code endDayOfWeek} on |
512 * or <em>after</em> <code>endDay</code>. If false, this rule |
512 * or <em>after</em> {@code endDay}. If false, this rule |
513 * selects the last <code>endDayOfWeek</code> on or before |
513 * selects the last {@code endDayOfWeek} on or before |
514 * <code>endDay</code> of the month. |
514 * {@code endDay} of the month. |
515 * @exception IllegalArgumentException the <code>endMonth</code>, <code>endDay</code>, |
515 * @throws IllegalArgumentException the {@code endMonth}, {@code endDay}, |
516 * <code>endDayOfWeek</code>, or <code>endTime</code> parameters are out of range |
516 * {@code endDayOfWeek}, or {@code endTime} parameters are out of range |
517 * @since 1.2 |
517 * @since 1.2 |
518 */ |
518 */ |
519 public void setEndRule(int endMonth, int endDay, int endDayOfWeek, int endTime, boolean after) |
519 public void setEndRule(int endMonth, int endDay, int endDayOfWeek, int endTime, boolean after) |
520 { |
520 { |
521 if (after) { |
521 if (after) { |
581 * daylight saving, for the specified date and time. This method |
581 * daylight saving, for the specified date and time. This method |
582 * assumes that the start and end month are distinct. It also |
582 * assumes that the start and end month are distinct. It also |
583 * uses a default {@link GregorianCalendar} object as its |
583 * uses a default {@link GregorianCalendar} object as its |
584 * underlying calendar, such as for determining leap years. Do |
584 * underlying calendar, such as for determining leap years. Do |
585 * not use the result of this method with a calendar other than a |
585 * not use the result of this method with a calendar other than a |
586 * default <code>GregorianCalendar</code>. |
586 * default {@code GregorianCalendar}. |
587 * |
587 * |
588 * <p><em>Note: In general, clients should use |
588 * <p><em>Note: In general, clients should use |
589 * <code>Calendar.get(ZONE_OFFSET) + Calendar.get(DST_OFFSET)</code> |
589 * {@code Calendar.get(ZONE_OFFSET) + Calendar.get(DST_OFFSET)} |
590 * instead of calling this method.</em> |
590 * instead of calling this method.</em> |
591 * |
591 * |
592 * @param era The era of the given date. |
592 * @param era The era of the given date. |
593 * @param year The year in the given date. |
593 * @param year The year in the given date. |
594 * @param month The month in the given date. Month is 0-based. e.g., |
594 * @param month The month in the given date. Month is 0-based. e.g., |
595 * 0 for January. |
595 * 0 for January. |
596 * @param day The day-in-month of the given date. |
596 * @param day The day-in-month of the given date. |
597 * @param dayOfWeek The day-of-week of the given date. |
597 * @param dayOfWeek The day-of-week of the given date. |
598 * @param millis The milliseconds in day in <em>standard</em> local time. |
598 * @param millis The milliseconds in day in <em>standard</em> local time. |
599 * @return The milliseconds to add to UTC to get local time. |
599 * @return The milliseconds to add to UTC to get local time. |
600 * @exception IllegalArgumentException the <code>era</code>, |
600 * @throws IllegalArgumentException the {@code era}, |
601 * <code>month</code>, <code>day</code>, <code>dayOfWeek</code>, |
601 * {@code month}, {@code day}, {@code dayOfWeek}, |
602 * or <code>millis</code> parameters are out of range |
602 * or {@code millis} parameters are out of range |
603 */ |
603 */ |
604 public int getOffset(int era, int year, int month, int day, int dayOfWeek, |
604 public int getOffset(int era, int year, int month, int day, int dayOfWeek, |
605 int millis) |
605 int millis) |
606 { |
606 { |
607 if (era != GregorianCalendar.AD && era != GregorianCalendar.BC) { |
607 if (era != GregorianCalendar.AD && era != GregorianCalendar.BC) { |
955 |
955 |
956 // =======================privates=============================== |
956 // =======================privates=============================== |
957 |
957 |
958 /** |
958 /** |
959 * The month in which daylight saving time starts. This value must be |
959 * The month in which daylight saving time starts. This value must be |
960 * between <code>Calendar.JANUARY</code> and |
960 * between {@code Calendar.JANUARY} and |
961 * <code>Calendar.DECEMBER</code> inclusive. This value must not equal |
961 * {@code Calendar.DECEMBER} inclusive. This value must not equal |
962 * <code>endMonth</code>. |
962 * {@code endMonth}. |
963 * <p>If <code>useDaylight</code> is false, this value is ignored. |
963 * <p>If {@code useDaylight} is false, this value is ignored. |
964 * @serial |
964 * @serial |
965 */ |
965 */ |
966 private int startMonth; |
966 private int startMonth; |
967 |
967 |
968 /** |
968 /** |
969 * This field has two possible interpretations: |
969 * This field has two possible interpretations: |
970 * <dl> |
970 * <dl> |
971 * <dt><code>startMode == DOW_IN_MONTH</code></dt> |
971 * <dt>{@code startMode == DOW_IN_MONTH}</dt> |
972 * <dd> |
972 * <dd> |
973 * <code>startDay</code> indicates the day of the month of |
973 * {@code startDay} indicates the day of the month of |
974 * <code>startMonth</code> on which daylight |
974 * {@code startMonth} on which daylight |
975 * saving time starts, from 1 to 28, 30, or 31, depending on the |
975 * saving time starts, from 1 to 28, 30, or 31, depending on the |
976 * <code>startMonth</code>. |
976 * {@code startMonth}. |
977 * </dd> |
977 * </dd> |
978 * <dt><code>startMode != DOW_IN_MONTH</code></dt> |
978 * <dt>{@code startMode != DOW_IN_MONTH}</dt> |
979 * <dd> |
979 * <dd> |
980 * <code>startDay</code> indicates which <code>startDayOfWeek</code> in the |
980 * {@code startDay} indicates which {@code startDayOfWeek} in the |
981 * month <code>startMonth</code> daylight |
981 * month {@code startMonth} daylight |
982 * saving time starts on. For example, a value of +1 and a |
982 * saving time starts on. For example, a value of +1 and a |
983 * <code>startDayOfWeek</code> of <code>Calendar.SUNDAY</code> indicates the |
983 * {@code startDayOfWeek} of {@code Calendar.SUNDAY} indicates the |
984 * first Sunday of <code>startMonth</code>. Likewise, +2 would indicate the |
984 * first Sunday of {@code startMonth}. Likewise, +2 would indicate the |
985 * second Sunday, and -1 the last Sunday. A value of 0 is illegal. |
985 * second Sunday, and -1 the last Sunday. A value of 0 is illegal. |
986 * </dd> |
986 * </dd> |
987 * </dl> |
987 * </dl> |
988 * <p>If <code>useDaylight</code> is false, this value is ignored. |
988 * <p>If {@code useDaylight} is false, this value is ignored. |
989 * @serial |
989 * @serial |
990 */ |
990 */ |
991 private int startDay; |
991 private int startDay; |
992 |
992 |
993 /** |
993 /** |
994 * The day of the week on which daylight saving time starts. This value |
994 * The day of the week on which daylight saving time starts. This value |
995 * must be between <code>Calendar.SUNDAY</code> and |
995 * must be between {@code Calendar.SUNDAY} and |
996 * <code>Calendar.SATURDAY</code> inclusive. |
996 * {@code Calendar.SATURDAY} inclusive. |
997 * <p>If <code>useDaylight</code> is false or |
997 * <p>If {@code useDaylight} is false or |
998 * <code>startMode == DAY_OF_MONTH</code>, this value is ignored. |
998 * {@code startMode == DAY_OF_MONTH}, this value is ignored. |
999 * @serial |
999 * @serial |
1000 */ |
1000 */ |
1001 private int startDayOfWeek; |
1001 private int startDayOfWeek; |
1002 |
1002 |
1003 /** |
1003 /** |
1004 * The time in milliseconds after midnight at which daylight saving |
1004 * The time in milliseconds after midnight at which daylight saving |
1005 * time starts. This value is expressed as wall time, standard time, |
1005 * time starts. This value is expressed as wall time, standard time, |
1006 * or UTC time, depending on the setting of <code>startTimeMode</code>. |
1006 * or UTC time, depending on the setting of {@code startTimeMode}. |
1007 * <p>If <code>useDaylight</code> is false, this value is ignored. |
1007 * <p>If {@code useDaylight} is false, this value is ignored. |
1008 * @serial |
1008 * @serial |
1009 */ |
1009 */ |
1010 private int startTime; |
1010 private int startTime; |
1011 |
1011 |
1012 /** |
1012 /** |
1016 */ |
1016 */ |
1017 private int startTimeMode; |
1017 private int startTimeMode; |
1018 |
1018 |
1019 /** |
1019 /** |
1020 * The month in which daylight saving time ends. This value must be |
1020 * The month in which daylight saving time ends. This value must be |
1021 * between <code>Calendar.JANUARY</code> and |
1021 * between {@code Calendar.JANUARY} and |
1022 * <code>Calendar.UNDECIMBER</code>. This value must not equal |
1022 * {@code Calendar.UNDECIMBER}. This value must not equal |
1023 * <code>startMonth</code>. |
1023 * {@code startMonth}. |
1024 * <p>If <code>useDaylight</code> is false, this value is ignored. |
1024 * <p>If {@code useDaylight} is false, this value is ignored. |
1025 * @serial |
1025 * @serial |
1026 */ |
1026 */ |
1027 private int endMonth; |
1027 private int endMonth; |
1028 |
1028 |
1029 /** |
1029 /** |
1030 * This field has two possible interpretations: |
1030 * This field has two possible interpretations: |
1031 * <dl> |
1031 * <dl> |
1032 * <dt><code>endMode == DOW_IN_MONTH</code></dt> |
1032 * <dt>{@code endMode == DOW_IN_MONTH}</dt> |
1033 * <dd> |
1033 * <dd> |
1034 * <code>endDay</code> indicates the day of the month of |
1034 * {@code endDay} indicates the day of the month of |
1035 * <code>endMonth</code> on which daylight |
1035 * {@code endMonth} on which daylight |
1036 * saving time ends, from 1 to 28, 30, or 31, depending on the |
1036 * saving time ends, from 1 to 28, 30, or 31, depending on the |
1037 * <code>endMonth</code>. |
1037 * {@code endMonth}. |
1038 * </dd> |
1038 * </dd> |
1039 * <dt><code>endMode != DOW_IN_MONTH</code></dt> |
1039 * <dt>{@code endMode != DOW_IN_MONTH}</dt> |
1040 * <dd> |
1040 * <dd> |
1041 * <code>endDay</code> indicates which <code>endDayOfWeek</code> in th |
1041 * {@code endDay} indicates which {@code endDayOfWeek} in th |
1042 * month <code>endMonth</code> daylight |
1042 * month {@code endMonth} daylight |
1043 * saving time ends on. For example, a value of +1 and a |
1043 * saving time ends on. For example, a value of +1 and a |
1044 * <code>endDayOfWeek</code> of <code>Calendar.SUNDAY</code> indicates the |
1044 * {@code endDayOfWeek} of {@code Calendar.SUNDAY} indicates the |
1045 * first Sunday of <code>endMonth</code>. Likewise, +2 would indicate the |
1045 * first Sunday of {@code endMonth}. Likewise, +2 would indicate the |
1046 * second Sunday, and -1 the last Sunday. A value of 0 is illegal. |
1046 * second Sunday, and -1 the last Sunday. A value of 0 is illegal. |
1047 * </dd> |
1047 * </dd> |
1048 * </dl> |
1048 * </dl> |
1049 * <p>If <code>useDaylight</code> is false, this value is ignored. |
1049 * <p>If {@code useDaylight} is false, this value is ignored. |
1050 * @serial |
1050 * @serial |
1051 */ |
1051 */ |
1052 private int endDay; |
1052 private int endDay; |
1053 |
1053 |
1054 /** |
1054 /** |
1055 * The day of the week on which daylight saving time ends. This value |
1055 * The day of the week on which daylight saving time ends. This value |
1056 * must be between <code>Calendar.SUNDAY</code> and |
1056 * must be between {@code Calendar.SUNDAY} and |
1057 * <code>Calendar.SATURDAY</code> inclusive. |
1057 * {@code Calendar.SATURDAY} inclusive. |
1058 * <p>If <code>useDaylight</code> is false or |
1058 * <p>If {@code useDaylight} is false or |
1059 * <code>endMode == DAY_OF_MONTH</code>, this value is ignored. |
1059 * {@code endMode == DAY_OF_MONTH}, this value is ignored. |
1060 * @serial |
1060 * @serial |
1061 */ |
1061 */ |
1062 private int endDayOfWeek; |
1062 private int endDayOfWeek; |
1063 |
1063 |
1064 /** |
1064 /** |
1065 * The time in milliseconds after midnight at which daylight saving |
1065 * The time in milliseconds after midnight at which daylight saving |
1066 * time ends. This value is expressed as wall time, standard time, |
1066 * time ends. This value is expressed as wall time, standard time, |
1067 * or UTC time, depending on the setting of <code>endTimeMode</code>. |
1067 * or UTC time, depending on the setting of {@code endTimeMode}. |
1068 * <p>If <code>useDaylight</code> is false, this value is ignored. |
1068 * <p>If {@code useDaylight} is false, this value is ignored. |
1069 * @serial |
1069 * @serial |
1070 */ |
1070 */ |
1071 private int endTime; |
1071 private int endTime; |
1072 |
1072 |
1073 /** |
1073 /** |
1074 * The format of endTime, either <code>WALL_TIME</code>, |
1074 * The format of endTime, either {@code WALL_TIME}, |
1075 * <code>STANDARD_TIME</code>, or <code>UTC_TIME</code>. |
1075 * {@code STANDARD_TIME}, or {@code UTC_TIME}. |
1076 * @serial |
1076 * @serial |
1077 * @since 1.3 |
1077 * @since 1.3 |
1078 */ |
1078 */ |
1079 private int endTimeMode; |
1079 private int endTimeMode; |
1080 |
1080 |
1081 /** |
1081 /** |
1082 * The year in which daylight saving time is first observed. This is an {@link GregorianCalendar#AD AD} |
1082 * The year in which daylight saving time is first observed. This is an {@link GregorianCalendar#AD AD} |
1083 * value. If this value is less than 1 then daylight saving time is observed |
1083 * value. If this value is less than 1 then daylight saving time is observed |
1084 * for all <code>AD</code> years. |
1084 * for all {@code AD} years. |
1085 * <p>If <code>useDaylight</code> is false, this value is ignored. |
1085 * <p>If {@code useDaylight} is false, this value is ignored. |
1086 * @serial |
1086 * @serial |
1087 */ |
1087 */ |
1088 private int startYear; |
1088 private int startYear; |
1089 |
1089 |
1090 /** |
1090 /** |
1091 * The offset in milliseconds between this zone and GMT. Negative offsets |
1091 * The offset in milliseconds between this zone and GMT. Negative offsets |
1092 * are to the west of Greenwich. To obtain local <em>standard</em> time, |
1092 * are to the west of Greenwich. To obtain local <em>standard</em> time, |
1093 * add the offset to GMT time. To obtain local wall time it may also be |
1093 * add the offset to GMT time. To obtain local wall time it may also be |
1094 * necessary to add <code>dstSavings</code>. |
1094 * necessary to add {@code dstSavings}. |
1095 * @serial |
1095 * @serial |
1096 */ |
1096 */ |
1097 private int rawOffset; |
1097 private int rawOffset; |
1098 |
1098 |
1099 /** |
1099 /** |
1120 |
1120 |
1121 /** |
1121 /** |
1122 * Variables specifying the mode of the start rule. Takes the following |
1122 * Variables specifying the mode of the start rule. Takes the following |
1123 * values: |
1123 * values: |
1124 * <dl> |
1124 * <dl> |
1125 * <dt><code>DOM_MODE</code></dt> |
1125 * <dt>{@code DOM_MODE}</dt> |
1126 * <dd> |
1126 * <dd> |
1127 * Exact day of week; e.g., March 1. |
1127 * Exact day of week; e.g., March 1. |
1128 * </dd> |
1128 * </dd> |
1129 * <dt><code>DOW_IN_MONTH_MODE</code></dt> |
1129 * <dt>{@code DOW_IN_MONTH_MODE}</dt> |
1130 * <dd> |
1130 * <dd> |
1131 * Day of week in month; e.g., last Sunday in March. |
1131 * Day of week in month; e.g., last Sunday in March. |
1132 * </dd> |
1132 * </dd> |
1133 * <dt><code>DOW_GE_DOM_MODE</code></dt> |
1133 * <dt>{@code DOW_GE_DOM_MODE}</dt> |
1134 * <dd> |
1134 * <dd> |
1135 * Day of week after day of month; e.g., Sunday on or after March 15. |
1135 * Day of week after day of month; e.g., Sunday on or after March 15. |
1136 * </dd> |
1136 * </dd> |
1137 * <dt><code>DOW_LE_DOM_MODE</code></dt> |
1137 * <dt>{@code DOW_LE_DOM_MODE}</dt> |
1138 * <dd> |
1138 * <dd> |
1139 * Day of week before day of month; e.g., Sunday on or before March 15. |
1139 * Day of week before day of month; e.g., Sunday on or before March 15. |
1140 * </dd> |
1140 * </dd> |
1141 * </dl> |
1141 * </dl> |
1142 * The setting of this field affects the interpretation of the |
1142 * The setting of this field affects the interpretation of the |
1143 * <code>startDay</code> field. |
1143 * {@code startDay} field. |
1144 * <p>If <code>useDaylight</code> is false, this value is ignored. |
1144 * <p>If {@code useDaylight} is false, this value is ignored. |
1145 * @serial |
1145 * @serial |
1146 * @since 1.1.4 |
1146 * @since 1.1.4 |
1147 */ |
1147 */ |
1148 private int startMode; |
1148 private int startMode; |
1149 |
1149 |
1150 /** |
1150 /** |
1151 * Variables specifying the mode of the end rule. Takes the following |
1151 * Variables specifying the mode of the end rule. Takes the following |
1152 * values: |
1152 * values: |
1153 * <dl> |
1153 * <dl> |
1154 * <dt><code>DOM_MODE</code></dt> |
1154 * <dt>{@code DOM_MODE}</dt> |
1155 * <dd> |
1155 * <dd> |
1156 * Exact day of week; e.g., March 1. |
1156 * Exact day of week; e.g., March 1. |
1157 * </dd> |
1157 * </dd> |
1158 * <dt><code>DOW_IN_MONTH_MODE</code></dt> |
1158 * <dt>{@code DOW_IN_MONTH_MODE}</dt> |
1159 * <dd> |
1159 * <dd> |
1160 * Day of week in month; e.g., last Sunday in March. |
1160 * Day of week in month; e.g., last Sunday in March. |
1161 * </dd> |
1161 * </dd> |
1162 * <dt><code>DOW_GE_DOM_MODE</code></dt> |
1162 * <dt>{@code DOW_GE_DOM_MODE}</dt> |
1163 * <dd> |
1163 * <dd> |
1164 * Day of week after day of month; e.g., Sunday on or after March 15. |
1164 * Day of week after day of month; e.g., Sunday on or after March 15. |
1165 * </dd> |
1165 * </dd> |
1166 * <dt><code>DOW_LE_DOM_MODE</code></dt> |
1166 * <dt>{@code DOW_LE_DOM_MODE}</dt> |
1167 * <dd> |
1167 * <dd> |
1168 * Day of week before day of month; e.g., Sunday on or before March 15. |
1168 * Day of week before day of month; e.g., Sunday on or before March 15. |
1169 * </dd> |
1169 * </dd> |
1170 * </dl> |
1170 * </dl> |
1171 * The setting of this field affects the interpretation of the |
1171 * The setting of this field affects the interpretation of the |
1172 * <code>endDay</code> field. |
1172 * {@code endDay} field. |
1173 * <p>If <code>useDaylight</code> is false, this value is ignored. |
1173 * <p>If {@code useDaylight} is false, this value is ignored. |
1174 * @serial |
1174 * @serial |
1175 * @since 1.1.4 |
1175 * @since 1.1.4 |
1176 */ |
1176 */ |
1177 private int endMode; |
1177 private int endMode; |
1178 |
1178 |
1179 /** |
1179 /** |
1180 * A positive value indicating the amount of time saved during DST in |
1180 * A positive value indicating the amount of time saved during DST in |
1181 * milliseconds. |
1181 * milliseconds. |
1182 * Typically one hour (3600000); sometimes 30 minutes (1800000). |
1182 * Typically one hour (3600000); sometimes 30 minutes (1800000). |
1183 * <p>If <code>useDaylight</code> is false, this value is ignored. |
1183 * <p>If {@code useDaylight} is false, this value is ignored. |
1184 * @serial |
1184 * @serial |
1185 * @since 1.1.4 |
1185 * @since 1.1.4 |
1186 */ |
1186 */ |
1187 private int dstSavings; |
1187 private int dstSavings; |
1188 |
1188 |
1622 |
1623 |
1623 /** |
1624 /** |
1624 * Save the state of this object to a stream (i.e., serialize it). |
1625 * Save the state of this object to a stream (i.e., serialize it). |
1625 * |
1626 * |
1626 * @serialData We write out two formats, a JDK 1.1 compatible format, using |
1627 * @serialData We write out two formats, a JDK 1.1 compatible format, using |
1627 * <code>DOW_IN_MONTH_MODE</code> rules, in the required section, followed |
1628 * {@code DOW_IN_MONTH_MODE} rules, in the required section, followed |
1628 * by the full rules, in packed format, in the optional section. The |
1629 * by the full rules, in packed format, in the optional section. The |
1629 * optional section will be ignored by JDK 1.1 code upon stream in. |
1630 * optional section will be ignored by JDK 1.1 code upon stream in. |
1630 * <p> Contents of the optional section: The length of a byte array is |
1631 * <p> Contents of the optional section: The length of a byte array is |
1631 * emitted (int); this is 4 as of this release. The byte array of the given |
1632 * emitted (int); this is 4 as of this release. The byte array of the given |
1632 * length is emitted. The contents of the byte array are the true values of |
1633 * length is emitted. The contents of the byte array are the true values of |
1633 * the fields <code>startDay</code>, <code>startDayOfWeek</code>, |
1634 * the fields {@code startDay}, {@code startDayOfWeek}, |
1634 * <code>endDay</code>, and <code>endDayOfWeek</code>. The values of these |
1635 * {@code endDay}, and {@code endDayOfWeek}. The values of these |
1635 * fields in the required section are approximate values suited to the rule |
1636 * fields in the required section are approximate values suited to the rule |
1636 * mode <code>DOW_IN_MONTH_MODE</code>, which is the only mode recognized by |
1637 * mode {@code DOW_IN_MONTH_MODE}, which is the only mode recognized by |
1637 * JDK 1.1. |
1638 * JDK 1.1. |
1638 */ |
1639 */ |
|
1640 @java.io.Serial |
1639 private void writeObject(ObjectOutputStream stream) |
1641 private void writeObject(ObjectOutputStream stream) |
1640 throws IOException |
1642 throws IOException |
1641 { |
1643 { |
1642 // Construct a binary rule |
1644 // Construct a binary rule |
1643 byte[] rules = packRules(); |
1645 byte[] rules = packRules(); |