src/java.base/share/classes/java/util/SimpleTimeZone.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58288 48e480e56aad
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
53563
a4b7ea85d668 8218022: Repeated words typos in java.base
prappo
parents: 48239
diff changeset
     2
 * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3738
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3738
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3738
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3738
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3738
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * (C) Copyright Taligent, Inc. 1996 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * (C) Copyright IBM Corp. 1996 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *   The original version of this source code and documentation is copyrighted
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * materials are provided under terms of a License Agreement between Taligent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * and Sun. This technology is protected by multiple US and International
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * patents. This notice and attribution to Taligent may not be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *   Taligent is a registered trademark of Taligent, Inc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
package java.util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.io.IOException;
47414
3448b80444f3 8181323: Better timezone processing
naoto
parents: 47216
diff changeset
    44
import java.io.InvalidObjectException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import sun.util.calendar.CalendarSystem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import sun.util.calendar.CalendarUtils;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import sun.util.calendar.BaseCalendar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import sun.util.calendar.Gregorian;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
/**
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
    51
 * {@code SimpleTimeZone} is a concrete subclass of {@code TimeZone}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * that represents a time zone for use with a Gregorian calendar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * The class holds an offset from GMT, called <em>raw offset</em>, and start
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * and end rules for a daylight saving time schedule.  Since it only holds
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * single values for each, it cannot handle historical changes in the offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * from GMT and the daylight saving schedule, except that the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * #setStartYear setStartYear} method can specify the year when the daylight
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * saving time schedule starts in effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <p>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
    60
 * To construct a {@code SimpleTimeZone} with a daylight saving time
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * schedule, the schedule can be described with a set of rules,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <em>start-rule</em> and <em>end-rule</em>. A day when daylight saving time
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * starts or ends is specified by a combination of <em>month</em>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <em>day-of-month</em>, and <em>day-of-week</em> values. The <em>month</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * value is represented by a Calendar {@link Calendar#MONTH MONTH} field
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * value, such as {@link Calendar#MARCH}. The <em>day-of-week</em> value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * represented by a Calendar {@link Calendar#DAY_OF_WEEK DAY_OF_WEEK} value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * such as {@link Calendar#SUNDAY SUNDAY}. The meanings of value combinations
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * are as follows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <li><b>Exact day of month</b><br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * To specify an exact day of month, set the <em>month</em> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <em>day-of-month</em> to an exact value, and <em>day-of-week</em> to zero. For
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * example, to specify March 1, set the <em>month</em> to {@link Calendar#MARCH
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * MARCH}, <em>day-of-month</em> to 1, and <em>day-of-week</em> to 0.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * <li><b>Day of week on or after day of month</b><br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * To specify a day of week on or after an exact day of month, set the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * <em>month</em> to an exact month value, <em>day-of-month</em> to the day on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * or after which the rule is applied, and <em>day-of-week</em> to a negative {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * Calendar#DAY_OF_WEEK DAY_OF_WEEK} field value. For example, to specify the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * second Sunday of April, set <em>month</em> to {@link Calendar#APRIL APRIL},
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
    84
 * <em>day-of-month</em> to 8, and <em>day-of-week</em> to {@code -}{@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * Calendar#SUNDAY SUNDAY}.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * <li><b>Day of week on or before day of month</b><br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * To specify a day of the week on or before an exact day of the month, set
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * <em>day-of-month</em> and <em>day-of-week</em> to a negative value. For
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * example, to specify the last Wednesday on or before the 21st of March, set
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * <em>month</em> to {@link Calendar#MARCH MARCH}, <em>day-of-month</em> is -21
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
    92
 * and <em>day-of-week</em> is {@code -}{@link Calendar#WEDNESDAY WEDNESDAY}. </li>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * <li><b>Last day-of-week of month</b><br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * To specify, the last day-of-week of the month, set <em>day-of-week</em> to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * {@link Calendar#DAY_OF_WEEK DAY_OF_WEEK} value and <em>day-of-month</em> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * -1. For example, to specify the last Sunday of October, set <em>month</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * to {@link Calendar#OCTOBER OCTOBER}, <em>day-of-week</em> to {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * Calendar#SUNDAY SUNDAY} and <em>day-of-month</em> to -1.  </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * The time of the day at which daylight saving time starts or ends is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * specified by a millisecond value within the day. There are three kinds of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * <em>mode</em>s to specify the time: {@link #WALL_TIME}, {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * #STANDARD_TIME} and {@link #UTC_TIME}. For example, if daylight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * saving time ends
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * at 2:00 am in the wall clock time, it can be specified by 7200000
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * milliseconds in the {@link #WALL_TIME} mode. In this case, the wall clock time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * for an <em>end-rule</em> means the same thing as the daylight time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * The following are examples of parameters for constructing time zone objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * <pre><code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 *      // Base GMT offset: -8:00
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 *      // DST starts:      at 2:00am in standard time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 *      //                  on the first Sunday in April
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 *      // DST ends:        at 2:00am in daylight time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 *      //                  on the last Sunday in October
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 *      // Save:            1 hour
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 *      SimpleTimeZone(-28800000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 *                     "America/Los_Angeles",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 *                     Calendar.APRIL, 1, -Calendar.SUNDAY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 *                     7200000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 *                     Calendar.OCTOBER, -1, Calendar.SUNDAY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 *                     7200000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 *                     3600000)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 *      // Base GMT offset: +1:00
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 *      // DST starts:      at 1:00am in UTC time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 *      //                  on the last Sunday in March
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 *      // DST ends:        at 1:00am in UTC time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 *      //                  on the last Sunday in October
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 *      // Save:            1 hour
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 *      SimpleTimeZone(3600000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 *                     "Europe/Paris",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 *                     Calendar.MARCH, -1, Calendar.SUNDAY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 *                     3600000, SimpleTimeZone.UTC_TIME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 *                     Calendar.OCTOBER, -1, Calendar.SUNDAY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 *                     3600000, SimpleTimeZone.UTC_TIME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 *                     3600000)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * </code></pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * These parameter rules are also applicable to the set rule methods, such as
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   142
 * {@code setStartRule}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * @since 1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * @see      Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * @see      GregorianCalendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * @see      TimeZone
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * @author   David Goldsmith, Mark Davis, Chen-Lieh Huang, Alan Liu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
public class SimpleTimeZone extends TimeZone {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * Constructs a SimpleTimeZone with the given base time zone offset from GMT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * and time zone ID with no daylight saving time schedule.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @param rawOffset  The base time zone offset in milliseconds to GMT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @param ID         The time zone name that is given to this instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    public SimpleTimeZone(int rawOffset, String ID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        this.rawOffset = rawOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        setID (ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        dstSavings = millisPerHour; // In case user sets rules later
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Constructs a SimpleTimeZone with the given base time zone offset from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * GMT, time zone ID, and rules for starting and ending the daylight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * time.
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   170
     * Both {@code startTime} and {@code endTime} are specified to be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * represented in the wall clock time. The amount of daylight saving is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * assumed to be 3600000 milliseconds (i.e., one hour). This constructor is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * equivalent to:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * <pre><code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *     SimpleTimeZone(rawOffset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *                    ID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *                    startMonth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *                    startDay,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *                    startDayOfWeek,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *                    startTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *                    SimpleTimeZone.{@link #WALL_TIME},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *                    endMonth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *                    endDay,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *                    endDayOfWeek,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *                    endTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *                    SimpleTimeZone.{@link #WALL_TIME},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *                    3600000)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * </code></pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @param rawOffset       The given base time zone offset from GMT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @param ID              The time zone ID which is given to this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @param startMonth      The daylight saving time starting month. Month is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *                        a {@link Calendar#MONTH MONTH} field value (0-based. e.g., 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *                        for January).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @param startDay        The day of the month on which the daylight saving time starts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *                        See the class description for the special cases of this parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @param startDayOfWeek  The daylight saving time starting day-of-week.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *                        See the class description for the special cases of this parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @param startTime       The daylight saving time starting time in local wall clock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *                        time (in milliseconds within the day), which is local
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *                        standard time in this case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @param endMonth        The daylight saving time ending month. Month is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *                        a {@link Calendar#MONTH MONTH} field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *                        value (0-based. e.g., 9 for October).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @param endDay          The day of the month on which the daylight saving time ends.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     *                        See the class description for the special cases of this parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * @param endDayOfWeek    The daylight saving time ending day-of-week.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *                        See the class description for the special cases of this parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @param endTime         The daylight saving ending time in local wall clock time,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *                        (in milliseconds within the day) which is local daylight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *                        time in this case.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   212
     * @throws    IllegalArgumentException if the month, day, dayOfWeek, or time
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * parameters are out of range for the start or end rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    public SimpleTimeZone(int rawOffset, String ID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                          int startMonth, int startDay, int startDayOfWeek, int startTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                          int endMonth, int endDay, int endDayOfWeek, int endTime)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        this(rawOffset, ID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
             startMonth, startDay, startDayOfWeek, startTime, WALL_TIME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
             endMonth, endDay, endDayOfWeek, endTime, WALL_TIME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
             millisPerHour);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * Constructs a SimpleTimeZone with the given base time zone offset from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * GMT, time zone ID, and rules for starting and ending the daylight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * time.
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   229
     * Both {@code startTime} and {@code endTime} are assumed to be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * represented in the wall clock time. This constructor is equivalent to:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * <pre><code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *     SimpleTimeZone(rawOffset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *                    ID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *                    startMonth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *                    startDay,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *                    startDayOfWeek,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *                    startTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *                    SimpleTimeZone.{@link #WALL_TIME},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *                    endMonth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *                    endDay,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *                    endDayOfWeek,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *                    endTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *                    SimpleTimeZone.{@link #WALL_TIME},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *                    dstSavings)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * </code></pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @param rawOffset       The given base time zone offset from GMT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @param ID              The time zone ID which is given to this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @param startMonth      The daylight saving time starting month. Month is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     *                        a {@link Calendar#MONTH MONTH} field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     *                        value (0-based. e.g., 0 for January).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @param startDay        The day of the month on which the daylight saving time starts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *                        See the class description for the special cases of this parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @param startDayOfWeek  The daylight saving time starting day-of-week.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *                        See the class description for the special cases of this parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @param startTime       The daylight saving time starting time in local wall clock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *                        time, which is local standard time in this case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @param endMonth        The daylight saving time ending month. Month is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *                        a {@link Calendar#MONTH MONTH} field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *                        value (0-based. e.g., 9 for October).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @param endDay          The day of the month on which the daylight saving time ends.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *                        See the class description for the special cases of this parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @param endDayOfWeek    The daylight saving time ending day-of-week.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *                        See the class description for the special cases of this parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @param endTime         The daylight saving ending time in local wall clock time,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *                        which is local daylight time in this case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @param dstSavings      The amount of time in milliseconds saved during
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *                        daylight saving time.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   269
     * @throws    IllegalArgumentException if the month, day, dayOfWeek, or time
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * parameters are out of range for the start or end rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    public SimpleTimeZone(int rawOffset, String ID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                          int startMonth, int startDay, int startDayOfWeek, int startTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                          int endMonth, int endDay, int endDayOfWeek, int endTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                          int dstSavings)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        this(rawOffset, ID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
             startMonth, startDay, startDayOfWeek, startTime, WALL_TIME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
             endMonth, endDay, endDayOfWeek, endTime, WALL_TIME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
             dstSavings);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * Constructs a SimpleTimeZone with the given base time zone offset from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * GMT, time zone ID, and rules for starting and ending the daylight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * This constructor takes the full set of the start and end rules
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   289
     * parameters, including modes of {@code startTime} and
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   290
     * {@code endTime}. The mode specifies either {@link #WALL_TIME wall
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * time} or {@link #STANDARD_TIME standard time} or {@link #UTC_TIME UTC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * time}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * @param rawOffset       The given base time zone offset from GMT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @param ID              The time zone ID which is given to this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * @param startMonth      The daylight saving time starting month. Month is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     *                        a {@link Calendar#MONTH MONTH} field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     *                        value (0-based. e.g., 0 for January).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @param startDay        The day of the month on which the daylight saving time starts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     *                        See the class description for the special cases of this parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @param startDayOfWeek  The daylight saving time starting day-of-week.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *                        See the class description for the special cases of this parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @param startTime       The daylight saving time starting time in the time mode
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   304
     *                        specified by {@code startTimeMode}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @param startTimeMode   The mode of the start time specified by startTime.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @param endMonth        The daylight saving time ending month. Month is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *                        a {@link Calendar#MONTH MONTH} field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *                        value (0-based. e.g., 9 for October).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @param endDay          The day of the month on which the daylight saving time ends.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *                        See the class description for the special cases of this parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @param endDayOfWeek    The daylight saving time ending day-of-week.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     *                        See the class description for the special cases of this parameter.
53563
a4b7ea85d668 8218022: Repeated words typos in java.base
prappo
parents: 48239
diff changeset
   313
     * @param endTime         The daylight saving ending time in time mode
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   314
     *                        specified by {@code endTimeMode}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * @param endTimeMode     The mode of the end time specified by endTime
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * @param dstSavings      The amount of time in milliseconds saved during
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     *                        daylight saving time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   319
     * @throws    IllegalArgumentException if the month, day, dayOfWeek, time more, or
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * time parameters are out of range for the start or end rule, or if a time mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * value is invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @see #WALL_TIME
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @see #STANDARD_TIME
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * @see #UTC_TIME
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    public SimpleTimeZone(int rawOffset, String ID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                          int startMonth, int startDay, int startDayOfWeek,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                          int startTime, int startTimeMode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                          int endMonth, int endDay, int endDayOfWeek,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                          int endTime, int endTimeMode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                          int dstSavings) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        setID(ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        this.rawOffset      = rawOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        this.startMonth     = startMonth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        this.startDay       = startDay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        this.startDayOfWeek = startDayOfWeek;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        this.startTime      = startTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        this.startTimeMode  = startTimeMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        this.endMonth       = endMonth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        this.endDay         = endDay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        this.endDayOfWeek   = endDayOfWeek;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        this.endTime        = endTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        this.endTimeMode    = endTimeMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        this.dstSavings     = dstSavings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        // this.useDaylight is set by decodeRules
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        decodeRules();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        if (dstSavings <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            throw new IllegalArgumentException("Illegal daylight saving value: " + dstSavings);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * Sets the daylight saving time starting year.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * @param year  The daylight saving starting year.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    public void setStartYear(int year)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        startYear = year;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        invalidateCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * Sets the daylight saving time start rule. For example, if daylight saving
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * time starts on the first Sunday in April at 2 am in local wall clock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * time, you can set the start rule by calling:
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   372
     * <pre>{@code setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2*60*60*1000);}</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * @param startMonth      The daylight saving time starting month. Month is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     *                        a {@link Calendar#MONTH MONTH} field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     *                        value (0-based. e.g., 0 for January).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * @param startDay        The day of the month on which the daylight saving time starts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     *                        See the class description for the special cases of this parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * @param startDayOfWeek  The daylight saving time starting day-of-week.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     *                        See the class description for the special cases of this parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * @param startTime       The daylight saving time starting time in local wall clock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     *                        time, which is local standard time in this case.
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   383
     * @throws    IllegalArgumentException if the {@code startMonth}, {@code startDay},
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   384
     * {@code startDayOfWeek}, or {@code startTime} parameters are out of range
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    public void setStartRule(int startMonth, int startDay, int startDayOfWeek, int startTime)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        this.startMonth = startMonth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        this.startDay = startDay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        this.startDayOfWeek = startDayOfWeek;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        this.startTime = startTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        startTimeMode = WALL_TIME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        decodeStartRule();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        invalidateCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * Sets the daylight saving time start rule to a fixed date within a month.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * This method is equivalent to:
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   400
     * <pre>{@code setStartRule(startMonth, startDay, 0, startTime)}</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * @param startMonth      The daylight saving time starting month. Month is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     *                        a {@link Calendar#MONTH MONTH} field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     *                        value (0-based. e.g., 0 for January).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * @param startDay        The day of the month on which the daylight saving time starts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * @param startTime       The daylight saving time starting time in local wall clock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     *                        time, which is local standard time in this case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     *                        See the class description for the special cases of this parameter.
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   409
     * @throws    IllegalArgumentException if the {@code startMonth},
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   410
     * {@code startDayOfMonth}, or {@code startTime} parameters are out of range
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    public void setStartRule(int startMonth, int startDay, int startTime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        setStartRule(startMonth, startDay, 0, startTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * Sets the daylight saving time start rule to a weekday before or after the given date within
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * a month, e.g., the first Monday on or after the 8th.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @param startMonth      The daylight saving time starting month. Month is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     *                        a {@link Calendar#MONTH MONTH} field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     *                        value (0-based. e.g., 0 for January).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * @param startDay        The day of the month on which the daylight saving time starts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * @param startDayOfWeek  The daylight saving time starting day-of-week.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * @param startTime       The daylight saving time starting time in local wall clock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     *                        time, which is local standard time in this case.
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   428
     * @param after           If true, this rule selects the first {@code dayOfWeek} on or
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   429
     *                        <em>after</em> {@code dayOfMonth}.  If false, this rule
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   430
     *                        selects the last {@code dayOfWeek} on or <em>before</em>
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   431
     *                        {@code dayOfMonth}.
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   432
     * @throws    IllegalArgumentException if the {@code startMonth}, {@code startDay},
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   433
     * {@code startDayOfWeek}, or {@code startTime} parameters are out of range
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    public void setStartRule(int startMonth, int startDay, int startDayOfWeek,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                             int startTime, boolean after)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        // TODO: this method doesn't check the initial values of dayOfMonth or dayOfWeek.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        if (after) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            setStartRule(startMonth, startDay, -startDayOfWeek, startTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            setStartRule(startMonth, -startDay, -startDayOfWeek, startTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * Sets the daylight saving time end rule. For example, if daylight saving time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * ends on the last Sunday in October at 2 am in wall clock time,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * you can set the end rule by calling:
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   451
     * {@code setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2*60*60*1000);}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * @param endMonth        The daylight saving time ending month. Month is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     *                        a {@link Calendar#MONTH MONTH} field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     *                        value (0-based. e.g., 9 for October).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * @param endDay          The day of the month on which the daylight saving time ends.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     *                        See the class description for the special cases of this parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * @param endDayOfWeek    The daylight saving time ending day-of-week.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     *                        See the class description for the special cases of this parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * @param endTime         The daylight saving ending time in local wall clock time,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     *                        (in milliseconds within the day) which is local daylight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     *                        time in this case.
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   463
     * @throws    IllegalArgumentException if the {@code endMonth}, {@code endDay},
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   464
     * {@code endDayOfWeek}, or {@code endTime} parameters are out of range
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    public void setEndRule(int endMonth, int endDay, int endDayOfWeek,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                           int endTime)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        this.endMonth = endMonth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        this.endDay = endDay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        this.endDayOfWeek = endDayOfWeek;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        this.endTime = endTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        this.endTimeMode = WALL_TIME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        decodeEndRule();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        invalidateCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * Sets the daylight saving time end rule to a fixed date within a month.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * This method is equivalent to:
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   481
     * <pre>{@code setEndRule(endMonth, endDay, 0, endTime)}</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * @param endMonth        The daylight saving time ending month. Month is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     *                        a {@link Calendar#MONTH MONTH} field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     *                        value (0-based. e.g., 9 for October).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * @param endDay          The day of the month on which the daylight saving time ends.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * @param endTime         The daylight saving ending time in local wall clock time,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     *                        (in milliseconds within the day) which is local daylight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     *                        time in this case.
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   490
     * @throws    IllegalArgumentException the {@code endMonth}, {@code endDay},
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   491
     * or {@code endTime} parameters are out of range
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    public void setEndRule(int endMonth, int endDay, int endTime)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        setEndRule(endMonth, endDay, 0, endTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * Sets the daylight saving time end rule to a weekday before or after the given date within
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * a month, e.g., the first Monday on or after the 8th.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * @param endMonth        The daylight saving time ending month. Month is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     *                        a {@link Calendar#MONTH MONTH} field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     *                        value (0-based. e.g., 9 for October).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * @param endDay          The day of the month on which the daylight saving time ends.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * @param endDayOfWeek    The daylight saving time ending day-of-week.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * @param endTime         The daylight saving ending time in local wall clock time,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     *                        (in milliseconds within the day) which is local daylight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     *                        time in this case.
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   511
     * @param after           If true, this rule selects the first {@code endDayOfWeek} on
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   512
     *                        or <em>after</em> {@code endDay}.  If false, this rule
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   513
     *                        selects the last {@code endDayOfWeek} on or before
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   514
     *                        {@code endDay} of the month.
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   515
     * @throws    IllegalArgumentException the {@code endMonth}, {@code endDay},
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   516
     * {@code endDayOfWeek}, or {@code endTime} parameters are out of range
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    public void setEndRule(int endMonth, int endDay, int endDayOfWeek, int endTime, boolean after)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        if (after) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            setEndRule(endMonth, endDay, -endDayOfWeek, endTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            setEndRule(endMonth, -endDay, -endDayOfWeek, endTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * Returns the offset of this time zone from UTC at the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * time. If daylight saving time is in effect at the given time,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * the offset value is adjusted with the amount of daylight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * saving.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * @param date the time at which the time zone offset is found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * @return the amount of time in milliseconds to add to UTC to get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * local time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    public int getOffset(long date) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        return getOffsets(date, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * @see TimeZone#getOffsets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    int getOffsets(long date, int[] offsets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        int offset = rawOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
      computeOffset:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        if (useDaylight) {
48239
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
   551
            Cache cache = this.cache;
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
   552
            if (cache != null) {
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
   553
                if (date >= cache.start && date < cache.end) {
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
   554
                    offset += dstSavings;
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
   555
                    break computeOffset;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            BaseCalendar cal = date >= GregorianCalendar.DEFAULT_GREGORIAN_CUTOVER ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                gcal : (BaseCalendar) CalendarSystem.forName("julian");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            BaseCalendar.Date cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            // Get the year in local time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            cal.getCalendarDate(date + rawOffset, cdate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            int year = cdate.getNormalizedYear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            if (year >= startYear) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                // Clear time elements for the transition calculations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                cdate.setTimeOfDay(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                offset = getOffset(cal, cdate, year, date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        if (offsets != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            offsets[0] = rawOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            offsets[1] = offset - rawOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        return offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * Returns the difference in milliseconds between local time and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * UTC, taking into account both the raw offset and the effect of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * daylight saving, for the specified date and time.  This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * assumes that the start and end month are distinct.  It also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * uses a default {@link GregorianCalendar} object as its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * underlying calendar, such as for determining leap years.  Do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * not use the result of this method with a calendar other than a
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   586
     * default {@code GregorianCalendar}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * <p><em>Note:  In general, clients should use
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   589
     * {@code Calendar.get(ZONE_OFFSET) + Calendar.get(DST_OFFSET)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * instead of calling this method.</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * @param era       The era of the given date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * @param year      The year in the given date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * @param month     The month in the given date. Month is 0-based. e.g.,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     *                  0 for January.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * @param day       The day-in-month of the given date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * @param dayOfWeek The day-of-week of the given date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * @param millis    The milliseconds in day in <em>standard</em> local time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * @return          The milliseconds to add to UTC to get local time.
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   600
     * @throws          IllegalArgumentException the {@code era},
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   601
     *                  {@code month}, {@code day}, {@code dayOfWeek},
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   602
     *                  or {@code millis} parameters are out of range
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    public int getOffset(int era, int year, int month, int day, int dayOfWeek,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                         int millis)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        if (era != GregorianCalendar.AD && era != GregorianCalendar.BC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            throw new IllegalArgumentException("Illegal era " + era);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        int y = year;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        if (era == GregorianCalendar.BC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            // adjust y with the GregorianCalendar-style year numbering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            y = 1 - y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        // If the year isn't representable with the 64-bit long
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        // integer in milliseconds, convert the year to an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        // equivalent year. This is required to pass some JCK test cases
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        // which are actually useless though because the specified years
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        // can't be supported by the Java time system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        if (y >= 292278994) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            y = 2800 + y % 2800;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        } else if (y <= -292269054) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            // y %= 28 also produces an equivalent year, but positive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            // year numbers would be convenient to use the UNIX cal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            // command.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            y = (int) CalendarUtils.mod((long) y, 28);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        // convert year to its 1-based month value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        int m = month + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        // First, calculate time as a Gregorian date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        BaseCalendar cal = gcal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        BaseCalendar.Date cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        cdate.setDate(y, m, day);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        long time = cal.getTime(cdate); // normalize cdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        time += millis - rawOffset; // UTC time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        // If the time value represents a time before the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        // Gregorian cutover, recalculate time using the Julian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        // calendar system. For the Julian calendar system, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        // normalized year numbering is ..., -2 (BCE 2), -1 (BCE 1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        // 1, 2 ... which is different from the GregorianCalendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        // style year numbering (..., -1, 0 (BCE 1), 1, 2, ...).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        if (time < GregorianCalendar.DEFAULT_GREGORIAN_CUTOVER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            cal = (BaseCalendar) CalendarSystem.forName("julian");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            cdate.setNormalizedDate(y, m, day);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            time = cal.getTime(cdate) + millis - rawOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        if ((cdate.getNormalizedYear() != y)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            || (cdate.getMonth() != m)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            || (cdate.getDayOfMonth() != day)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            // The validation should be cdate.getDayOfWeek() ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            // dayOfWeek. However, we don't check dayOfWeek for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            // compatibility.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            || (dayOfWeek < Calendar.SUNDAY || dayOfWeek > Calendar.SATURDAY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            || (millis < 0 || millis >= (24*60*60*1000))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        if (!useDaylight || year < startYear || era != GregorianCalendar.CE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            return rawOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        return getOffset(cal, cdate, y, time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    private int getOffset(BaseCalendar cal, BaseCalendar.Date cdate, int year, long time) {
48239
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
   673
        Cache cache = this.cache;
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
   674
        if (cache != null) {
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
   675
            if (time >= cache.start && time < cache.end) {
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
   676
                return rawOffset + dstSavings;
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
   677
            }
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
   678
            if (year == cache.year) {
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
   679
                return rawOffset;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        long start = getStart(cal, cdate, year);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        long end = getEnd(cal, cdate, year);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        int offset = rawOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        if (start <= end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            if (time >= start && time < end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                offset += dstSavings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            }
48239
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
   690
            this.cache = new Cache(year, start, end);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            if (time < end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                // TODO: support Gregorian cutover. The previous year
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                // may be in the other calendar system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                start = getStart(cal, cdate, year - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                if (time >= start) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                    offset += dstSavings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            } else if (time >= start) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                // TODO: support Gregorian cutover. The next year
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                // may be in the other calendar system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                end = getEnd(cal, cdate, year + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                if (time < end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                    offset += dstSavings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            if (start <= end) {
48239
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
   708
                this.cache = new Cache((long) startYear - 1, start, end);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        return offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    private long getStart(BaseCalendar cal, BaseCalendar.Date cdate, int year) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        int time = startTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        if (startTimeMode != UTC_TIME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            time -= rawOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        return getTransition(cal, cdate, startMode, year, startMonth, startDay,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                             startDayOfWeek, time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    private long getEnd(BaseCalendar cal, BaseCalendar.Date cdate, int year) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        int time = endTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        if (endTimeMode != UTC_TIME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            time -= rawOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        if (endTimeMode == WALL_TIME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            time -= dstSavings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        return getTransition(cal, cdate, endMode, year, endMonth, endDay,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                                        endDayOfWeek, time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    private long getTransition(BaseCalendar cal, BaseCalendar.Date cdate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                               int mode, int year, int month, int dayOfMonth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                               int dayOfWeek, int timeOfDay) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        cdate.setNormalizedYear(year);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        cdate.setMonth(month + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        switch (mode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        case DOM_MODE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            cdate.setDayOfMonth(dayOfMonth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        case DOW_IN_MONTH_MODE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            cdate.setDayOfMonth(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            if (dayOfMonth < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                cdate.setDayOfMonth(cal.getMonthLength(cdate));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            cdate = (BaseCalendar.Date) cal.getNthDayOfWeek(dayOfMonth, dayOfWeek, cdate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        case DOW_GE_DOM_MODE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            cdate.setDayOfMonth(dayOfMonth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            cdate = (BaseCalendar.Date) cal.getNthDayOfWeek(1, dayOfWeek, cdate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        case DOW_LE_DOM_MODE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            cdate.setDayOfMonth(dayOfMonth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            cdate = (BaseCalendar.Date) cal.getNthDayOfWeek(-1, dayOfWeek, cdate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        return cal.getTime(cdate) + timeOfDay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     * Gets the GMT offset for this time zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     * @return the GMT offset value in milliseconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * @see #setRawOffset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    public int getRawOffset()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        // The given date will be taken into account while
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        // we have the historical time zone data in place.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        return rawOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * Sets the base time zone offset to GMT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * This is the offset to add to UTC to get local time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * @see #getRawOffset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    public void setRawOffset(int offsetMillis)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        this.rawOffset = offsetMillis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * Sets the amount of time in milliseconds that the clock is advanced
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * during daylight saving time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * @param millisSavedDuringDST the number of milliseconds the time is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * advanced with respect to standard time when the daylight saving time rules
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * are in effect. A positive number, typically one hour (3600000).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * @see #getDSTSavings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    public void setDSTSavings(int millisSavedDuringDST) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        if (millisSavedDuringDST <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            throw new IllegalArgumentException("Illegal daylight saving value: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                                               + millisSavedDuringDST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        dstSavings = millisSavedDuringDST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * Returns the amount of time in milliseconds that the clock is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * advanced during daylight saving time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * @return the number of milliseconds the time is advanced with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * respect to standard time when the daylight saving rules are in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * effect, or 0 (zero) if this time zone doesn't observe daylight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * saving time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     * @see #setDSTSavings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    public int getDSTSavings() {
8375
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 5506
diff changeset
   818
        return useDaylight ? dstSavings : 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     * Queries if this time zone uses daylight saving time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     * @return true if this time zone uses daylight saving time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     * false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    public boolean useDaylightTime()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        return useDaylight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    /**
8375
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 5506
diff changeset
   832
     * Returns {@code true} if this {@code SimpleTimeZone} observes
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 5506
diff changeset
   833
     * Daylight Saving Time. This method is equivalent to {@link
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 5506
diff changeset
   834
     * #useDaylightTime()}.
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 5506
diff changeset
   835
     *
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 5506
diff changeset
   836
     * @return {@code true} if this {@code SimpleTimeZone} observes
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 5506
diff changeset
   837
     * Daylight Saving Time; {@code false} otherwise.
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 5506
diff changeset
   838
     * @since 1.7
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 5506
diff changeset
   839
     */
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 5506
diff changeset
   840
    @Override
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 5506
diff changeset
   841
    public boolean observesDaylightTime() {
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 5506
diff changeset
   842
        return useDaylightTime();
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 5506
diff changeset
   843
    }
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 5506
diff changeset
   844
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 5506
diff changeset
   845
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * Queries if the given date is in daylight saving time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * @return true if daylight saving time is in effective at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * given date; false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    public boolean inDaylightTime(Date date)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        return (getOffset(date.getTime()) != rawOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
    /**
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   856
     * Returns a clone of this {@code SimpleTimeZone} instance.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * @return a clone of this instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
    public Object clone()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        return super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * Generates the hash code for the SimpleDateFormat object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     * @return the hash code for this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     */
48239
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
   868
    public int hashCode()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        return startMonth ^ startDay ^ startDayOfWeek ^ startTime ^
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
            endMonth ^ endDay ^ endDayOfWeek ^ endTime ^ rawOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
    /**
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   875
     * Compares the equality of two {@code SimpleTimeZone} objects.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     *
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   877
     * @param obj  The {@code SimpleTimeZone} object to be compared with.
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   878
     * @return     True if the given {@code obj} is the same as this
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   879
     *             {@code SimpleTimeZone} object; false otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
    public boolean equals(Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        if (this == obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        if (!(obj instanceof SimpleTimeZone)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        SimpleTimeZone that = (SimpleTimeZone) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        return getID().equals(that.getID()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            hasSameRules(that);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
    /**
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   897
     * Returns {@code true} if this zone has the same rules and offset as another zone.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     * @param other the TimeZone object to be compared with
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   899
     * @return {@code true} if the given zone is a SimpleTimeZone and has the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     * same rules and offset as this one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
    public boolean hasSameRules(TimeZone other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        if (this == other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        if (!(other instanceof SimpleTimeZone)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        SimpleTimeZone that = (SimpleTimeZone) other;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        return rawOffset == that.rawOffset &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            useDaylight == that.useDaylight &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            (!useDaylight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
             // Only check rules if using DST
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
             || (dstSavings == that.dstSavings &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                 startMode == that.startMode &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                 startMonth == that.startMonth &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                 startDay == that.startDay &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                 startDayOfWeek == that.startDayOfWeek &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                 startTime == that.startTime &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                 startTimeMode == that.startTimeMode &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                 endMode == that.endMode &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                 endMonth == that.endMonth &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                 endDay == that.endDay &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                 endDayOfWeek == that.endDayOfWeek &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                 endTime == that.endTime &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                 endTimeMode == that.endTimeMode &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                 startYear == that.startYear));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     * Returns a string representation of this time zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     * @return a string representation of this time zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        return getClass().getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            "[id=" + getID() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            ",offset=" + rawOffset +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
            ",dstSavings=" + dstSavings +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
            ",useDaylight=" + useDaylight +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
            ",startYear=" + startYear +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            ",startMode=" + startMode +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
            ",startMonth=" + startMonth +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            ",startDay=" + startDay +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            ",startDayOfWeek=" + startDayOfWeek +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
            ",startTime=" + startTime +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            ",startTimeMode=" + startTimeMode +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            ",endMode=" + endMode +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            ",endMonth=" + endMonth +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            ",endDay=" + endDay +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
            ",endDayOfWeek=" + endDayOfWeek +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            ",endTime=" + endTime +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            ",endTimeMode=" + endTimeMode + ']';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
    // =======================privates===============================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     * The month in which daylight saving time starts.  This value must be
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   960
     * between {@code Calendar.JANUARY} and
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   961
     * {@code Calendar.DECEMBER} inclusive.  This value must not equal
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   962
     * {@code endMonth}.
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   963
     * <p>If {@code useDaylight} is false, this value is ignored.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
    private int startMonth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     * This field has two possible interpretations:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
     * <dl>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   971
     * <dt>{@code startMode == DOW_IN_MONTH}</dt>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
     * <dd>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   973
     * {@code startDay} indicates the day of the month of
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   974
     * {@code startMonth} on which daylight
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     * saving time starts, from 1 to 28, 30, or 31, depending on the
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   976
     * {@code startMonth}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     * </dd>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   978
     * <dt>{@code startMode != DOW_IN_MONTH}</dt>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     * <dd>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   980
     * {@code startDay} indicates which {@code startDayOfWeek} in the
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   981
     * month {@code startMonth} daylight
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     * saving time starts on.  For example, a value of +1 and a
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   983
     * {@code startDayOfWeek} of {@code Calendar.SUNDAY} indicates the
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   984
     * first Sunday of {@code startMonth}.  Likewise, +2 would indicate the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * second Sunday, and -1 the last Sunday.  A value of 0 is illegal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * </dd>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     * </dl>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   988
     * <p>If {@code useDaylight} is false, this value is ignored.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
    private int startDay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     * The day of the week on which daylight saving time starts.  This value
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   995
     * must be between {@code Calendar.SUNDAY} and
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   996
     * {@code Calendar.SATURDAY} inclusive.
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   997
     * <p>If {@code useDaylight} is false or
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   998
     * {@code startMode == DAY_OF_MONTH}, this value is ignored.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
    private int startDayOfWeek;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * The time in milliseconds after midnight at which daylight saving
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     * time starts.  This value is expressed as wall time, standard time,
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1006
     * or UTC time, depending on the setting of {@code startTimeMode}.
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1007
     * <p>If {@code useDaylight} is false, this value is ignored.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
    private int startTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     * The format of startTime, either WALL_TIME, STANDARD_TIME, or UTC_TIME.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
    private int startTimeMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     * The month in which daylight saving time ends.  This value must be
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1021
     * between {@code Calendar.JANUARY} and
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1022
     * {@code Calendar.UNDECIMBER}.  This value must not equal
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1023
     * {@code startMonth}.
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1024
     * <p>If {@code useDaylight} is false, this value is ignored.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
    private int endMonth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     * This field has two possible interpretations:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     * <dl>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1032
     * <dt>{@code endMode == DOW_IN_MONTH}</dt>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     * <dd>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1034
     * {@code endDay} indicates the day of the month of
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1035
     * {@code endMonth} on which daylight
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     * saving time ends, from 1 to 28, 30, or 31, depending on the
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1037
     * {@code endMonth}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     * </dd>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1039
     * <dt>{@code endMode != DOW_IN_MONTH}</dt>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     * <dd>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1041
     * {@code endDay} indicates which {@code endDayOfWeek} in th
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1042
     * month {@code endMonth} daylight
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
     * saving time ends on.  For example, a value of +1 and a
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1044
     * {@code endDayOfWeek} of {@code Calendar.SUNDAY} indicates the
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1045
     * first Sunday of {@code endMonth}.  Likewise, +2 would indicate the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     * second Sunday, and -1 the last Sunday.  A value of 0 is illegal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
     * </dd>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
     * </dl>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1049
     * <p>If {@code useDaylight} is false, this value is ignored.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
    private int endDay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
     * The day of the week on which daylight saving time ends.  This value
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1056
     * must be between {@code Calendar.SUNDAY} and
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1057
     * {@code Calendar.SATURDAY} inclusive.
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1058
     * <p>If {@code useDaylight} is false or
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1059
     * {@code endMode == DAY_OF_MONTH}, this value is ignored.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
    private int endDayOfWeek;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     * The time in milliseconds after midnight at which daylight saving
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     * time ends.  This value is expressed as wall time, standard time,
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1067
     * or UTC time, depending on the setting of {@code endTimeMode}.
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1068
     * <p>If {@code useDaylight} is false, this value is ignored.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
    private int endTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
    /**
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1074
     * The format of endTime, either {@code WALL_TIME},
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1075
     * {@code STANDARD_TIME}, or {@code UTC_TIME}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
    private int endTimeMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
     * The year in which daylight saving time is first observed.  This is an {@link GregorianCalendar#AD AD}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
     * value.  If this value is less than 1 then daylight saving time is observed
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1084
     * for all {@code AD} years.
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1085
     * <p>If {@code useDaylight} is false, this value is ignored.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
    private int startYear;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
     * The offset in milliseconds between this zone and GMT.  Negative offsets
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
     * are to the west of Greenwich.  To obtain local <em>standard</em> time,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
     * add the offset to GMT time.  To obtain local wall time it may also be
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1094
     * necessary to add {@code dstSavings}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
    private int rawOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
     * A boolean value which is true if and only if this zone uses daylight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
     * saving time.  If this value is false, several other fields are ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
    private boolean useDaylight=false; // indicate if this time zone uses DST
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
    private static final int millisPerHour = 60*60*1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
    private static final int millisPerDay  = 24*millisPerHour;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
     * This field was serialized in JDK 1.1, so we have to keep it that way
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
     * to maintain serialization compatibility. However, there's no need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
     * recreate the array each time we create a new time zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
     * @serial An array of bytes containing the values {31, 28, 31, 30, 31, 30,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
     * 31, 31, 30, 31, 30, 31}.  This is ignored as of the Java 2 platform v1.2, however, it must
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
     * be streamed out for compatibility with JDK 1.1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
    private final byte monthLength[] = staticMonthLength;
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
  1118
    private static final byte staticMonthLength[] = {31,28,31,30,31,30,31,31,30,31,30,31};
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
  1119
    private static final byte staticLeapMonthLength[] = {31,29,31,30,31,30,31,31,30,31,30,31};
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
     * Variables specifying the mode of the start rule.  Takes the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
     * values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
     * <dl>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1125
     * <dt>{@code DOM_MODE}</dt>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
     * <dd>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
     * Exact day of week; e.g., March 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
     * </dd>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1129
     * <dt>{@code DOW_IN_MONTH_MODE}</dt>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
     * <dd>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
     * Day of week in month; e.g., last Sunday in March.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
     * </dd>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1133
     * <dt>{@code DOW_GE_DOM_MODE}</dt>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     * <dd>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
     * Day of week after day of month; e.g., Sunday on or after March 15.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
     * </dd>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1137
     * <dt>{@code DOW_LE_DOM_MODE}</dt>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
     * <dd>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
     * Day of week before day of month; e.g., Sunday on or before March 15.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     * </dd>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     * </dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     * The setting of this field affects the interpretation of the
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1143
     * {@code startDay} field.
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1144
     * <p>If {@code useDaylight} is false, this value is ignored.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     * @since 1.1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
    private int startMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
     * Variables specifying the mode of the end rule.  Takes the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
     * values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
     * <dl>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1154
     * <dt>{@code DOM_MODE}</dt>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
     * <dd>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
     * Exact day of week; e.g., March 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
     * </dd>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1158
     * <dt>{@code DOW_IN_MONTH_MODE}</dt>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
     * <dd>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
     * Day of week in month; e.g., last Sunday in March.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
     * </dd>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1162
     * <dt>{@code DOW_GE_DOM_MODE}</dt>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
     * <dd>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
     * Day of week after day of month; e.g., Sunday on or after March 15.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     * </dd>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1166
     * <dt>{@code DOW_LE_DOM_MODE}</dt>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     * <dd>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     * Day of week before day of month; e.g., Sunday on or before March 15.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     * </dd>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
     * </dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     * The setting of this field affects the interpretation of the
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1172
     * {@code endDay} field.
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1173
     * <p>If {@code useDaylight} is false, this value is ignored.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     * @since 1.1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
    private int endMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
     * A positive value indicating the amount of time saved during DST in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
     * milliseconds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
     * Typically one hour (3600000); sometimes 30 minutes (1800000).
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1183
     * <p>If {@code useDaylight} is false, this value is ignored.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
     * @since 1.1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
    private int dstSavings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
    private static final Gregorian gcal = CalendarSystem.getGregorianCalendar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     * Cache values representing a single period of daylight saving
48239
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
  1193
     * time. Cache.start is the start time (inclusive) of daylight
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
  1194
     * saving time and Cache.end is the end time (exclusive).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
     *
48239
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
  1196
     * Cache.year has a year value if both Cache.start and Cache.end are
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
  1197
     * in the same year. Cache.year is set to startYear - 1 if
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
  1198
     * Cache.start and Cache.end are in different years.
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
  1199
     * Cache.year is a long to support Integer.MIN_VALUE - 1 (JCK requirement).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
     */
48239
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
  1201
    private static final class Cache {
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
  1202
        final long year;
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
  1203
        final long start;
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
  1204
        final long end;
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
  1205
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
  1206
        Cache(long year, long start, long end) {
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
  1207
            this.year = year;
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
  1208
            this.start = start;
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
  1209
            this.end = end;
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
  1210
        }
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
  1211
    }
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
  1212
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
  1213
    private transient volatile Cache cache;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
     * Constants specifying values of startMode and endMode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
    private static final int DOM_MODE          = 1; // Exact day of month, "Mar 1"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
    private static final int DOW_IN_MONTH_MODE = 2; // Day of week in month, "lastSun"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
    private static final int DOW_GE_DOM_MODE   = 3; // Day of week after day of month, "Sun>=15"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
    private static final int DOW_LE_DOM_MODE   = 4; // Day of week before day of month, "Sun<=21"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
     * Constant for a mode of start or end time specified as wall clock
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
     * time.  Wall clock time is standard time for the onset rule, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
     * daylight time for the end rule.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
    public static final int WALL_TIME = 0; // Zero for backward compatibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     * Constant for a mode of start or end time specified as standard time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
    public static final int STANDARD_TIME = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
     * Constant for a mode of start or end time specified as UTC. European
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     * Union rules are specified as UTC time, for example.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
    public static final int UTC_TIME = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
    // Proclaim compatibility with 1.1
57956
e0b8b019d2f5 8229997: Apply java.io.Serial annotations in java.base
darcy
parents: 53563
diff changeset
  1245
    @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
    static final long serialVersionUID = -403250971215465050L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
    // the internal serial version which says which version was written
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
    // - 0 (default) for version up to JDK 1.1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
    // - 1 for version from JDK 1.1.4, which includes 3 new fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
    // - 2 for JDK 1.3, which includes 2 new fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
    static final int currentSerialVersion = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
     * The version of the serialized data on the stream.  Possible values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
     * <dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
     * <dt><b>0</b> or not present on stream</dt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
     * <dd>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
     * JDK 1.1.3 or earlier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
     * </dd>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
     * <dt><b>1</b></dt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
     * <dd>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1263
     * JDK 1.1.4 or later.  Includes three new fields: {@code startMode},
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1264
     * {@code endMode}, and {@code dstSavings}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
     * </dd>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
     * <dt><b>2</b></dt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
     * <dd>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1268
     * JDK 1.3 or later.  Includes two new fields: {@code startTimeMode}
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1269
     * and {@code endTimeMode}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
     * </dd>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
     * </dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
     * When streaming out this class, the most recent format
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1273
     * and the highest allowable {@code serialVersionOnStream}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
     * is written.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
     * @since 1.1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
    private int serialVersionOnStream = currentSerialVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
47414
3448b80444f3 8181323: Better timezone processing
naoto
parents: 47216
diff changeset
  1280
    // Maximum number of rules.
3448b80444f3 8181323: Better timezone processing
naoto
parents: 47216
diff changeset
  1281
    private static final int MAX_RULE_NUM = 6;
3448b80444f3 8181323: Better timezone processing
naoto
parents: 47216
diff changeset
  1282
48239
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
  1283
    private void invalidateCache() {
8067e9cba973 8191216: SimpleTimeZone.clone() has a data race on cache fields
plevart
parents: 47414
diff changeset
  1284
        cache = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
    //----------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
    // Rule representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
    // We represent the following flavors of rules:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
    //       5        the fifth of the month
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
    //       lastSun  the last Sunday in the month
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
    //       lastMon  the last Monday in the month
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
    //       Sun>=8   first Sunday on or after the eighth
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
    //       Sun<=25  last Sunday on or before the 25th
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
    // This is further complicated by the fact that we need to remain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
    // backward compatible with the 1.1 FCS.  Finally, we need to minimize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
    // API changes.  In order to satisfy these requirements, we support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
    // three representation systems, and we translate between them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
    // INTERNAL REPRESENTATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
    // This is the format SimpleTimeZone objects take after construction or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
    // streaming in is complete.  Rules are represented directly, using an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
    // unencoded format.  We will discuss the start rule only below; the end
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
    // rule is analogous.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
    //   startMode      Takes on enumerated values DAY_OF_MONTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
    //                  DOW_IN_MONTH, DOW_AFTER_DOM, or DOW_BEFORE_DOM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
    //   startDay       The day of the month, or for DOW_IN_MONTH mode, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
    //                  value indicating which DOW, such as +1 for first,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
    //                  +2 for second, -1 for last, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
    //   startDayOfWeek The day of the week.  Ignored for DAY_OF_MONTH.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
    // ENCODED REPRESENTATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
    // This is the format accepted by the constructor and by setStartRule()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
    // and setEndRule().  It uses various combinations of positive, negative,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
    // and zero values to encode the different rules.  This representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
    // allows us to specify all the different rule flavors without altering
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
    // the API.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
    //   MODE              startMonth    startDay    startDayOfWeek
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
    //   DOW_IN_MONTH_MODE >=0           !=0         >0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
    //   DOM_MODE          >=0           >0          ==0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
    //   DOW_GE_DOM_MODE   >=0           >0          <0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
    //   DOW_LE_DOM_MODE   >=0           <0          <0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
    //   (no DST)          don't care    ==0         don't care
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
    // STREAMED REPRESENTATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
    // We must retain binary compatibility with the 1.1 FCS.  The 1.1 code only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
    // handles DOW_IN_MONTH_MODE and non-DST mode, the latter indicated by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
    // flag useDaylight.  When we stream an object out, we translate into an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
    // approximate DOW_IN_MONTH_MODE representation so the object can be parsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
    // and used by 1.1 code.  Following that, we write out the full
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
    // representation separately so that contemporary code can recognize and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
    // parse it.  The full representation is written in a "packed" format,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
    // consisting of a version number, a length, and an array of bytes.  Future
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
    // versions of this class may specify different versions.  If they wish to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
    // include additional data, they should do so by storing them after the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
    // packed representation below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
    //----------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
     * Given a set of encoded rules in startDay and startDayOfMonth, decode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
     * them and set the startMode appropriately.  Do the same for endDay and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
     * endDayOfMonth.  Upon entry, the day of week variables may be zero or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
     * negative, in order to indicate special modes.  The day of month
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
     * variables may also be negative.  Upon exit, the mode variables will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
     * set, and the day of week and day of month variables will be positive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
     * This method also recognizes a startDay or endDay of zero as indicating
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
     * no DST.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
    private void decodeRules()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
        decodeStartRule();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
        decodeEndRule();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
     * Decode the start rule and validate the parameters.  The parameters are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
     * expected to be in encoded form, which represents the various rule modes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
     * by negating or zeroing certain values.  Representation formats are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
     *            DOW_IN_MONTH  DOM    DOW>=DOM  DOW<=DOM  no DST
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
     *            ------------  -----  --------  --------  ----------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
     * month       0..11        same    same      same     don't care
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
     * day        -5..5         1..31   1..31    -1..-31   0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
     * dayOfWeek   1..7         0      -1..-7    -1..-7    don't care
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
     * time        0..ONEDAY    same    same      same     don't care
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
     * The range for month does not include UNDECIMBER since this class is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
     * really specific to GregorianCalendar, which does not use that month.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
     * The range for time includes ONEDAY (vs. ending at ONEDAY-1) because the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
     * end rule is an exclusive limit point.  That is, the range of times that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
     * are in DST include those >= the start and < the end.  For this reason,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
     * it should be possible to specify an end of ONEDAY in order to include the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
     * entire day.  Although this is equivalent to time 0 of the following day,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
     * it's not always possible to specify that, for example, on December 31.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
     * While arguably the start range should still be 0..ONEDAY-1, we keep
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
     * the start and end ranges the same for consistency.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
    private void decodeStartRule() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        useDaylight = (startDay != 0) && (endDay != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
        if (startDay != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
            if (startMonth < Calendar.JANUARY || startMonth > Calendar.DECEMBER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
                throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
                        "Illegal start month " + startMonth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
            }
3738
837612df050f 6851214: (tz) New Jordan rule creates a failure for SimpleTimeZone parsing post tzdata2009h
peytoia
parents: 2
diff changeset
  1387
            if (startTime < 0 || startTime > millisPerDay) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
                throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
                        "Illegal start time " + startTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
            if (startDayOfWeek == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
                startMode = DOM_MODE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
                if (startDayOfWeek > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
                    startMode = DOW_IN_MONTH_MODE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
                    startDayOfWeek = -startDayOfWeek;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
                    if (startDay > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
                        startMode = DOW_GE_DOM_MODE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
                        startDay = -startDay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
                        startMode = DOW_LE_DOM_MODE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
                if (startDayOfWeek > Calendar.SATURDAY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
                    throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
                           "Illegal start day of week " + startDayOfWeek);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
            if (startMode == DOW_IN_MONTH_MODE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
                if (startDay < -5 || startDay > 5) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
                    throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
                            "Illegal start day of week in month " + startDay);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
            } else if (startDay < 1 || startDay > staticMonthLength[startMonth]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
                throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
                        "Illegal start day " + startDay);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
     * Decode the end rule and validate the parameters.  This method is exactly
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
     * analogous to decodeStartRule().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
     * @see decodeStartRule
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
    private void decodeEndRule() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
        useDaylight = (startDay != 0) && (endDay != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
        if (endDay != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
            if (endMonth < Calendar.JANUARY || endMonth > Calendar.DECEMBER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
                throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
                        "Illegal end month " + endMonth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
            }
3738
837612df050f 6851214: (tz) New Jordan rule creates a failure for SimpleTimeZone parsing post tzdata2009h
peytoia
parents: 2
diff changeset
  1434
            if (endTime < 0 || endTime > millisPerDay) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
                throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
                        "Illegal end time " + endTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
            if (endDayOfWeek == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
                endMode = DOM_MODE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
                if (endDayOfWeek > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
                    endMode = DOW_IN_MONTH_MODE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
                    endDayOfWeek = -endDayOfWeek;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
                    if (endDay > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
                        endMode = DOW_GE_DOM_MODE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
                        endDay = -endDay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
                        endMode = DOW_LE_DOM_MODE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
                if (endDayOfWeek > Calendar.SATURDAY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
                    throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
                           "Illegal end day of week " + endDayOfWeek);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
            if (endMode == DOW_IN_MONTH_MODE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
                if (endDay < -5 || endDay > 5) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
                    throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
                            "Illegal end day of week in month " + endDay);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
            } else if (endDay < 1 || endDay > staticMonthLength[endMonth]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
                throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
                        "Illegal end day " + endDay);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
     * Make rules compatible to 1.1 FCS code.  Since 1.1 FCS code only understands
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
     * day-of-week-in-month rules, we must modify other modes of rules to their
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
     * approximate equivalent in 1.1 FCS terms.  This method is used when streaming
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
     * out objects of this class.  After it is called, the rules will be modified,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
     * with a possible loss of information.  startMode and endMode will NOT be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
     * altered, even though semantically they should be set to DOW_IN_MONTH_MODE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
     * since the rule modification is only intended to be temporary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
    private void makeRulesCompatible()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
        switch (startMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
        case DOM_MODE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
            startDay = 1 + (startDay / 7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
            startDayOfWeek = Calendar.SUNDAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
        case DOW_GE_DOM_MODE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
            // A day-of-month of 1 is equivalent to DOW_IN_MONTH_MODE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
            // that is, Sun>=1 == firstSun.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
            if (startDay != 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
                startDay = 1 + (startDay / 7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
        case DOW_LE_DOM_MODE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
            if (startDay >= 30) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
                startDay = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
                startDay = 1 + (startDay / 7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
        switch (endMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
        case DOM_MODE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
            endDay = 1 + (endDay / 7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
            endDayOfWeek = Calendar.SUNDAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
        case DOW_GE_DOM_MODE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
            // A day-of-month of 1 is equivalent to DOW_IN_MONTH_MODE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
            // that is, Sun>=1 == firstSun.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
            if (endDay != 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
                endDay = 1 + (endDay / 7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
        case DOW_LE_DOM_MODE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
            if (endDay >= 30) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
                endDay = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
                endDay = 1 + (endDay / 7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
         * Adjust the start and end times to wall time.  This works perfectly
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
         * well unless it pushes into the next or previous day.  If that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
         * happens, we attempt to adjust the day rule somewhat crudely.  The day
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
         * rules have been forced into DOW_IN_MONTH mode already, so we change
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
         * the day of week to move forward or back by a day.  It's possible to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
         * make a more refined adjustment of the original rules first, but in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
         * most cases this extra effort will go to waste once we adjust the day
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
         * rules anyway.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
        switch (startTimeMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
        case UTC_TIME:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
            startTime += rawOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
        while (startTime < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
            startTime += millisPerDay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
            startDayOfWeek = 1 + ((startDayOfWeek+5) % 7); // Back 1 day
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
        while (startTime >= millisPerDay) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
            startTime -= millisPerDay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
            startDayOfWeek = 1 + (startDayOfWeek % 7); // Forward 1 day
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
        switch (endTimeMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
        case UTC_TIME:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
            endTime += rawOffset + dstSavings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
        case STANDARD_TIME:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
            endTime += dstSavings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
        while (endTime < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
            endTime += millisPerDay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
            endDayOfWeek = 1 + ((endDayOfWeek+5) % 7); // Back 1 day
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
        while (endTime >= millisPerDay) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
            endTime -= millisPerDay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
            endDayOfWeek = 1 + (endDayOfWeek % 7); // Forward 1 day
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
     * Pack the start and end rules into an array of bytes.  Only pack
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
     * data which is not preserved by makeRulesCompatible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
    private byte[] packRules()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
    {
47414
3448b80444f3 8181323: Better timezone processing
naoto
parents: 47216
diff changeset
  1573
        byte[] rules = new byte[MAX_RULE_NUM];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
        rules[0] = (byte)startDay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
        rules[1] = (byte)startDayOfWeek;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
        rules[2] = (byte)endDay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
        rules[3] = (byte)endDayOfWeek;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
        // As of serial version 2, include time modes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
        rules[4] = (byte)startTimeMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
        rules[5] = (byte)endTimeMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
        return rules;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
     * Given an array of bytes produced by packRules, interpret them
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
     * as the start and end rules.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
    private void unpackRules(byte[] rules)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
        startDay       = rules[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
        startDayOfWeek = rules[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
        endDay         = rules[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
        endDayOfWeek   = rules[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
        // As of serial version 2, include time modes
47414
3448b80444f3 8181323: Better timezone processing
naoto
parents: 47216
diff changeset
  1598
        if (rules.length >= MAX_RULE_NUM) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
            startTimeMode = rules[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
            endTimeMode   = rules[5];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
     * Pack the start and end times into an array of bytes.  This is required
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
     * as of serial version 2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
    private int[] packTimes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
        int[] times = new int[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
        times[0] = startTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
        times[1] = endTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
        return times;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
     * Unpack the start and end times from an array of bytes.  This is required
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
     * as of serial version 2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
    private void unpackTimes(int[] times) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
        startTime = times[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
        endTime = times[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
     * Save the state of this object to a stream (i.e., serialize it).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
     * @serialData We write out two formats, a JDK 1.1 compatible format, using
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1628
     * {@code DOW_IN_MONTH_MODE} rules, in the required section, followed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
     * by the full rules, in packed format, in the optional section.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
     * optional section will be ignored by JDK 1.1 code upon stream in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
     * <p> Contents of the optional section: The length of a byte array is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
     * emitted (int); this is 4 as of this release. The byte array of the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
     * length is emitted. The contents of the byte array are the true values of
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1634
     * the fields {@code startDay}, {@code startDayOfWeek},
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1635
     * {@code endDay}, and {@code endDayOfWeek}.  The values of these
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
     * fields in the required section are approximate values suited to the rule
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1637
     * mode {@code DOW_IN_MONTH_MODE}, which is the only mode recognized by
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
     * JDK 1.1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
     */
57956
e0b8b019d2f5 8229997: Apply java.io.Serial annotations in java.base
darcy
parents: 53563
diff changeset
  1640
    @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
    private void writeObject(ObjectOutputStream stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
         throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
        // Construct a binary rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
        byte[] rules = packRules();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
        int[] times = packTimes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
        // Convert to 1.1 FCS rules.  This step may cause us to lose information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
        makeRulesCompatible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
        // Write out the 1.1 FCS rules
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
        stream.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
        // Write out the binary rules in the optional data area of the stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
        stream.writeInt(rules.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
        stream.write(rules);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
        stream.writeObject(times);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
        // Recover the original rules.  This recovers the information lost
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
        // by makeRulesCompatible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
        unpackRules(rules);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
        unpackTimes(times);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
     * Reconstitute this object from a stream (i.e., deserialize it).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
     * We handle both JDK 1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
     * binary formats and full formats with a packed byte array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
     */
57956
e0b8b019d2f5 8229997: Apply java.io.Serial annotations in java.base
darcy
parents: 53563
diff changeset
  1671
    @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
    private void readObject(ObjectInputStream stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
         throws IOException, ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
        stream.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
        if (serialVersionOnStream < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
            // Fix a bug in the 1.1 SimpleTimeZone code -- namely,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
            // startDayOfWeek and endDayOfWeek were usually uninitialized.  We can't do
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
            // too much, so we assume SUNDAY, which actually works most of the time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
            if (startDayOfWeek == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
                startDayOfWeek = Calendar.SUNDAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
            if (endDayOfWeek == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
                endDayOfWeek = Calendar.SUNDAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
            // The variables dstSavings, startMode, and endMode are post-1.1, so they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
            // won't be present if we're reading from a 1.1 stream.  Fix them up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
            startMode = endMode = DOW_IN_MONTH_MODE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
            dstSavings = millisPerHour;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
            // For 1.1.4, in addition to the 3 new instance variables, we also
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
            // store the actual rules (which have not be made compatible with 1.1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
            // in the optional area.  Read them in here and parse them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
            int length = stream.readInt();
47414
3448b80444f3 8181323: Better timezone processing
naoto
parents: 47216
diff changeset
  1697
            if (length <= MAX_RULE_NUM) {
3448b80444f3 8181323: Better timezone processing
naoto
parents: 47216
diff changeset
  1698
                byte[] rules = new byte[length];
3448b80444f3 8181323: Better timezone processing
naoto
parents: 47216
diff changeset
  1699
                stream.readFully(rules);
3448b80444f3 8181323: Better timezone processing
naoto
parents: 47216
diff changeset
  1700
                unpackRules(rules);
3448b80444f3 8181323: Better timezone processing
naoto
parents: 47216
diff changeset
  1701
            } else {
3448b80444f3 8181323: Better timezone processing
naoto
parents: 47216
diff changeset
  1702
                throw new InvalidObjectException("Too many rules: " + length);
3448b80444f3 8181323: Better timezone processing
naoto
parents: 47216
diff changeset
  1703
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
        if (serialVersionOnStream >= 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
            int[] times = (int[]) stream.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
            unpackTimes(times);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
        serialVersionOnStream = currentSerialVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
}