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 * 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 * 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 * 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. 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 0N/A * (C) Copyright Taligent, Inc. 1996 - All Rights Reserved 0N/A * (C) Copyright IBM Corp. 1996 - All Rights Reserved 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 * <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 * 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 * <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 * <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 * <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 * <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 * 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 * 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 * The following are examples of parameters for constructing time zone objects. 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 * SimpleTimeZone(-28800000, 0N/A * Calendar.APRIL, 1, -Calendar.SUNDAY, 0N/A * Calendar.OCTOBER, -1, Calendar.SUNDAY, 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 * SimpleTimeZone(3600000, 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 * These parameter rules are also applicable to the set rule methods, such as 0N/A * <code>setStartRule</code>. 0N/A * @see GregorianCalendar 0N/A * @author David Goldsmith, Mark Davis, Chen-Lieh Huang, Alan Liu 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 * @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 * 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 * 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 * SimpleTimeZone(rawOffset, 0N/A * SimpleTimeZone.{@link #WALL_TIME}, 0N/A * SimpleTimeZone.{@link #WALL_TIME}, 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 * @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 * 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 * 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 * SimpleTimeZone(rawOffset, 0N/A * SimpleTimeZone.{@link #WALL_TIME}, 0N/A * SimpleTimeZone.{@link #WALL_TIME}, 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 * 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 * 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 * @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 * @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 * @see #STANDARD_TIME 0N/A // this.useDaylight is set by decodeRules 0N/A * Sets the daylight saving time starting year. 0N/A * @param year The daylight saving starting year. 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 * @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 * 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 * @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 * 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 * @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 // TODO: this method doesn't check the initial values of dayOfMonth or dayOfWeek. 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 * @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 * 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 * @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 * 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 * @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 * 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 * @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 * @see TimeZone#getOffsets 0N/A synchronized (
this) {
0N/A // Get the year in local time 0N/A // Clear time elements for the transition calculations 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 * <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 * @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 * @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 // adjust y with the GregorianCalendar-style year numbering. 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 // convert year to its 1-based month value 0N/A // First, calculate time as a Gregorian date. 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 // The validation should be cdate.getDayOfWeek() == 0N/A // dayOfWeek. However, we don't check dayOfWeek for 0N/A synchronized (
this) {
0N/A synchronized (
this) {
0N/A // TODO: support Gregorian cutover. The previous year 0N/A // may be in the other calendar system. 0N/A // TODO: support Gregorian cutover. The next year 0N/A // may be in the other calendar system. 0N/A synchronized (
this) {
0N/A // The start and end transitions are in multiple years. 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 // The given date will be taken into account while 0N/A // we have the historical time zone data in place. 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 * 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 * Returns the amount of time in milliseconds that the clock is 0N/A * advanced during daylight saving time. 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 * @see #setDSTSavings 0N/A * Queries if this time zone uses daylight saving time. 0N/A * @return true if this time zone uses daylight saving time; 3558N/A * Returns {@code true} if this {@code SimpleTimeZone} observes 3558N/A * Daylight Saving Time. This method is equivalent to {@link 3558N/A * @return {@code true} if this {@code SimpleTimeZone} observes 3558N/A * Daylight Saving Time; {@code false} otherwise. 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 * Returns a clone of this <code>SimpleTimeZone</code> instance. 0N/A * @return a clone of this instance. 0N/A * Generates the hash code for the SimpleDateFormat object. 0N/A * @return the hash code for this object 0N/A * Compares the equality of two <code>SimpleTimeZone</code> objects. 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 * 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 // Only check rules if using DST 0N/A * Returns a string representation of this time zone. 0N/A * @return a string representation of this time zone. 0N/A // =======================privates=============================== 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 * This field has two possible interpretations: 0N/A * <dt><code>startMode == DOW_IN_MONTH</code></dt> 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 * <dt><code>startMode != DOW_IN_MONTH</code></dt> 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 * <p>If <code>useDaylight</code> is false, this value is ignored. 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 * 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 * The format of startTime, either WALL_TIME, STANDARD_TIME, or UTC_TIME. 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 * This field has two possible interpretations: 0N/A * <dt><code>endMode == DOW_IN_MONTH</code></dt> 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 * <dt><code>endMode != DOW_IN_MONTH</code></dt> 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 * <p>If <code>useDaylight</code> is false, this value is ignored. 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 * 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 * The format of endTime, either <code>WALL_TIME</code>, 0N/A * <code>STANDARD_TIME</code>, or <code>UTC_TIME</code>. 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 * 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 * 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 private boolean useDaylight=
false;
// indicate if this time zone uses DST 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 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 * Variables specifying the mode of the start rule. Takes the following 0N/A * <dt><code>DOM_MODE</code></dt> 0N/A * Exact day of week; e.g., March 1. 0N/A * <dt><code>DOW_IN_MONTH_MODE</code></dt> 0N/A * Day of week in month; e.g., last Sunday in March. 0N/A * <dt><code>DOW_GE_DOM_MODE</code></dt> 0N/A * Day of week after day of month; e.g., Sunday on or after March 15. 0N/A * <dt><code>DOW_LE_DOM_MODE</code></dt> 0N/A * Day of week before day of month; e.g., Sunday on or before March 15. 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 * Variables specifying the mode of the end rule. Takes the following 0N/A * <dt><code>DOM_MODE</code></dt> 0N/A * Exact day of week; e.g., March 1. 0N/A * <dt><code>DOW_IN_MONTH_MODE</code></dt> 0N/A * Day of week in month; e.g., last Sunday in March. 0N/A * <dt><code>DOW_GE_DOM_MODE</code></dt> 0N/A * Day of week after day of month; e.g., Sunday on or after March 15. 0N/A * <dt><code>DOW_LE_DOM_MODE</code></dt> 0N/A * Day of week before day of month; e.g., Sunday on or before March 15. 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 * A positive value indicating the amount of time saved during DST in 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 * 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 * 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 * Constants specifying values of startMode and endMode. 0N/A private static final int DOM_MODE =
1;
// Exact day of month, "Mar 1" 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 * 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 public static final int WALL_TIME =
0;
// Zero for backward compatibility 0N/A * Constant for a mode of start or end time specified as standard time. 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 // Proclaim compatibility with 1.1 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 * The version of the serialized data on the stream. Possible values: 0N/A * <dt><b>0</b> or not present on stream</dt> 0N/A * JDK 1.1.3 or earlier. 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 * JDK 1.3 or later. Includes two new fields: <code>startTimeMode</code> 0N/A * and <code>endTimeMode</code>. 0N/A * When streaming out this class, the most recent format 0N/A * and the highest allowable <code>serialVersionOnStream</code> 0N/A //---------------------------------------------------------------------- 0N/A // Rule representation 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 // 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 // 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 // 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 // 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 * 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 * 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 * 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 * 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 * Decode the end rule and validate the parameters. This method is exactly 0N/A * analogous to decodeStartRule(). 0N/A * @see decodeStartRule 0N/A "Illegal end day of week in month " +
endDay);
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 // A day-of-month of 1 is equivalent to DOW_IN_MONTH_MODE 0N/A // that is, Sun>=1 == firstSun. 0N/A // A day-of-month of 1 is equivalent to DOW_IN_MONTH_MODE 0N/A // that is, Sun>=1 == firstSun. 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 * Pack the start and end rules into an array of bytes. Only pack 0N/A * data which is not preserved by makeRulesCompatible. 0N/A // As of serial version 2, include time modes 0N/A * Given an array of bytes produced by packRules, interpret them 0N/A * as the start and end rules. 0N/A // As of serial version 2, include time modes 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 * Unpack the start and end times from an array of bytes. This is required 0N/A * as of serial version 2. 0N/A * Save the state of this object to a stream (i.e., serialize it). 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 // Construct a binary rule 0N/A // Convert to 1.1 FCS rules. This step may cause us to lose information. 0N/A // Write out the 1.1 FCS rules 0N/A // Write out the binary rules in the optional data area of the stream. 0N/A // Recover the original rules. This recovers the information lost 0N/A // by makeRulesCompatible. 0N/A * Reconstitute this object from a stream (i.e., deserialize it). 0N/A * We handle both JDK 1.1 0N/A * binary formats and full formats with a packed byte array. 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 // 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 // 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.