0N/A/*
3558N/A * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * (C) Copyright Taligent, Inc. 1996 - All Rights Reserved
0N/A * (C) Copyright IBM Corp. 1996 - All Rights Reserved
0N/A *
0N/A * The original version of this source code and documentation is copyrighted
0N/A * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
0N/A * materials are provided under terms of a License Agreement between Taligent
0N/A * and Sun. This technology is protected by multiple US and International
0N/A * patents. This notice and attribution to Taligent may not be removed.
0N/A * Taligent is a registered trademark of Taligent, Inc.
0N/A *
0N/A */
0N/A
0N/Apackage java.util;
0N/A
0N/Aimport java.io.ObjectInputStream;
0N/Aimport java.io.ObjectOutputStream;
0N/Aimport java.io.IOException;
0N/Aimport sun.util.calendar.CalendarSystem;
0N/Aimport sun.util.calendar.CalendarUtils;
0N/Aimport sun.util.calendar.BaseCalendar;
0N/Aimport sun.util.calendar.Gregorian;
0N/A
0N/A/**
0N/A * <code>SimpleTimeZone</code> is a concrete subclass of <code>TimeZone</code>
0N/A * that represents a time zone for use with a Gregorian calendar.
0N/A * The class holds an offset from GMT, called <em>raw offset</em>, and start
0N/A * and end rules for a daylight saving time schedule. Since it only holds
0N/A * single values for each, it cannot handle historical changes in the offset
0N/A * from GMT and the daylight saving schedule, except that the {@link
0N/A * #setStartYear setStartYear} method can specify the year when the daylight
0N/A * saving time schedule starts in effect.
0N/A * <p>
0N/A * To construct a <code>SimpleTimeZone</code> with a daylight saving time
0N/A * schedule, the schedule can be described with a set of rules,
0N/A * <em>start-rule</em> and <em>end-rule</em>. A day when daylight saving time
0N/A * starts or ends is specified by a combination of <em>month</em>,
0N/A * <em>day-of-month</em>, and <em>day-of-week</em> values. The <em>month</em>
0N/A * value is represented by a Calendar {@link Calendar#MONTH MONTH} field
0N/A * value, such as {@link Calendar#MARCH}. The <em>day-of-week</em> value is
0N/A * represented by a Calendar {@link Calendar#DAY_OF_WEEK DAY_OF_WEEK} value,
0N/A * such as {@link Calendar#SUNDAY SUNDAY}. The meanings of value combinations
0N/A * are as follows.
0N/A *
0N/A * <ul>
0N/A * <li><b>Exact day of month</b><br>
0N/A * To specify an exact day of month, set the <em>month</em> and
0N/A * <em>day-of-month</em> to an exact value, and <em>day-of-week</em> to zero. For
0N/A * example, to specify March 1, set the <em>month</em> to {@link Calendar#MARCH
0N/A * MARCH}, <em>day-of-month</em> to 1, and <em>day-of-week</em> to 0.</li>
0N/A *
0N/A * <li><b>Day of week on or after day of month</b><br>
0N/A * To specify a day of week on or after an exact day of month, set the
0N/A * <em>month</em> to an exact month value, <em>day-of-month</em> to the day on
0N/A * or after which the rule is applied, and <em>day-of-week</em> to a negative {@link
0N/A * Calendar#DAY_OF_WEEK DAY_OF_WEEK} field value. For example, to specify the
0N/A * second Sunday of April, set <em>month</em> to {@link Calendar#APRIL APRIL},
0N/A * <em>day-of-month</em> to 8, and <em>day-of-week</em> to <code>-</code>{@link
0N/A * Calendar#SUNDAY SUNDAY}.</li>
0N/A *
0N/A * <li><b>Day of week on or before day of month</b><br>
0N/A * To specify a day of the week on or before an exact day of the month, set
0N/A * <em>day-of-month</em> and <em>day-of-week</em> to a negative value. For
0N/A * example, to specify the last Wednesday on or before the 21st of March, set
0N/A * <em>month</em> to {@link Calendar#MARCH MARCH}, <em>day-of-month</em> is -21
0N/A * and <em>day-of-week</em> is <code>-</code>{@link Calendar#WEDNESDAY WEDNESDAY}. </li>
0N/A *
0N/A * <li><b>Last day-of-week of month</b><br>
0N/A * To specify, the last day-of-week of the month, set <em>day-of-week</em> to a
0N/A * {@link Calendar#DAY_OF_WEEK DAY_OF_WEEK} value and <em>day-of-month</em> to
0N/A * -1. For example, to specify the last Sunday of October, set <em>month</em>
0N/A * to {@link Calendar#OCTOBER OCTOBER}, <em>day-of-week</em> to {@link
0N/A * Calendar#SUNDAY SUNDAY} and <em>day-of-month</em> to -1. </li>
0N/A *
0N/A * </ul>
0N/A * The time of the day at which daylight saving time starts or ends is
0N/A * specified by a millisecond value within the day. There are three kinds of
0N/A * <em>mode</em>s to specify the time: {@link #WALL_TIME}, {@link
0N/A * #STANDARD_TIME} and {@link #UTC_TIME}. For example, if daylight
0N/A * saving time ends
0N/A * at 2:00 am in the wall clock time, it can be specified by 7200000
0N/A * milliseconds in the {@link #WALL_TIME} mode. In this case, the wall clock time
0N/A * for an <em>end-rule</em> means the same thing as the daylight time.
0N/A * <p>
0N/A * The following are examples of parameters for constructing time zone objects.
0N/A * <pre><code>
0N/A * // Base GMT offset: -8:00
0N/A * // DST starts: at 2:00am in standard time
0N/A * // on the first Sunday in April
0N/A * // DST ends: at 2:00am in daylight time
0N/A * // on the last Sunday in October
0N/A * // Save: 1 hour
0N/A * SimpleTimeZone(-28800000,
0N/A * "America/Los_Angeles",
0N/A * Calendar.APRIL, 1, -Calendar.SUNDAY,
0N/A * 7200000,
0N/A * Calendar.OCTOBER, -1, Calendar.SUNDAY,
0N/A * 7200000,
0N/A * 3600000)
0N/A *
0N/A * // Base GMT offset: +1:00
0N/A * // DST starts: at 1:00am in UTC time
0N/A * // on the last Sunday in March
0N/A * // DST ends: at 1:00am in UTC time
0N/A * // on the last Sunday in October
0N/A * // Save: 1 hour
0N/A * SimpleTimeZone(3600000,
0N/A * "Europe/Paris",
0N/A * Calendar.MARCH, -1, Calendar.SUNDAY,
0N/A * 3600000, SimpleTimeZone.UTC_TIME,
0N/A * Calendar.OCTOBER, -1, Calendar.SUNDAY,
0N/A * 3600000, SimpleTimeZone.UTC_TIME,
0N/A * 3600000)
0N/A * </code></pre>
0N/A * These parameter rules are also applicable to the set rule methods, such as
0N/A * <code>setStartRule</code>.
0N/A *
0N/A * @since 1.1
0N/A * @see Calendar
0N/A * @see GregorianCalendar
0N/A * @see TimeZone
0N/A * @author David Goldsmith, Mark Davis, Chen-Lieh Huang, Alan Liu
0N/A */
0N/A
0N/Apublic class SimpleTimeZone extends TimeZone {
0N/A /**
0N/A * Constructs a SimpleTimeZone with the given base time zone offset from GMT
0N/A * and time zone ID with no daylight saving time schedule.
0N/A *
0N/A * @param rawOffset The base time zone offset in milliseconds to GMT.
0N/A * @param ID The time zone name that is given to this instance.
0N/A */
0N/A public SimpleTimeZone(int rawOffset, String ID)
0N/A {
0N/A this.rawOffset = rawOffset;
0N/A setID (ID);
0N/A dstSavings = millisPerHour; // In case user sets rules later
0N/A }
0N/A
0N/A /**
0N/A * Constructs a SimpleTimeZone with the given base time zone offset from
0N/A * GMT, time zone ID, and rules for starting and ending the daylight
0N/A * time.
0N/A * Both <code>startTime</code> and <code>endTime</code> are specified to be
0N/A * represented in the wall clock time. The amount of daylight saving is
0N/A * assumed to be 3600000 milliseconds (i.e., one hour). This constructor is
0N/A * equivalent to:
0N/A * <pre><code>
0N/A * SimpleTimeZone(rawOffset,
0N/A * ID,
0N/A * startMonth,
0N/A * startDay,
0N/A * startDayOfWeek,
0N/A * startTime,
0N/A * SimpleTimeZone.{@link #WALL_TIME},
0N/A * endMonth,
0N/A * endDay,
0N/A * endDayOfWeek,
0N/A * endTime,
0N/A * SimpleTimeZone.{@link #WALL_TIME},
0N/A * 3600000)
0N/A * </code></pre>
0N/A *
0N/A * @param rawOffset The given base time zone offset from GMT.
0N/A * @param ID The time zone ID which is given to this object.
0N/A * @param startMonth The daylight saving time starting month. Month is
0N/A * a {@link Calendar#MONTH MONTH} field value (0-based. e.g., 0
0N/A * for January).
0N/A * @param startDay The day of the month on which the daylight saving time starts.
0N/A * See the class description for the special cases of this parameter.
0N/A * @param startDayOfWeek The daylight saving time starting day-of-week.
0N/A * See the class description for the special cases of this parameter.
0N/A * @param startTime The daylight saving time starting time in local wall clock
0N/A * time (in milliseconds within the day), which is local
0N/A * standard time in this case.
0N/A * @param endMonth The daylight saving time ending month. Month is
0N/A * a {@link Calendar#MONTH MONTH} field
0N/A * value (0-based. e.g., 9 for October).
0N/A * @param endDay The day of the month on which the daylight saving time ends.
0N/A * See the class description for the special cases of this parameter.
0N/A * @param endDayOfWeek The daylight saving time ending day-of-week.
0N/A * See the class description for the special cases of this parameter.
0N/A * @param endTime The daylight saving ending time in local wall clock time,
0N/A * (in milliseconds within the day) which is local daylight
0N/A * time in this case.
0N/A * @exception IllegalArgumentException if the month, day, dayOfWeek, or time
0N/A * parameters are out of range for the start or end rule
0N/A */
0N/A public SimpleTimeZone(int rawOffset, String ID,
0N/A int startMonth, int startDay, int startDayOfWeek, int startTime,
0N/A int endMonth, int endDay, int endDayOfWeek, int endTime)
0N/A {
0N/A this(rawOffset, ID,
0N/A startMonth, startDay, startDayOfWeek, startTime, WALL_TIME,
0N/A endMonth, endDay, endDayOfWeek, endTime, WALL_TIME,
0N/A millisPerHour);
0N/A }
0N/A
0N/A /**
0N/A * Constructs a SimpleTimeZone with the given base time zone offset from
0N/A * GMT, time zone ID, and rules for starting and ending the daylight
0N/A * time.
0N/A * Both <code>startTime</code> and <code>endTime</code> are assumed to be
0N/A * represented in the wall clock time. This constructor is equivalent to:
0N/A * <pre><code>
0N/A * SimpleTimeZone(rawOffset,
0N/A * ID,
0N/A * startMonth,
0N/A * startDay,
0N/A * startDayOfWeek,
0N/A * startTime,
0N/A * SimpleTimeZone.{@link #WALL_TIME},
0N/A * endMonth,
0N/A * endDay,
0N/A * endDayOfWeek,
0N/A * endTime,
0N/A * SimpleTimeZone.{@link #WALL_TIME},
0N/A * dstSavings)
0N/A * </code></pre>
0N/A *
0N/A * @param rawOffset The given base time zone offset from GMT.
0N/A * @param ID The time zone ID which is given to this object.
0N/A * @param startMonth The daylight saving time starting month. Month is
0N/A * a {@link Calendar#MONTH MONTH} field
0N/A * value (0-based. e.g., 0 for January).
0N/A * @param startDay The day of the month on which the daylight saving time starts.
0N/A * See the class description for the special cases of this parameter.
0N/A * @param startDayOfWeek The daylight saving time starting day-of-week.
0N/A * See the class description for the special cases of this parameter.
0N/A * @param startTime The daylight saving time starting time in local wall clock
0N/A * time, which is local standard time in this case.
0N/A * @param endMonth The daylight saving time ending month. Month is
0N/A * a {@link Calendar#MONTH MONTH} field
0N/A * value (0-based. e.g., 9 for October).
0N/A * @param endDay The day of the month on which the daylight saving time ends.
0N/A * See the class description for the special cases of this parameter.
0N/A * @param endDayOfWeek The daylight saving time ending day-of-week.
0N/A * See the class description for the special cases of this parameter.
0N/A * @param endTime The daylight saving ending time in local wall clock time,
0N/A * which is local daylight time in this case.
0N/A * @param dstSavings The amount of time in milliseconds saved during
0N/A * daylight saving time.
0N/A * @exception IllegalArgumentException if the month, day, dayOfWeek, or time
0N/A * parameters are out of range for the start or end rule
0N/A * @since 1.2
0N/A */
0N/A public SimpleTimeZone(int rawOffset, String ID,
0N/A int startMonth, int startDay, int startDayOfWeek, int startTime,
0N/A int endMonth, int endDay, int endDayOfWeek, int endTime,
0N/A int dstSavings)
0N/A {
0N/A this(rawOffset, ID,
0N/A startMonth, startDay, startDayOfWeek, startTime, WALL_TIME,
0N/A endMonth, endDay, endDayOfWeek, endTime, WALL_TIME,
0N/A dstSavings);
0N/A }
0N/A
0N/A /**
0N/A * Constructs a SimpleTimeZone with the given base time zone offset from
0N/A * GMT, time zone ID, and rules for starting and ending the daylight
0N/A * time.
0N/A * This constructor takes the full set of the start and end rules
0N/A * parameters, including modes of <code>startTime</code> and
0N/A * <code>endTime</code>. The mode specifies either {@link #WALL_TIME wall
0N/A * time} or {@link #STANDARD_TIME standard time} or {@link #UTC_TIME UTC
0N/A * time}.
0N/A *
0N/A * @param rawOffset The given base time zone offset from GMT.
0N/A * @param ID The time zone ID which is given to this object.
0N/A * @param startMonth The daylight saving time starting month. Month is
0N/A * a {@link Calendar#MONTH MONTH} field
0N/A * value (0-based. e.g., 0 for January).
0N/A * @param startDay The day of the month on which the daylight saving time starts.
0N/A * See the class description for the special cases of this parameter.
0N/A * @param startDayOfWeek The daylight saving time starting day-of-week.
0N/A * See the class description for the special cases of this parameter.
0N/A * @param startTime The daylight saving time starting time in the time mode
0N/A * specified by <code>startTimeMode</code>.
0N/A * @param startTimeMode The mode of the start time specified by startTime.
0N/A * @param endMonth The daylight saving time ending month. Month is
0N/A * a {@link Calendar#MONTH MONTH} field
0N/A * value (0-based. e.g., 9 for October).
0N/A * @param endDay The day of the month on which the daylight saving time ends.
0N/A * See the class description for the special cases of this parameter.
0N/A * @param endDayOfWeek The daylight saving time ending day-of-week.
0N/A * See the class description for the special cases of this parameter.
0N/A * @param endTime The daylight saving ending time in time time mode
0N/A * specified by <code>endTimeMode</code>.
0N/A * @param endTimeMode The mode of the end time specified by endTime
0N/A * @param dstSavings The amount of time in milliseconds saved during
0N/A * daylight saving time.
0N/A *
0N/A * @exception IllegalArgumentException if the month, day, dayOfWeek, time more, or
0N/A * time parameters are out of range for the start or end rule, or if a time mode
0N/A * value is invalid.
0N/A *
0N/A * @see #WALL_TIME
0N/A * @see #STANDARD_TIME
0N/A * @see #UTC_TIME
0N/A *
0N/A * @since 1.4
0N/A */
0N/A public SimpleTimeZone(int rawOffset, String ID,
0N/A int startMonth, int startDay, int startDayOfWeek,
0N/A int startTime, int startTimeMode,
0N/A int endMonth, int endDay, int endDayOfWeek,
0N/A int endTime, int endTimeMode,
0N/A int dstSavings) {
0N/A
0N/A setID(ID);
0N/A this.rawOffset = rawOffset;
0N/A this.startMonth = startMonth;
0N/A this.startDay = startDay;
0N/A this.startDayOfWeek = startDayOfWeek;
0N/A this.startTime = startTime;
0N/A this.startTimeMode = startTimeMode;
0N/A this.endMonth = endMonth;
0N/A this.endDay = endDay;
0N/A this.endDayOfWeek = endDayOfWeek;
0N/A this.endTime = endTime;
0N/A this.endTimeMode = endTimeMode;
0N/A this.dstSavings = dstSavings;
0N/A
0N/A // this.useDaylight is set by decodeRules
0N/A decodeRules();
0N/A if (dstSavings <= 0) {
0N/A throw new IllegalArgumentException("Illegal daylight saving value: " + dstSavings);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the daylight saving time starting year.
0N/A *
0N/A * @param year The daylight saving starting year.
0N/A */
0N/A public void setStartYear(int year)
0N/A {
0N/A startYear = year;
0N/A invalidateCache();
0N/A }
0N/A
0N/A /**
0N/A * Sets the daylight saving time start rule. For example, if daylight saving
0N/A * time starts on the first Sunday in April at 2 am in local wall clock
0N/A * time, you can set the start rule by calling:
0N/A * <pre><code>setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2*60*60*1000);</code></pre>
0N/A *
0N/A * @param startMonth The daylight saving time starting month. Month is
0N/A * a {@link Calendar#MONTH MONTH} field
0N/A * value (0-based. e.g., 0 for January).
0N/A * @param startDay The day of the month on which the daylight saving time starts.
0N/A * See the class description for the special cases of this parameter.
0N/A * @param startDayOfWeek The daylight saving time starting day-of-week.
0N/A * See the class description for the special cases of this parameter.
0N/A * @param startTime The daylight saving time starting time in local wall clock
0N/A * time, which is local standard time in this case.
0N/A * @exception IllegalArgumentException if the <code>startMonth</code>, <code>startDay</code>,
0N/A * <code>startDayOfWeek</code>, or <code>startTime</code> parameters are out of range
0N/A */
0N/A public void setStartRule(int startMonth, int startDay, int startDayOfWeek, int startTime)
0N/A {
0N/A this.startMonth = startMonth;
0N/A this.startDay = startDay;
0N/A this.startDayOfWeek = startDayOfWeek;
0N/A this.startTime = startTime;
0N/A startTimeMode = WALL_TIME;
0N/A decodeStartRule();
0N/A invalidateCache();
0N/A }
0N/A
0N/A /**
0N/A * Sets the daylight saving time start rule to a fixed date within a month.
0N/A * This method is equivalent to:
0N/A * <pre><code>setStartRule(startMonth, startDay, 0, startTime)</code></pre>
0N/A *
0N/A * @param startMonth The daylight saving time starting month. Month is
0N/A * a {@link Calendar#MONTH MONTH} field
0N/A * value (0-based. e.g., 0 for January).
0N/A * @param startDay The day of the month on which the daylight saving time starts.
0N/A * @param startTime The daylight saving time starting time in local wall clock
0N/A * time, which is local standard time in this case.
0N/A * See the class description for the special cases of this parameter.
0N/A * @exception IllegalArgumentException if the <code>startMonth</code>,
0N/A * <code>startDayOfMonth</code>, or <code>startTime</code> parameters are out of range
0N/A * @since 1.2
0N/A */
0N/A public void setStartRule(int startMonth, int startDay, int startTime) {
0N/A setStartRule(startMonth, startDay, 0, startTime);
0N/A }
0N/A
0N/A /**
0N/A * Sets the daylight saving time start rule to a weekday before or after the given date within
0N/A * a month, e.g., the first Monday on or after the 8th.
0N/A *
0N/A * @param startMonth The daylight saving time starting month. Month is
0N/A * a {@link Calendar#MONTH MONTH} field
0N/A * value (0-based. e.g., 0 for January).
0N/A * @param startDay The day of the month on which the daylight saving time starts.
0N/A * @param startDayOfWeek The daylight saving time starting day-of-week.
0N/A * @param startTime The daylight saving time starting time in local wall clock
0N/A * time, which is local standard time in this case.
0N/A * @param after If true, this rule selects the first <code>dayOfWeek</code> on or
0N/A * <em>after</em> <code>dayOfMonth</code>. If false, this rule
0N/A * selects the last <code>dayOfWeek</code> on or <em>before</em>
0N/A * <code>dayOfMonth</code>.
0N/A * @exception IllegalArgumentException if the <code>startMonth</code>, <code>startDay</code>,
0N/A * <code>startDayOfWeek</code>, or <code>startTime</code> parameters are out of range
0N/A * @since 1.2
0N/A */
0N/A public void setStartRule(int startMonth, int startDay, int startDayOfWeek,
0N/A int startTime, boolean after)
0N/A {
0N/A // TODO: this method doesn't check the initial values of dayOfMonth or dayOfWeek.
0N/A if (after) {
0N/A setStartRule(startMonth, startDay, -startDayOfWeek, startTime);
0N/A } else {
0N/A setStartRule(startMonth, -startDay, -startDayOfWeek, startTime);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the daylight saving time end rule. For example, if daylight saving time
0N/A * ends on the last Sunday in October at 2 am in wall clock time,
0N/A * you can set the end rule by calling:
0N/A * <code>setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2*60*60*1000);</code>
0N/A *
0N/A * @param endMonth The daylight saving time ending month. Month is
0N/A * a {@link Calendar#MONTH MONTH} field
0N/A * value (0-based. e.g., 9 for October).
0N/A * @param endDay The day of the month on which the daylight saving time ends.
0N/A * See the class description for the special cases of this parameter.
0N/A * @param endDayOfWeek The daylight saving time ending day-of-week.
0N/A * See the class description for the special cases of this parameter.
0N/A * @param endTime The daylight saving ending time in local wall clock time,
0N/A * (in milliseconds within the day) which is local daylight
0N/A * time in this case.
0N/A * @exception IllegalArgumentException if the <code>endMonth</code>, <code>endDay</code>,
0N/A * <code>endDayOfWeek</code>, or <code>endTime</code> parameters are out of range
0N/A */
0N/A public void setEndRule(int endMonth, int endDay, int endDayOfWeek,
0N/A int endTime)
0N/A {
0N/A this.endMonth = endMonth;
0N/A this.endDay = endDay;
0N/A this.endDayOfWeek = endDayOfWeek;
0N/A this.endTime = endTime;
0N/A this.endTimeMode = WALL_TIME;
0N/A decodeEndRule();
0N/A invalidateCache();
0N/A }
0N/A
0N/A /**
0N/A * Sets the daylight saving time end rule to a fixed date within a month.
0N/A * This method is equivalent to:
0N/A * <pre><code>setEndRule(endMonth, endDay, 0, endTime)</code></pre>
0N/A *
0N/A * @param endMonth The daylight saving time ending month. Month is
0N/A * a {@link Calendar#MONTH MONTH} field
0N/A * value (0-based. e.g., 9 for October).
0N/A * @param endDay The day of the month on which the daylight saving time ends.
0N/A * @param endTime The daylight saving ending time in local wall clock time,
0N/A * (in milliseconds within the day) which is local daylight
0N/A * time in this case.
0N/A * @exception IllegalArgumentException the <code>endMonth</code>, <code>endDay</code>,
0N/A * or <code>endTime</code> parameters are out of range
0N/A * @since 1.2
0N/A */
0N/A public void setEndRule(int endMonth, int endDay, int endTime)
0N/A {
0N/A setEndRule(endMonth, endDay, 0, endTime);
0N/A }
0N/A
0N/A /**
0N/A * Sets the daylight saving time end rule to a weekday before or after the given date within
0N/A * a month, e.g., the first Monday on or after the 8th.
0N/A *
0N/A * @param endMonth The daylight saving time ending month. Month is
0N/A * a {@link Calendar#MONTH MONTH} field
0N/A * value (0-based. e.g., 9 for October).
0N/A * @param endDay The day of the month on which the daylight saving time ends.
0N/A * @param endDayOfWeek The daylight saving time ending day-of-week.
0N/A * @param endTime The daylight saving ending time in local wall clock time,
0N/A * (in milliseconds within the day) which is local daylight
0N/A * time in this case.
0N/A * @param after If true, this rule selects the first <code>endDayOfWeek</code> on
0N/A * or <em>after</em> <code>endDay</code>. If false, this rule
0N/A * selects the last <code>endDayOfWeek</code> on or before
0N/A * <code>endDay</code> of the month.
0N/A * @exception IllegalArgumentException the <code>endMonth</code>, <code>endDay</code>,
0N/A * <code>endDayOfWeek</code>, or <code>endTime</code> parameters are out of range
0N/A * @since 1.2
0N/A */
0N/A public void setEndRule(int endMonth, int endDay, int endDayOfWeek, int endTime, boolean after)
0N/A {
0N/A if (after) {
0N/A setEndRule(endMonth, endDay, -endDayOfWeek, endTime);
0N/A } else {
0N/A setEndRule(endMonth, -endDay, -endDayOfWeek, endTime);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the offset of this time zone from UTC at the given
0N/A * time. If daylight saving time is in effect at the given time,
0N/A * the offset value is adjusted with the amount of daylight
0N/A * saving.
0N/A *
0N/A * @param date the time at which the time zone offset is found
0N/A * @return the amount of time in milliseconds to add to UTC to get
0N/A * local time.
0N/A * @since 1.4
0N/A */
0N/A public int getOffset(long date) {
0N/A return getOffsets(date, null);
0N/A }
0N/A
0N/A /**
0N/A * @see TimeZone#getOffsets
0N/A */
0N/A int getOffsets(long date, int[] offsets) {
0N/A int offset = rawOffset;
0N/A
0N/A computeOffset:
0N/A if (useDaylight) {
0N/A synchronized (this) {
0N/A if (cacheStart != 0) {
0N/A if (date >= cacheStart && date < cacheEnd) {
0N/A offset += dstSavings;
0N/A break computeOffset;
0N/A }
0N/A }
0N/A }
0N/A BaseCalendar cal = date >= GregorianCalendar.DEFAULT_GREGORIAN_CUTOVER ?
0N/A gcal : (BaseCalendar) CalendarSystem.forName("julian");
0N/A BaseCalendar.Date cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE);
0N/A // Get the year in local time
0N/A cal.getCalendarDate(date + rawOffset, cdate);
0N/A int year = cdate.getNormalizedYear();
0N/A if (year >= startYear) {
0N/A // Clear time elements for the transition calculations
0N/A cdate.setTimeOfDay(0, 0, 0, 0);
0N/A offset = getOffset(cal, cdate, year, date);
0N/A }
0N/A }
0N/A
0N/A if (offsets != null) {
0N/A offsets[0] = rawOffset;
0N/A offsets[1] = offset - rawOffset;
0N/A }
0N/A return offset;
0N/A }
0N/A
0N/A /**
0N/A * Returns the difference in milliseconds between local time and
0N/A * UTC, taking into account both the raw offset and the effect of
0N/A * daylight saving, for the specified date and time. This method
0N/A * assumes that the start and end month are distinct. It also
0N/A * uses a default {@link GregorianCalendar} object as its
0N/A * underlying calendar, such as for determining leap years. Do
0N/A * not use the result of this method with a calendar other than a
0N/A * default <code>GregorianCalendar</code>.
0N/A *
0N/A * <p><em>Note: In general, clients should use
0N/A * <code>Calendar.get(ZONE_OFFSET) + Calendar.get(DST_OFFSET)</code>
0N/A * instead of calling this method.</em>
0N/A *
0N/A * @param era The era of the given date.
0N/A * @param year The year in the given date.
0N/A * @param month The month in the given date. Month is 0-based. e.g.,
0N/A * 0 for January.
0N/A * @param day The day-in-month of the given date.
0N/A * @param dayOfWeek The day-of-week of the given date.
0N/A * @param millis The milliseconds in day in <em>standard</em> local time.
0N/A * @return The milliseconds to add to UTC to get local time.
0N/A * @exception IllegalArgumentException the <code>era</code>,
0N/A * <code>month</code>, <code>day</code>, <code>dayOfWeek</code>,
0N/A * or <code>millis</code> parameters are out of range
0N/A */
0N/A public int getOffset(int era, int year, int month, int day, int dayOfWeek,
0N/A int millis)
0N/A {
0N/A if (era != GregorianCalendar.AD && era != GregorianCalendar.BC) {
0N/A throw new IllegalArgumentException("Illegal era " + era);
0N/A }
0N/A
0N/A int y = year;
0N/A if (era == GregorianCalendar.BC) {
0N/A // adjust y with the GregorianCalendar-style year numbering.
0N/A y = 1 - y;
0N/A }
0N/A
0N/A // If the year isn't representable with the 64-bit long
0N/A // integer in milliseconds, convert the year to an
0N/A // equivalent year. This is required to pass some JCK test cases
0N/A // which are actually useless though because the specified years
0N/A // can't be supported by the Java time system.
0N/A if (y >= 292278994) {
0N/A y = 2800 + y % 2800;
0N/A } else if (y <= -292269054) {
0N/A // y %= 28 also produces an equivalent year, but positive
0N/A // year numbers would be convenient to use the UNIX cal
0N/A // command.
0N/A y = (int) CalendarUtils.mod((long) y, 28);
0N/A }
0N/A
0N/A // convert year to its 1-based month value
0N/A int m = month + 1;
0N/A
0N/A // First, calculate time as a Gregorian date.
0N/A BaseCalendar cal = gcal;
0N/A BaseCalendar.Date cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE);
0N/A cdate.setDate(y, m, day);
0N/A long time = cal.getTime(cdate); // normalize cdate
0N/A time += millis - rawOffset; // UTC time
0N/A
0N/A // If the time value represents a time before the default
0N/A // Gregorian cutover, recalculate time using the Julian
0N/A // calendar system. For the Julian calendar system, the
0N/A // normalized year numbering is ..., -2 (BCE 2), -1 (BCE 1),
0N/A // 1, 2 ... which is different from the GregorianCalendar
0N/A // style year numbering (..., -1, 0 (BCE 1), 1, 2, ...).
0N/A if (time < GregorianCalendar.DEFAULT_GREGORIAN_CUTOVER) {
0N/A cal = (BaseCalendar) CalendarSystem.forName("julian");
0N/A cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE);
0N/A cdate.setNormalizedDate(y, m, day);
0N/A time = cal.getTime(cdate) + millis - rawOffset;
0N/A }
0N/A
0N/A if ((cdate.getNormalizedYear() != y)
0N/A || (cdate.getMonth() != m)
0N/A || (cdate.getDayOfMonth() != day)
0N/A // The validation should be cdate.getDayOfWeek() ==
0N/A // dayOfWeek. However, we don't check dayOfWeek for
0N/A // compatibility.
0N/A || (dayOfWeek < Calendar.SUNDAY || dayOfWeek > Calendar.SATURDAY)
0N/A || (millis < 0 || millis >= (24*60*60*1000))) {
0N/A throw new IllegalArgumentException();
0N/A }
0N/A
0N/A if (!useDaylight || year < startYear || era != GregorianCalendar.CE) {
0N/A return rawOffset;
0N/A }
0N/A
0N/A return getOffset(cal, cdate, y, time);
0N/A }
0N/A
0N/A private int getOffset(BaseCalendar cal, BaseCalendar.Date cdate, int year, long time) {
0N/A synchronized (this) {
0N/A if (cacheStart != 0) {
0N/A if (time >= cacheStart && time < cacheEnd) {
0N/A return rawOffset + dstSavings;
0N/A }
0N/A if (year == cacheYear) {
0N/A return rawOffset;
0N/A }
0N/A }
0N/A }
0N/A
0N/A long start = getStart(cal, cdate, year);
0N/A long end = getEnd(cal, cdate, year);
0N/A int offset = rawOffset;
0N/A if (start <= end) {
0N/A if (time >= start && time < end) {
0N/A offset += dstSavings;
0N/A }
0N/A synchronized (this) {
0N/A cacheYear = year;
0N/A cacheStart = start;
0N/A cacheEnd = end;
0N/A }
0N/A } else {
0N/A if (time < end) {
0N/A // TODO: support Gregorian cutover. The previous year
0N/A // may be in the other calendar system.
0N/A start = getStart(cal, cdate, year - 1);
0N/A if (time >= start) {
0N/A offset += dstSavings;
0N/A }
0N/A } else if (time >= start) {
0N/A // TODO: support Gregorian cutover. The next year
0N/A // may be in the other calendar system.
0N/A end = getEnd(cal, cdate, year + 1);
0N/A if (time < end) {
0N/A offset += dstSavings;
0N/A }
0N/A }
0N/A if (start <= end) {
0N/A synchronized (this) {
0N/A // The start and end transitions are in multiple years.
0N/A cacheYear = (long) startYear - 1;
0N/A cacheStart = start;
0N/A cacheEnd = end;
0N/A }
0N/A }
0N/A }
0N/A return offset;
0N/A }
0N/A
0N/A private long getStart(BaseCalendar cal, BaseCalendar.Date cdate, int year) {
0N/A int time = startTime;
0N/A if (startTimeMode != UTC_TIME) {
0N/A time -= rawOffset;
0N/A }
0N/A return getTransition(cal, cdate, startMode, year, startMonth, startDay,
0N/A startDayOfWeek, time);
0N/A }
0N/A
0N/A private long getEnd(BaseCalendar cal, BaseCalendar.Date cdate, int year) {
0N/A int time = endTime;
0N/A if (endTimeMode != UTC_TIME) {
0N/A time -= rawOffset;
0N/A }
0N/A if (endTimeMode == WALL_TIME) {
0N/A time -= dstSavings;
0N/A }
0N/A return getTransition(cal, cdate, endMode, year, endMonth, endDay,
0N/A endDayOfWeek, time);
0N/A }
0N/A
0N/A private long getTransition(BaseCalendar cal, BaseCalendar.Date cdate,
0N/A int mode, int year, int month, int dayOfMonth,
0N/A int dayOfWeek, int timeOfDay) {
0N/A cdate.setNormalizedYear(year);
0N/A cdate.setMonth(month + 1);
0N/A switch (mode) {
0N/A case DOM_MODE:
0N/A cdate.setDayOfMonth(dayOfMonth);
0N/A break;
0N/A
0N/A case DOW_IN_MONTH_MODE:
0N/A cdate.setDayOfMonth(1);
0N/A if (dayOfMonth < 0) {
0N/A cdate.setDayOfMonth(cal.getMonthLength(cdate));
0N/A }
0N/A cdate = (BaseCalendar.Date) cal.getNthDayOfWeek(dayOfMonth, dayOfWeek, cdate);
0N/A break;
0N/A
0N/A case DOW_GE_DOM_MODE:
0N/A cdate.setDayOfMonth(dayOfMonth);
0N/A cdate = (BaseCalendar.Date) cal.getNthDayOfWeek(1, dayOfWeek, cdate);
0N/A break;
0N/A
0N/A case DOW_LE_DOM_MODE:
0N/A cdate.setDayOfMonth(dayOfMonth);
0N/A cdate = (BaseCalendar.Date) cal.getNthDayOfWeek(-1, dayOfWeek, cdate);
0N/A break;
0N/A }
0N/A return cal.getTime(cdate) + timeOfDay;
0N/A }
0N/A
0N/A /**
0N/A * Gets the GMT offset for this time zone.
0N/A * @return the GMT offset value in milliseconds
0N/A * @see #setRawOffset
0N/A */
0N/A public int getRawOffset()
0N/A {
0N/A // The given date will be taken into account while
0N/A // we have the historical time zone data in place.
0N/A return rawOffset;
0N/A }
0N/A
0N/A /**
0N/A * Sets the base time zone offset to GMT.
0N/A * This is the offset to add to UTC to get local time.
0N/A * @see #getRawOffset
0N/A */
0N/A public void setRawOffset(int offsetMillis)
0N/A {
0N/A this.rawOffset = offsetMillis;
0N/A }
0N/A
0N/A /**
0N/A * Sets the amount of time in milliseconds that the clock is advanced
0N/A * during daylight saving time.
0N/A * @param millisSavedDuringDST the number of milliseconds the time is
0N/A * advanced with respect to standard time when the daylight saving time rules
0N/A * are in effect. A positive number, typically one hour (3600000).
0N/A * @see #getDSTSavings
0N/A * @since 1.2
0N/A */
0N/A public void setDSTSavings(int millisSavedDuringDST) {
0N/A if (millisSavedDuringDST <= 0) {
0N/A throw new IllegalArgumentException("Illegal daylight saving value: "
0N/A + millisSavedDuringDST);
0N/A }
0N/A dstSavings = millisSavedDuringDST;
0N/A }
0N/A
0N/A /**
0N/A * Returns the amount of time in milliseconds that the clock is
0N/A * advanced during daylight saving time.
0N/A *
0N/A * @return the number of milliseconds the time is advanced with
0N/A * respect to standard time when the daylight saving rules are in
0N/A * effect, or 0 (zero) if this time zone doesn't observe daylight
0N/A * saving time.
0N/A *
0N/A * @see #setDSTSavings
0N/A * @since 1.2
0N/A */
0N/A public int getDSTSavings() {
3558N/A return useDaylight ? dstSavings : 0;
0N/A }
0N/A
0N/A /**
0N/A * Queries if this time zone uses daylight saving time.
0N/A * @return true if this time zone uses daylight saving time;
0N/A * false otherwise.
0N/A */
0N/A public boolean useDaylightTime()
0N/A {
0N/A return useDaylight;
0N/A }
0N/A
0N/A /**
3558N/A * Returns {@code true} if this {@code SimpleTimeZone} observes
3558N/A * Daylight Saving Time. This method is equivalent to {@link
3558N/A * #useDaylightTime()}.
3558N/A *
3558N/A * @return {@code true} if this {@code SimpleTimeZone} observes
3558N/A * Daylight Saving Time; {@code false} otherwise.
3558N/A * @since 1.7
3558N/A */
3558N/A @Override
3558N/A public boolean observesDaylightTime() {
3558N/A return useDaylightTime();
3558N/A }
3558N/A
3558N/A /**
0N/A * Queries if the given date is in daylight saving time.
0N/A * @return true if daylight saving time is in effective at the
0N/A * given date; false otherwise.
0N/A */
0N/A public boolean inDaylightTime(Date date)
0N/A {
0N/A return (getOffset(date.getTime()) != rawOffset);
0N/A }
0N/A
0N/A /**
0N/A * Returns a clone of this <code>SimpleTimeZone</code> instance.
0N/A * @return a clone of this instance.
0N/A */
0N/A public Object clone()
0N/A {
0N/A return super.clone();
0N/A }
0N/A
0N/A /**
0N/A * Generates the hash code for the SimpleDateFormat object.
0N/A * @return the hash code for this object
0N/A */
0N/A public synchronized int hashCode()
0N/A {
0N/A return startMonth ^ startDay ^ startDayOfWeek ^ startTime ^
0N/A endMonth ^ endDay ^ endDayOfWeek ^ endTime ^ rawOffset;
0N/A }
0N/A
0N/A /**
0N/A * Compares the equality of two <code>SimpleTimeZone</code> objects.
0N/A *
0N/A * @param obj The <code>SimpleTimeZone</code> object to be compared with.
0N/A * @return True if the given <code>obj</code> is the same as this
0N/A * <code>SimpleTimeZone</code> object; false otherwise.
0N/A */
0N/A public boolean equals(Object obj)
0N/A {
0N/A if (this == obj) {
0N/A return true;
0N/A }
0N/A if (!(obj instanceof SimpleTimeZone)) {
0N/A return false;
0N/A }
0N/A
0N/A SimpleTimeZone that = (SimpleTimeZone) obj;
0N/A
0N/A return getID().equals(that.getID()) &&
0N/A hasSameRules(that);
0N/A }
0N/A
0N/A /**
0N/A * Returns <code>true</code> if this zone has the same rules and offset as another zone.
0N/A * @param other the TimeZone object to be compared with
0N/A * @return <code>true</code> if the given zone is a SimpleTimeZone and has the
0N/A * same rules and offset as this one
0N/A * @since 1.2
0N/A */
0N/A public boolean hasSameRules(TimeZone other) {
0N/A if (this == other) {
0N/A return true;
0N/A }
0N/A if (!(other instanceof SimpleTimeZone)) {
0N/A return false;
0N/A }
0N/A SimpleTimeZone that = (SimpleTimeZone) other;
0N/A return rawOffset == that.rawOffset &&
0N/A useDaylight == that.useDaylight &&
0N/A (!useDaylight
0N/A // Only check rules if using DST
0N/A || (dstSavings == that.dstSavings &&
0N/A startMode == that.startMode &&
0N/A startMonth == that.startMonth &&
0N/A startDay == that.startDay &&
0N/A startDayOfWeek == that.startDayOfWeek &&
0N/A startTime == that.startTime &&
0N/A startTimeMode == that.startTimeMode &&
0N/A endMode == that.endMode &&
0N/A endMonth == that.endMonth &&
0N/A endDay == that.endDay &&
0N/A endDayOfWeek == that.endDayOfWeek &&
0N/A endTime == that.endTime &&
0N/A endTimeMode == that.endTimeMode &&
0N/A startYear == that.startYear));
0N/A }
0N/A
0N/A /**
0N/A * Returns a string representation of this time zone.
0N/A * @return a string representation of this time zone.
0N/A */
0N/A public String toString() {
0N/A return getClass().getName() +
0N/A "[id=" + getID() +
0N/A ",offset=" + rawOffset +
0N/A ",dstSavings=" + dstSavings +
0N/A ",useDaylight=" + useDaylight +
0N/A ",startYear=" + startYear +
0N/A ",startMode=" + startMode +
0N/A ",startMonth=" + startMonth +
0N/A ",startDay=" + startDay +
0N/A ",startDayOfWeek=" + startDayOfWeek +
0N/A ",startTime=" + startTime +
0N/A ",startTimeMode=" + startTimeMode +
0N/A ",endMode=" + endMode +
0N/A ",endMonth=" + endMonth +
0N/A ",endDay=" + endDay +
0N/A ",endDayOfWeek=" + endDayOfWeek +
0N/A ",endTime=" + endTime +
0N/A ",endTimeMode=" + endTimeMode + ']';
0N/A }
0N/A
0N/A // =======================privates===============================
0N/A
0N/A /**
0N/A * The month in which daylight saving time starts. This value must be
0N/A * between <code>Calendar.JANUARY</code> and
0N/A * <code>Calendar.DECEMBER</code> inclusive. This value must not equal
0N/A * <code>endMonth</code>.
0N/A * <p>If <code>useDaylight</code> is false, this value is ignored.
0N/A * @serial
0N/A */
0N/A private int startMonth;
0N/A
0N/A /**
0N/A * This field has two possible interpretations:
0N/A * <dl>
0N/A * <dt><code>startMode == DOW_IN_MONTH</code></dt>
0N/A * <dd>
0N/A * <code>startDay</code> indicates the day of the month of
0N/A * <code>startMonth</code> on which daylight
0N/A * saving time starts, from 1 to 28, 30, or 31, depending on the
0N/A * <code>startMonth</code>.
0N/A * </dd>
0N/A * <dt><code>startMode != DOW_IN_MONTH</code></dt>
0N/A * <dd>
0N/A * <code>startDay</code> indicates which <code>startDayOfWeek</code> in the
0N/A * month <code>startMonth</code> daylight
0N/A * saving time starts on. For example, a value of +1 and a
0N/A * <code>startDayOfWeek</code> of <code>Calendar.SUNDAY</code> indicates the
0N/A * first Sunday of <code>startMonth</code>. Likewise, +2 would indicate the
0N/A * second Sunday, and -1 the last Sunday. A value of 0 is illegal.
0N/A * </dd>
0N/A * </dl>
0N/A * <p>If <code>useDaylight</code> is false, this value is ignored.
0N/A * @serial
0N/A */
0N/A private int startDay;
0N/A
0N/A /**
0N/A * The day of the week on which daylight saving time starts. This value
0N/A * must be between <code>Calendar.SUNDAY</code> and
0N/A * <code>Calendar.SATURDAY</code> inclusive.
0N/A * <p>If <code>useDaylight</code> is false or
0N/A * <code>startMode == DAY_OF_MONTH</code>, this value is ignored.
0N/A * @serial
0N/A */
0N/A private int startDayOfWeek;
0N/A
0N/A /**
0N/A * The time in milliseconds after midnight at which daylight saving
0N/A * time starts. This value is expressed as wall time, standard time,
0N/A * or UTC time, depending on the setting of <code>startTimeMode</code>.
0N/A * <p>If <code>useDaylight</code> is false, this value is ignored.
0N/A * @serial
0N/A */
0N/A private int startTime;
0N/A
0N/A /**
0N/A * The format of startTime, either WALL_TIME, STANDARD_TIME, or UTC_TIME.
0N/A * @serial
0N/A * @since 1.3
0N/A */
0N/A private int startTimeMode;
0N/A
0N/A /**
0N/A * The month in which daylight saving time ends. This value must be
0N/A * between <code>Calendar.JANUARY</code> and
0N/A * <code>Calendar.UNDECIMBER</code>. This value must not equal
0N/A * <code>startMonth</code>.
0N/A * <p>If <code>useDaylight</code> is false, this value is ignored.
0N/A * @serial
0N/A */
0N/A private int endMonth;
0N/A
0N/A /**
0N/A * This field has two possible interpretations:
0N/A * <dl>
0N/A * <dt><code>endMode == DOW_IN_MONTH</code></dt>
0N/A * <dd>
0N/A * <code>endDay</code> indicates the day of the month of
0N/A * <code>endMonth</code> on which daylight
0N/A * saving time ends, from 1 to 28, 30, or 31, depending on the
0N/A * <code>endMonth</code>.
0N/A * </dd>
0N/A * <dt><code>endMode != DOW_IN_MONTH</code></dt>
0N/A * <dd>
0N/A * <code>endDay</code> indicates which <code>endDayOfWeek</code> in th
0N/A * month <code>endMonth</code> daylight
0N/A * saving time ends on. For example, a value of +1 and a
0N/A * <code>endDayOfWeek</code> of <code>Calendar.SUNDAY</code> indicates the
0N/A * first Sunday of <code>endMonth</code>. Likewise, +2 would indicate the
0N/A * second Sunday, and -1 the last Sunday. A value of 0 is illegal.
0N/A * </dd>
0N/A * </dl>
0N/A * <p>If <code>useDaylight</code> is false, this value is ignored.
0N/A * @serial
0N/A */
0N/A private int endDay;
0N/A
0N/A /**
0N/A * The day of the week on which daylight saving time ends. This value
0N/A * must be between <code>Calendar.SUNDAY</code> and
0N/A * <code>Calendar.SATURDAY</code> inclusive.
0N/A * <p>If <code>useDaylight</code> is false or
0N/A * <code>endMode == DAY_OF_MONTH</code>, this value is ignored.
0N/A * @serial
0N/A */
0N/A private int endDayOfWeek;
0N/A
0N/A /**
0N/A * The time in milliseconds after midnight at which daylight saving
0N/A * time ends. This value is expressed as wall time, standard time,
0N/A * or UTC time, depending on the setting of <code>endTimeMode</code>.
0N/A * <p>If <code>useDaylight</code> is false, this value is ignored.
0N/A * @serial
0N/A */
0N/A private int endTime;
0N/A
0N/A /**
0N/A * The format of endTime, either <code>WALL_TIME</code>,
0N/A * <code>STANDARD_TIME</code>, or <code>UTC_TIME</code>.
0N/A * @serial
0N/A * @since 1.3
0N/A */
0N/A private int endTimeMode;
0N/A
0N/A /**
0N/A * The year in which daylight saving time is first observed. This is an {@link GregorianCalendar#AD AD}
0N/A * value. If this value is less than 1 then daylight saving time is observed
0N/A * for all <code>AD</code> years.
0N/A * <p>If <code>useDaylight</code> is false, this value is ignored.
0N/A * @serial
0N/A */
0N/A private int startYear;
0N/A
0N/A /**
0N/A * The offset in milliseconds between this zone and GMT. Negative offsets
0N/A * are to the west of Greenwich. To obtain local <em>standard</em> time,
0N/A * add the offset to GMT time. To obtain local wall time it may also be
0N/A * necessary to add <code>dstSavings</code>.
0N/A * @serial
0N/A */
0N/A private int rawOffset;
0N/A
0N/A /**
0N/A * A boolean value which is true if and only if this zone uses daylight
0N/A * saving time. If this value is false, several other fields are ignored.
0N/A * @serial
0N/A */
0N/A private boolean useDaylight=false; // indicate if this time zone uses DST
0N/A
0N/A private static final int millisPerHour = 60*60*1000;
0N/A private static final int millisPerDay = 24*millisPerHour;
0N/A
0N/A /**
0N/A * This field was serialized in JDK 1.1, so we have to keep it that way
0N/A * to maintain serialization compatibility. However, there's no need to
0N/A * recreate the array each time we create a new time zone.
0N/A * @serial An array of bytes containing the values {31, 28, 31, 30, 31, 30,
0N/A * 31, 31, 30, 31, 30, 31}. This is ignored as of the Java 2 platform v1.2, however, it must
0N/A * be streamed out for compatibility with JDK 1.1.
0N/A */
0N/A private final byte monthLength[] = staticMonthLength;
0N/A private final static byte staticMonthLength[] = {31,28,31,30,31,30,31,31,30,31,30,31};
0N/A private final static byte staticLeapMonthLength[] = {31,29,31,30,31,30,31,31,30,31,30,31};
0N/A
0N/A /**
0N/A * Variables specifying the mode of the start rule. Takes the following
0N/A * values:
0N/A * <dl>
0N/A * <dt><code>DOM_MODE</code></dt>
0N/A * <dd>
0N/A * Exact day of week; e.g., March 1.
0N/A * </dd>
0N/A * <dt><code>DOW_IN_MONTH_MODE</code></dt>
0N/A * <dd>
0N/A * Day of week in month; e.g., last Sunday in March.
0N/A * </dd>
0N/A * <dt><code>DOW_GE_DOM_MODE</code></dt>
0N/A * <dd>
0N/A * Day of week after day of month; e.g., Sunday on or after March 15.
0N/A * </dd>
0N/A * <dt><code>DOW_LE_DOM_MODE</code></dt>
0N/A * <dd>
0N/A * Day of week before day of month; e.g., Sunday on or before March 15.
0N/A * </dd>
0N/A * </dl>
0N/A * The setting of this field affects the interpretation of the
0N/A * <code>startDay</code> field.
0N/A * <p>If <code>useDaylight</code> is false, this value is ignored.
0N/A * @serial
0N/A * @since 1.1.4
0N/A */
0N/A private int startMode;
0N/A
0N/A /**
0N/A * Variables specifying the mode of the end rule. Takes the following
0N/A * values:
0N/A * <dl>
0N/A * <dt><code>DOM_MODE</code></dt>
0N/A * <dd>
0N/A * Exact day of week; e.g., March 1.
0N/A * </dd>
0N/A * <dt><code>DOW_IN_MONTH_MODE</code></dt>
0N/A * <dd>
0N/A * Day of week in month; e.g., last Sunday in March.
0N/A * </dd>
0N/A * <dt><code>DOW_GE_DOM_MODE</code></dt>
0N/A * <dd>
0N/A * Day of week after day of month; e.g., Sunday on or after March 15.
0N/A * </dd>
0N/A * <dt><code>DOW_LE_DOM_MODE</code></dt>
0N/A * <dd>
0N/A * Day of week before day of month; e.g., Sunday on or before March 15.
0N/A * </dd>
0N/A * </dl>
0N/A * The setting of this field affects the interpretation of the
0N/A * <code>endDay</code> field.
0N/A * <p>If <code>useDaylight</code> is false, this value is ignored.
0N/A * @serial
0N/A * @since 1.1.4
0N/A */
0N/A private int endMode;
0N/A
0N/A /**
0N/A * A positive value indicating the amount of time saved during DST in
0N/A * milliseconds.
0N/A * Typically one hour (3600000); sometimes 30 minutes (1800000).
0N/A * <p>If <code>useDaylight</code> is false, this value is ignored.
0N/A * @serial
0N/A * @since 1.1.4
0N/A */
0N/A private int dstSavings;
0N/A
0N/A private static final Gregorian gcal = CalendarSystem.getGregorianCalendar();
0N/A
0N/A /**
0N/A * Cache values representing a single period of daylight saving
0N/A * time. When the cache values are valid, cacheStart is the start
0N/A * time (inclusive) of daylight saving time and cacheEnd is the
0N/A * end time (exclusive).
0N/A *
0N/A * cacheYear has a year value if both cacheStart and cacheEnd are
0N/A * in the same year. cacheYear is set to startYear - 1 if
0N/A * cacheStart and cacheEnd are in different years. cacheStart is 0
0N/A * if the cache values are void. cacheYear is a long to support
0N/A * Integer.MIN_VALUE - 1 (JCK requirement).
0N/A */
0N/A private transient long cacheYear;
0N/A private transient long cacheStart;
0N/A private transient long cacheEnd;
0N/A
0N/A /**
0N/A * Constants specifying values of startMode and endMode.
0N/A */
0N/A private static final int DOM_MODE = 1; // Exact day of month, "Mar 1"
0N/A private static final int DOW_IN_MONTH_MODE = 2; // Day of week in month, "lastSun"
0N/A private static final int DOW_GE_DOM_MODE = 3; // Day of week after day of month, "Sun>=15"
0N/A private static final int DOW_LE_DOM_MODE = 4; // Day of week before day of month, "Sun<=21"
0N/A
0N/A /**
0N/A * Constant for a mode of start or end time specified as wall clock
0N/A * time. Wall clock time is standard time for the onset rule, and
0N/A * daylight time for the end rule.
0N/A * @since 1.4
0N/A */
0N/A public static final int WALL_TIME = 0; // Zero for backward compatibility
0N/A
0N/A /**
0N/A * Constant for a mode of start or end time specified as standard time.
0N/A * @since 1.4
0N/A */
0N/A public static final int STANDARD_TIME = 1;
0N/A
0N/A /**
0N/A * Constant for a mode of start or end time specified as UTC. European
0N/A * Union rules are specified as UTC time, for example.
0N/A * @since 1.4
0N/A */
0N/A public static final int UTC_TIME = 2;
0N/A
0N/A // Proclaim compatibility with 1.1
0N/A static final long serialVersionUID = -403250971215465050L;
0N/A
0N/A // the internal serial version which says which version was written
0N/A // - 0 (default) for version up to JDK 1.1.3
0N/A // - 1 for version from JDK 1.1.4, which includes 3 new fields
0N/A // - 2 for JDK 1.3, which includes 2 new fields
0N/A static final int currentSerialVersion = 2;
0N/A
0N/A /**
0N/A * The version of the serialized data on the stream. Possible values:
0N/A * <dl>
0N/A * <dt><b>0</b> or not present on stream</dt>
0N/A * <dd>
0N/A * JDK 1.1.3 or earlier.
0N/A * </dd>
0N/A * <dt><b>1</b></dt>
0N/A * <dd>
0N/A * JDK 1.1.4 or later. Includes three new fields: <code>startMode</code>,
0N/A * <code>endMode</code>, and <code>dstSavings</code>.
0N/A * </dd>
0N/A * <dt><b>2</b></dt>
0N/A * <dd>
0N/A * JDK 1.3 or later. Includes two new fields: <code>startTimeMode</code>
0N/A * and <code>endTimeMode</code>.
0N/A * </dd>
0N/A * </dl>
0N/A * When streaming out this class, the most recent format
0N/A * and the highest allowable <code>serialVersionOnStream</code>
0N/A * is written.
0N/A * @serial
0N/A * @since 1.1.4
0N/A */
0N/A private int serialVersionOnStream = currentSerialVersion;
0N/A
0N/A synchronized private void invalidateCache() {
0N/A cacheYear = startYear - 1;
0N/A cacheStart = cacheEnd = 0;
0N/A }
0N/A
0N/A //----------------------------------------------------------------------
0N/A // Rule representation
0N/A //
0N/A // We represent the following flavors of rules:
0N/A // 5 the fifth of the month
0N/A // lastSun the last Sunday in the month
0N/A // lastMon the last Monday in the month
0N/A // Sun>=8 first Sunday on or after the eighth
0N/A // Sun<=25 last Sunday on or before the 25th
0N/A // This is further complicated by the fact that we need to remain
0N/A // backward compatible with the 1.1 FCS. Finally, we need to minimize
0N/A // API changes. In order to satisfy these requirements, we support
0N/A // three representation systems, and we translate between them.
0N/A //
0N/A // INTERNAL REPRESENTATION
0N/A // This is the format SimpleTimeZone objects take after construction or
0N/A // streaming in is complete. Rules are represented directly, using an
0N/A // unencoded format. We will discuss the start rule only below; the end
0N/A // rule is analogous.
0N/A // startMode Takes on enumerated values DAY_OF_MONTH,
0N/A // DOW_IN_MONTH, DOW_AFTER_DOM, or DOW_BEFORE_DOM.
0N/A // startDay The day of the month, or for DOW_IN_MONTH mode, a
0N/A // value indicating which DOW, such as +1 for first,
0N/A // +2 for second, -1 for last, etc.
0N/A // startDayOfWeek The day of the week. Ignored for DAY_OF_MONTH.
0N/A //
0N/A // ENCODED REPRESENTATION
0N/A // This is the format accepted by the constructor and by setStartRule()
0N/A // and setEndRule(). It uses various combinations of positive, negative,
0N/A // and zero values to encode the different rules. This representation
0N/A // allows us to specify all the different rule flavors without altering
0N/A // the API.
0N/A // MODE startMonth startDay startDayOfWeek
0N/A // DOW_IN_MONTH_MODE >=0 !=0 >0
0N/A // DOM_MODE >=0 >0 ==0
0N/A // DOW_GE_DOM_MODE >=0 >0 <0
0N/A // DOW_LE_DOM_MODE >=0 <0 <0
0N/A // (no DST) don't care ==0 don't care
0N/A //
0N/A // STREAMED REPRESENTATION
0N/A // We must retain binary compatibility with the 1.1 FCS. The 1.1 code only
0N/A // handles DOW_IN_MONTH_MODE and non-DST mode, the latter indicated by the
0N/A // flag useDaylight. When we stream an object out, we translate into an
0N/A // approximate DOW_IN_MONTH_MODE representation so the object can be parsed
0N/A // and used by 1.1 code. Following that, we write out the full
0N/A // representation separately so that contemporary code can recognize and
0N/A // parse it. The full representation is written in a "packed" format,
0N/A // consisting of a version number, a length, and an array of bytes. Future
0N/A // versions of this class may specify different versions. If they wish to
0N/A // include additional data, they should do so by storing them after the
0N/A // packed representation below.
0N/A //----------------------------------------------------------------------
0N/A
0N/A /**
0N/A * Given a set of encoded rules in startDay and startDayOfMonth, decode
0N/A * them and set the startMode appropriately. Do the same for endDay and
0N/A * endDayOfMonth. Upon entry, the day of week variables may be zero or
0N/A * negative, in order to indicate special modes. The day of month
0N/A * variables may also be negative. Upon exit, the mode variables will be
0N/A * set, and the day of week and day of month variables will be positive.
0N/A * This method also recognizes a startDay or endDay of zero as indicating
0N/A * no DST.
0N/A */
0N/A private void decodeRules()
0N/A {
0N/A decodeStartRule();
0N/A decodeEndRule();
0N/A }
0N/A
0N/A /**
0N/A * Decode the start rule and validate the parameters. The parameters are
0N/A * expected to be in encoded form, which represents the various rule modes
0N/A * by negating or zeroing certain values. Representation formats are:
0N/A * <p>
0N/A * <pre>
0N/A * DOW_IN_MONTH DOM DOW>=DOM DOW<=DOM no DST
0N/A * ------------ ----- -------- -------- ----------
0N/A * month 0..11 same same same don't care
0N/A * day -5..5 1..31 1..31 -1..-31 0
0N/A * dayOfWeek 1..7 0 -1..-7 -1..-7 don't care
0N/A * time 0..ONEDAY same same same don't care
0N/A * </pre>
0N/A * The range for month does not include UNDECIMBER since this class is
0N/A * really specific to GregorianCalendar, which does not use that month.
0N/A * The range for time includes ONEDAY (vs. ending at ONEDAY-1) because the
0N/A * end rule is an exclusive limit point. That is, the range of times that
0N/A * are in DST include those >= the start and < the end. For this reason,
0N/A * it should be possible to specify an end of ONEDAY in order to include the
0N/A * entire day. Although this is equivalent to time 0 of the following day,
0N/A * it's not always possible to specify that, for example, on December 31.
0N/A * While arguably the start range should still be 0..ONEDAY-1, we keep
0N/A * the start and end ranges the same for consistency.
0N/A */
0N/A private void decodeStartRule() {
0N/A useDaylight = (startDay != 0) && (endDay != 0);
0N/A if (startDay != 0) {
0N/A if (startMonth < Calendar.JANUARY || startMonth > Calendar.DECEMBER) {
0N/A throw new IllegalArgumentException(
0N/A "Illegal start month " + startMonth);
0N/A }
1626N/A if (startTime < 0 || startTime > millisPerDay) {
0N/A throw new IllegalArgumentException(
0N/A "Illegal start time " + startTime);
0N/A }
0N/A if (startDayOfWeek == 0) {
0N/A startMode = DOM_MODE;
0N/A } else {
0N/A if (startDayOfWeek > 0) {
0N/A startMode = DOW_IN_MONTH_MODE;
0N/A } else {
0N/A startDayOfWeek = -startDayOfWeek;
0N/A if (startDay > 0) {
0N/A startMode = DOW_GE_DOM_MODE;
0N/A } else {
0N/A startDay = -startDay;
0N/A startMode = DOW_LE_DOM_MODE;
0N/A }
0N/A }
0N/A if (startDayOfWeek > Calendar.SATURDAY) {
0N/A throw new IllegalArgumentException(
0N/A "Illegal start day of week " + startDayOfWeek);
0N/A }
0N/A }
0N/A if (startMode == DOW_IN_MONTH_MODE) {
0N/A if (startDay < -5 || startDay > 5) {
0N/A throw new IllegalArgumentException(
0N/A "Illegal start day of week in month " + startDay);
0N/A }
0N/A } else if (startDay < 1 || startDay > staticMonthLength[startMonth]) {
0N/A throw new IllegalArgumentException(
0N/A "Illegal start day " + startDay);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Decode the end rule and validate the parameters. This method is exactly
0N/A * analogous to decodeStartRule().
0N/A * @see decodeStartRule
0N/A */
0N/A private void decodeEndRule() {
0N/A useDaylight = (startDay != 0) && (endDay != 0);
0N/A if (endDay != 0) {
0N/A if (endMonth < Calendar.JANUARY || endMonth > Calendar.DECEMBER) {
0N/A throw new IllegalArgumentException(
0N/A "Illegal end month " + endMonth);
0N/A }
1626N/A if (endTime < 0 || endTime > millisPerDay) {
0N/A throw new IllegalArgumentException(
0N/A "Illegal end time " + endTime);
0N/A }
0N/A if (endDayOfWeek == 0) {
0N/A endMode = DOM_MODE;
0N/A } else {
0N/A if (endDayOfWeek > 0) {
0N/A endMode = DOW_IN_MONTH_MODE;
0N/A } else {
0N/A endDayOfWeek = -endDayOfWeek;
0N/A if (endDay > 0) {
0N/A endMode = DOW_GE_DOM_MODE;
0N/A } else {
0N/A endDay = -endDay;
0N/A endMode = DOW_LE_DOM_MODE;
0N/A }
0N/A }
0N/A if (endDayOfWeek > Calendar.SATURDAY) {
0N/A throw new IllegalArgumentException(
0N/A "Illegal end day of week " + endDayOfWeek);
0N/A }
0N/A }
0N/A if (endMode == DOW_IN_MONTH_MODE) {
0N/A if (endDay < -5 || endDay > 5) {
0N/A throw new IllegalArgumentException(
0N/A "Illegal end day of week in month " + endDay);
0N/A }
0N/A } else if (endDay < 1 || endDay > staticMonthLength[endMonth]) {
0N/A throw new IllegalArgumentException(
0N/A "Illegal end day " + endDay);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Make rules compatible to 1.1 FCS code. Since 1.1 FCS code only understands
0N/A * day-of-week-in-month rules, we must modify other modes of rules to their
0N/A * approximate equivalent in 1.1 FCS terms. This method is used when streaming
0N/A * out objects of this class. After it is called, the rules will be modified,
0N/A * with a possible loss of information. startMode and endMode will NOT be
0N/A * altered, even though semantically they should be set to DOW_IN_MONTH_MODE,
0N/A * since the rule modification is only intended to be temporary.
0N/A */
0N/A private void makeRulesCompatible()
0N/A {
0N/A switch (startMode) {
0N/A case DOM_MODE:
0N/A startDay = 1 + (startDay / 7);
0N/A startDayOfWeek = Calendar.SUNDAY;
0N/A break;
0N/A
0N/A case DOW_GE_DOM_MODE:
0N/A // A day-of-month of 1 is equivalent to DOW_IN_MONTH_MODE
0N/A // that is, Sun>=1 == firstSun.
0N/A if (startDay != 1) {
0N/A startDay = 1 + (startDay / 7);
0N/A }
0N/A break;
0N/A
0N/A case DOW_LE_DOM_MODE:
0N/A if (startDay >= 30) {
0N/A startDay = -1;
0N/A } else {
0N/A startDay = 1 + (startDay / 7);
0N/A }
0N/A break;
0N/A }
0N/A
0N/A switch (endMode) {
0N/A case DOM_MODE:
0N/A endDay = 1 + (endDay / 7);
0N/A endDayOfWeek = Calendar.SUNDAY;
0N/A break;
0N/A
0N/A case DOW_GE_DOM_MODE:
0N/A // A day-of-month of 1 is equivalent to DOW_IN_MONTH_MODE
0N/A // that is, Sun>=1 == firstSun.
0N/A if (endDay != 1) {
0N/A endDay = 1 + (endDay / 7);
0N/A }
0N/A break;
0N/A
0N/A case DOW_LE_DOM_MODE:
0N/A if (endDay >= 30) {
0N/A endDay = -1;
0N/A } else {
0N/A endDay = 1 + (endDay / 7);
0N/A }
0N/A break;
0N/A }
0N/A
0N/A /*
0N/A * Adjust the start and end times to wall time. This works perfectly
0N/A * well unless it pushes into the next or previous day. If that
0N/A * happens, we attempt to adjust the day rule somewhat crudely. The day
0N/A * rules have been forced into DOW_IN_MONTH mode already, so we change
0N/A * the day of week to move forward or back by a day. It's possible to
0N/A * make a more refined adjustment of the original rules first, but in
0N/A * most cases this extra effort will go to waste once we adjust the day
0N/A * rules anyway.
0N/A */
0N/A switch (startTimeMode) {
0N/A case UTC_TIME:
0N/A startTime += rawOffset;
0N/A break;
0N/A }
0N/A while (startTime < 0) {
0N/A startTime += millisPerDay;
0N/A startDayOfWeek = 1 + ((startDayOfWeek+5) % 7); // Back 1 day
0N/A }
0N/A while (startTime >= millisPerDay) {
0N/A startTime -= millisPerDay;
0N/A startDayOfWeek = 1 + (startDayOfWeek % 7); // Forward 1 day
0N/A }
0N/A
0N/A switch (endTimeMode) {
0N/A case UTC_TIME:
0N/A endTime += rawOffset + dstSavings;
0N/A break;
0N/A case STANDARD_TIME:
0N/A endTime += dstSavings;
0N/A }
0N/A while (endTime < 0) {
0N/A endTime += millisPerDay;
0N/A endDayOfWeek = 1 + ((endDayOfWeek+5) % 7); // Back 1 day
0N/A }
0N/A while (endTime >= millisPerDay) {
0N/A endTime -= millisPerDay;
0N/A endDayOfWeek = 1 + (endDayOfWeek % 7); // Forward 1 day
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Pack the start and end rules into an array of bytes. Only pack
0N/A * data which is not preserved by makeRulesCompatible.
0N/A */
0N/A private byte[] packRules()
0N/A {
0N/A byte[] rules = new byte[6];
0N/A rules[0] = (byte)startDay;
0N/A rules[1] = (byte)startDayOfWeek;
0N/A rules[2] = (byte)endDay;
0N/A rules[3] = (byte)endDayOfWeek;
0N/A
0N/A // As of serial version 2, include time modes
0N/A rules[4] = (byte)startTimeMode;
0N/A rules[5] = (byte)endTimeMode;
0N/A
0N/A return rules;
0N/A }
0N/A
0N/A /**
0N/A * Given an array of bytes produced by packRules, interpret them
0N/A * as the start and end rules.
0N/A */
0N/A private void unpackRules(byte[] rules)
0N/A {
0N/A startDay = rules[0];
0N/A startDayOfWeek = rules[1];
0N/A endDay = rules[2];
0N/A endDayOfWeek = rules[3];
0N/A
0N/A // As of serial version 2, include time modes
0N/A if (rules.length >= 6) {
0N/A startTimeMode = rules[4];
0N/A endTimeMode = rules[5];
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Pack the start and end times into an array of bytes. This is required
0N/A * as of serial version 2.
0N/A */
0N/A private int[] packTimes() {
0N/A int[] times = new int[2];
0N/A times[0] = startTime;
0N/A times[1] = endTime;
0N/A return times;
0N/A }
0N/A
0N/A /**
0N/A * Unpack the start and end times from an array of bytes. This is required
0N/A * as of serial version 2.
0N/A */
0N/A private void unpackTimes(int[] times) {
0N/A startTime = times[0];
0N/A endTime = times[1];
0N/A }
0N/A
0N/A /**
0N/A * Save the state of this object to a stream (i.e., serialize it).
0N/A *
0N/A * @serialData We write out two formats, a JDK 1.1 compatible format, using
0N/A * <code>DOW_IN_MONTH_MODE</code> rules, in the required section, followed
0N/A * by the full rules, in packed format, in the optional section. The
0N/A * optional section will be ignored by JDK 1.1 code upon stream in.
0N/A * <p> Contents of the optional section: The length of a byte array is
0N/A * emitted (int); this is 4 as of this release. The byte array of the given
0N/A * length is emitted. The contents of the byte array are the true values of
0N/A * the fields <code>startDay</code>, <code>startDayOfWeek</code>,
0N/A * <code>endDay</code>, and <code>endDayOfWeek</code>. The values of these
0N/A * fields in the required section are approximate values suited to the rule
0N/A * mode <code>DOW_IN_MONTH_MODE</code>, which is the only mode recognized by
0N/A * JDK 1.1.
0N/A */
0N/A private void writeObject(ObjectOutputStream stream)
0N/A throws IOException
0N/A {
0N/A // Construct a binary rule
0N/A byte[] rules = packRules();
0N/A int[] times = packTimes();
0N/A
0N/A // Convert to 1.1 FCS rules. This step may cause us to lose information.
0N/A makeRulesCompatible();
0N/A
0N/A // Write out the 1.1 FCS rules
0N/A stream.defaultWriteObject();
0N/A
0N/A // Write out the binary rules in the optional data area of the stream.
0N/A stream.writeInt(rules.length);
0N/A stream.write(rules);
0N/A stream.writeObject(times);
0N/A
0N/A // Recover the original rules. This recovers the information lost
0N/A // by makeRulesCompatible.
0N/A unpackRules(rules);
0N/A unpackTimes(times);
0N/A }
0N/A
0N/A /**
0N/A * Reconstitute this object from a stream (i.e., deserialize it).
0N/A *
0N/A * We handle both JDK 1.1
0N/A * binary formats and full formats with a packed byte array.
0N/A */
0N/A private void readObject(ObjectInputStream stream)
0N/A throws IOException, ClassNotFoundException
0N/A {
0N/A stream.defaultReadObject();
0N/A
0N/A if (serialVersionOnStream < 1) {
0N/A // Fix a bug in the 1.1 SimpleTimeZone code -- namely,
0N/A // startDayOfWeek and endDayOfWeek were usually uninitialized. We can't do
0N/A // too much, so we assume SUNDAY, which actually works most of the time.
0N/A if (startDayOfWeek == 0) {
0N/A startDayOfWeek = Calendar.SUNDAY;
0N/A }
0N/A if (endDayOfWeek == 0) {
0N/A endDayOfWeek = Calendar.SUNDAY;
0N/A }
0N/A
0N/A // The variables dstSavings, startMode, and endMode are post-1.1, so they
0N/A // won't be present if we're reading from a 1.1 stream. Fix them up.
0N/A startMode = endMode = DOW_IN_MONTH_MODE;
0N/A dstSavings = millisPerHour;
0N/A } else {
0N/A // For 1.1.4, in addition to the 3 new instance variables, we also
0N/A // store the actual rules (which have not be made compatible with 1.1)
0N/A // in the optional area. Read them in here and parse them.
0N/A int length = stream.readInt();
0N/A byte[] rules = new byte[length];
0N/A stream.readFully(rules);
0N/A unpackRules(rules);
0N/A }
0N/A
0N/A if (serialVersionOnStream >= 2) {
0N/A int[] times = (int[]) stream.readObject();
0N/A unpackTimes(times);
0N/A }
0N/A
0N/A serialVersionOnStream = currentSerialVersion;
0N/A }
0N/A}