src/java.base/share/classes/sun/util/calendar/ZoneInfo.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 57956 e0b8b019d2f5
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
/*
57956
e0b8b019d2f5 8229997: Apply java.io.Serial annotations in java.base
darcy
parents: 57544
diff changeset
     2
 * Copyright (c) 2000, 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: 1639
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: 1639
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: 1639
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
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
package sun.util.calendar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.SimpleTimeZone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.TimeZone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <code>ZoneInfo</code> is an implementation subclass of {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * java.util.TimeZone TimeZone} that represents GMT offsets and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * daylight saving time transitions of a time zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * The daylight saving time transitions are described in the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * #transitions transitions} table consisting of a chronological
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * sequence of transitions of GMT offset and/or daylight saving time
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * changes. Since all transitions are represented in UTC, in theory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <code>ZoneInfo</code> can be used with any calendar systems except
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * for the {@link #getOffset(int,int,int,int,int,int) getOffset}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * method that takes Gregorian calendar date fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * This table covers transitions from 1900 until 2037 (as of version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * 1.4), Before 1900, it assumes that there was no daylight saving
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * time and the <code>getOffset</code> methods always return the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * {@link #getRawOffset} value. No Local Mean Time is supported. If a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * specified date is beyond the transition table and this time zone is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * supposed to observe daylight saving time in 2037, it delegates
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * operations to a {@link java.util.SimpleTimeZone SimpleTimeZone}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * object created using the daylight saving time schedule as of 2037.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * The date items, transitions, GMT offset(s), etc. are read from a database
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * file. See {@link ZoneInfoFile} for details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @see java.util.SimpleTimeZone
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
public class ZoneInfo extends TimeZone {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private static final int UTC_TIME = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private static final int STANDARD_TIME = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private static final int WALL_TIME = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private static final long OFFSET_MASK = 0x0fL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private static final long DST_MASK = 0xf0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private static final int DST_NSHIFT = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    // this bit field is reserved for abbreviation support
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private static final long ABBR_MASK = 0xf00L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private static final int TRANSITION_NSHIFT = 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * The raw GMT offset in milliseconds between this zone and GMT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * Negative offsets are to the west of Greenwich.  To obtain local
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * <em>standard</em> time, add the offset to GMT time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private int rawOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * Difference in milliseconds from the original GMT offset in case
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * the raw offset value has been modified by calling {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * #setRawOffset}. The initial value is 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private int rawOffsetDiff = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * A CRC32 value of all pairs of transition time (in milliseconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * in <code>long</code>) in local time and its GMT offset (in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * seconds in <code>int</code>) in the chronological order. Byte
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * values of each <code>long</code> and <code>int</code> are taken
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * in the big endian order (i.e., MSB to LSB).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private int checksum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * The amount of time in milliseconds saved during daylight saving
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * time. If <code>useDaylight</code> is false, this value is 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private int dstSavings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * This array describes transitions of GMT offsets of this time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * zone, including both raw offset changes and daylight saving
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * time changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * A long integer consists of four bit fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * <li>The most significant 52-bit field represents transition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * time in milliseconds from Gregorian January 1 1970, 00:00:00
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * GMT.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * <li>The next 4-bit field is reserved and must be 0.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * <li>The next 4-bit field is an index value to {@link #offsets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * offsets[]} for the amount of daylight saving at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * transition. If this value is zero, it means that no daylight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * saving, not the index value zero.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * <li>The least significant 4-bit field is an index value to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * {@link #offsets offsets[]} for <em>total</em> GMT offset at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * transition.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * If this time zone doesn't observe daylight saving time and has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * never changed any GMT offsets in the past, this value is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    private long[] transitions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * This array holds all unique offset values in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * milliseconds. Index values to this array are stored in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * transitions array elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    private int[] offsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * SimpleTimeZone parameter values. It has to have either 8 for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * {@link java.util.SimpleTimeZone#SimpleTimeZone(int, String,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * int, int , int , int , int , int , int , int , int) the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * 11-argument SimpleTimeZone constructor} or 10 for {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * java.util.SimpleTimeZone#SimpleTimeZone(int, String, int, int,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * int , int , int , int , int , int , int, int, int) the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * 13-argument SimpleTimeZone constructor} parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    private int[] simpleTimeZoneParams;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * True if the raw GMT offset value would change after the time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * zone data has been generated; false, otherwise. The default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * value is false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    private boolean willGMTOffsetChange = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * True if the object has been modified after its instantiation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31061
diff changeset
   164
    private transient boolean dirty = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
57956
e0b8b019d2f5 8229997: Apply java.io.Serial annotations in java.base
darcy
parents: 57544
diff changeset
   166
    @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    private static final long serialVersionUID = 2653134537216586139L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * A constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public ZoneInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * A Constructor for CustomID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    public ZoneInfo(String ID, int rawOffset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        this(ID, rawOffset, 0, 0, null, null, null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * Constructs a ZoneInfo instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @param ID time zone name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @param rawOffset GMT offset in milliseconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @param dstSavings daylight saving value in milliseconds or 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * (zero) if this time zone doesn't observe Daylight Saving Time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @param checksum CRC32 value with all transitions table entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @param transitions transition table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @param offsets offset value table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @param simpleTimeZoneParams parameter values for constructing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * SimpleTimeZone
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @param willGMTOffsetChange the value of willGMTOffsetChange
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    ZoneInfo(String ID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
             int rawOffset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
             int dstSavings,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
             int checksum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
             long[] transitions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
             int[] offsets,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
             int[] simpleTimeZoneParams,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
             boolean willGMTOffsetChange) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        setID(ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        this.rawOffset = rawOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        this.dstSavings = dstSavings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        this.checksum = checksum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        this.transitions = transitions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        this.offsets = offsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        this.simpleTimeZoneParams = simpleTimeZoneParams;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        this.willGMTOffsetChange = willGMTOffsetChange;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * Returns the difference in milliseconds between local time and UTC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * of given time, taking into account both the raw offset and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * effect of daylight savings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @param date the milliseconds in UTC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @return the milliseconds to add to UTC to get local wall time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    public int getOffset(long date) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        return getOffsets(date, null, UTC_TIME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public int getOffsets(long utc, int[] offsets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        return getOffsets(utc, offsets, UTC_TIME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public int getOffsetsByStandard(long standard, int[] offsets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        return getOffsets(standard, offsets, STANDARD_TIME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public int getOffsetsByWall(long wall, int[] offsets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        return getOffsets(wall, offsets, WALL_TIME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    private int getOffsets(long date, int[] offsets, int type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        // if dst is never observed, there is no transition.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        if (transitions == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            int offset = getLastRawOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            if (offsets != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                offsets[0] = offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                offsets[1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            return offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        date -= rawOffsetDiff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        int index = getTransitionIndex(date, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        // prior to the transition table, returns the raw offset.
8522
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   254
        // FIXME: should support LMT.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        if (index < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            int offset = getLastRawOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            if (offsets != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                offsets[0] = offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                offsets[1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            return offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        if (index < transitions.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            long val = transitions[index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            int offset = this.offsets[(int)(val & OFFSET_MASK)] + rawOffsetDiff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            if (offsets != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                int dst = (int)((val >>> DST_NSHIFT) & 0xfL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                int save = (dst == 0) ? 0 : this.offsets[dst];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                offsets[0] = offset - save;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                offsets[1] = save;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            return offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        // beyond the transitions, delegate to SimpleTimeZone if there
57544
99d2dd7b84a8 8212970: TZ database in "vanguard" format support
naoto
parents: 47216
diff changeset
   277
        // is a rule; otherwise, return the offset of the last transition.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        SimpleTimeZone tz = getLastRule();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        if (tz != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            int rawoffset = tz.getRawOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            long msec = date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            if (type != UTC_TIME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                msec -= rawOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            }
8523
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents: 8522
diff changeset
   285
            int dstoffset = tz.getOffset(msec) - rawOffset;
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents: 8522
diff changeset
   286
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents: 8522
diff changeset
   287
            // Check if it's in a standard-to-daylight transition.
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents: 8522
diff changeset
   288
            if (dstoffset > 0 && tz.getOffset(msec - dstoffset) == rawoffset) {
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents: 8522
diff changeset
   289
                dstoffset = 0;
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents: 8522
diff changeset
   290
            }
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents: 8522
diff changeset
   291
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            if (offsets != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                offsets[0] = rawoffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                offsets[1] = dstoffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            return rawoffset + dstoffset;
57544
99d2dd7b84a8 8212970: TZ database in "vanguard" format support
naoto
parents: 47216
diff changeset
   297
        } else {
99d2dd7b84a8 8212970: TZ database in "vanguard" format support
naoto
parents: 47216
diff changeset
   298
            // use the last transition
99d2dd7b84a8 8212970: TZ database in "vanguard" format support
naoto
parents: 47216
diff changeset
   299
            long val = transitions[transitions.length - 1];
99d2dd7b84a8 8212970: TZ database in "vanguard" format support
naoto
parents: 47216
diff changeset
   300
            int offset = this.offsets[(int)(val & OFFSET_MASK)] + rawOffsetDiff;
99d2dd7b84a8 8212970: TZ database in "vanguard" format support
naoto
parents: 47216
diff changeset
   301
            if (offsets != null) {
99d2dd7b84a8 8212970: TZ database in "vanguard" format support
naoto
parents: 47216
diff changeset
   302
                int dst = (int)((val >>> DST_NSHIFT) & 0xfL);
99d2dd7b84a8 8212970: TZ database in "vanguard" format support
naoto
parents: 47216
diff changeset
   303
                int save = (dst == 0) ? 0 : this.offsets[dst];
99d2dd7b84a8 8212970: TZ database in "vanguard" format support
naoto
parents: 47216
diff changeset
   304
                offsets[0] = offset - save;
99d2dd7b84a8 8212970: TZ database in "vanguard" format support
naoto
parents: 47216
diff changeset
   305
                offsets[1] = save;
99d2dd7b84a8 8212970: TZ database in "vanguard" format support
naoto
parents: 47216
diff changeset
   306
            }
99d2dd7b84a8 8212970: TZ database in "vanguard" format support
naoto
parents: 47216
diff changeset
   307
            return offset;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
11130
c7093e306a34 7117487: Warnings Cleanup: some i18n classes in java.util and sun.util
okutsu
parents: 8523
diff changeset
   311
    private int getTransitionIndex(long date, int type) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        int low = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        int high = transitions.length - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        while (low <= high) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            int mid = (low + high) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            long val = transitions[mid];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            long midVal = val >> TRANSITION_NSHIFT; // sign extended
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            if (type != UTC_TIME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                midVal += offsets[(int)(val & OFFSET_MASK)]; // wall time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            if (type == STANDARD_TIME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                int dstIndex = (int)((val >>> DST_NSHIFT) & 0xfL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                if (dstIndex != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                    midVal -= offsets[dstIndex]; // make it standard time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            if (midVal < date) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                low = mid + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            } else if (midVal > date) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                high = mid - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                return mid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        // if beyond the transitions, returns that index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        if (low >= transitions.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            return low;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        return low - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * Returns the difference in milliseconds between local time and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * UTC, taking into account both the raw offset and the effect of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * daylight savings, for the specified date and time.  This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * assumes that the start and end month are distinct.  This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * assumes a Gregorian calendar for calculations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * <em>Note: In general, clients should use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * {@link Calendar#ZONE_OFFSET Calendar.get(ZONE_OFFSET)} +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * {@link Calendar#DST_OFFSET Calendar.get(DST_OFFSET)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * instead of calling this method.</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * @param era       The era of the given date. The value must be either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     *                  GregorianCalendar.AD or GregorianCalendar.BC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * @param year      The year in the given date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * @param month     The month in the given date. Month is 0-based. e.g.,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     *                  0 for January.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * @param day       The day-in-month of the given date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * @param dayOfWeek The day-of-week of the given date.
31061
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
   364
     * @param milliseconds The milliseconds in day in <em>standard</em> local time.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * @return The milliseconds to add to UTC to get local time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    public int getOffset(int era, int year, int month, int day,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                         int dayOfWeek, int milliseconds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        if (milliseconds < 0 || milliseconds >= AbstractCalendar.DAY_IN_MILLIS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        if (era == java.util.GregorianCalendar.BC) { // BC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            year = 1 - year;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        } else if (era != java.util.GregorianCalendar.AD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
40541
8850531a2beb 8164669: Lazier initialization of java.time
redestad
parents: 32649
diff changeset
   379
        Gregorian gcal = CalendarSystem.getGregorianCalendar();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        CalendarDate date = gcal.newCalendarDate(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        date.setDate(year, month + 1, day);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        if (gcal.validate(date) == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        // bug-for-bug compatible argument checking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        if (dayOfWeek < java.util.GregorianCalendar.SUNDAY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            || dayOfWeek > java.util.GregorianCalendar.SATURDAY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        if (transitions == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            return getLastRawOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        long dateInMillis = gcal.getTime(date) + milliseconds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        dateInMillis -= (long) rawOffset; // make it UTC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        return getOffsets(dateInMillis, null, UTC_TIME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * Sets the base time zone offset from GMT. This operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * modifies all the transitions of this ZoneInfo object, including
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * historical ones, if applicable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * @param offsetMillis the base time zone offset to GMT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * @see getRawOffset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    public synchronized void setRawOffset(int offsetMillis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        if (offsetMillis == rawOffset + rawOffsetDiff) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        rawOffsetDiff = offsetMillis - rawOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        if (lastRule != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            lastRule.setRawOffset(offsetMillis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        dirty = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * Returns the GMT offset of the current date. This GMT offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * value is not modified during Daylight Saving Time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * @return the GMT offset value in milliseconds to add to UTC time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * to get local standard time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    public int getRawOffset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        if (!willGMTOffsetChange) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            return rawOffset + rawOffsetDiff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        int[] offsets = new int[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        getOffsets(System.currentTimeMillis(), offsets, UTC_TIME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        return offsets[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    public boolean isDirty() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        return dirty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    private int getLastRawOffset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        return rawOffset + rawOffsetDiff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * Queries if this time zone uses Daylight Saving Time in the last known rule.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    public boolean useDaylightTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        return (simpleTimeZoneParams != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
8522
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   452
    @Override
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   453
    public boolean observesDaylightTime() {
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   454
        if (simpleTimeZoneParams != null) {
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   455
            return true;
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   456
        }
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   457
        if (transitions == null) {
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   458
            return false;
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   459
        }
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   460
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   461
        // Look up the transition table to see if it's in DST right
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   462
        // now or if there's any standard-to-daylight transition at
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   463
        // any future.
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   464
        long utc = System.currentTimeMillis() - rawOffsetDiff;
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   465
        int index = getTransitionIndex(utc, UTC_TIME);
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   466
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   467
        // before transitions in the transition table
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   468
        if (index < 0) {
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   469
            return false;
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   470
        }
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   471
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   472
        // the time is in the table range.
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   473
        for (int i = index; i < transitions.length; i++) {
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   474
            if ((transitions[i] & DST_MASK) != 0) {
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   475
                return true;
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   476
            }
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   477
        }
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   478
        // No further DST is observed.
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   479
        return false;
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   480
    }
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   481
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * Queries if the specified date is in Daylight Saving Time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    public boolean inDaylightTime(Date date) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        if (date == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        if (transitions == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        long utc = date.getTime() - rawOffsetDiff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        int index = getTransitionIndex(utc, UTC_TIME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        // before transitions in the transition table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        if (index < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        // the time is in the table range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        if (index < transitions.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            return (transitions[index] & DST_MASK) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        // beyond the transition table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        SimpleTimeZone tz = getLastRule();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        if (tz != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            return tz.inDaylightTime(date);
57544
99d2dd7b84a8 8212970: TZ database in "vanguard" format support
naoto
parents: 47216
diff changeset
   511
        } else {
99d2dd7b84a8 8212970: TZ database in "vanguard" format support
naoto
parents: 47216
diff changeset
   512
            // use the last transition
99d2dd7b84a8 8212970: TZ database in "vanguard" format support
naoto
parents: 47216
diff changeset
   513
            return (transitions[transitions.length - 1] & DST_MASK) != 0;
99d2dd7b84a8 8212970: TZ database in "vanguard" format support
naoto
parents: 47216
diff changeset
   514
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * Returns the amount of time in milliseconds that the clock is advanced
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * during daylight saving time is in effect in its last daylight saving time rule.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * @return the number of milliseconds the time is advanced with respect to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * standard time when daylight saving time is in effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    public int getDSTSavings() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        return dstSavings;
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
//     * @return the last year in the transition table or -1 if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
//     * time zone doesn't observe any daylight saving time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
//     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
//    public int getMaxTransitionYear() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
//      if (transitions == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
//          return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
//      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
//      long val = transitions[transitions.length - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
//      int offset = this.offsets[(int)(val & OFFSET_MASK)] + rawOffsetDiff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
//      val = (val >> TRANSITION_NSHIFT) + offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
//      CalendarDate lastDate = Gregorian.getCalendarDate(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
//      return lastDate.getYear();
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
     * Returns a string representation of this time zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * @return the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        return getClass().getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            "[id=\"" + getID() + "\"" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            ",offset=" + getLastRawOffset() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            ",dstSavings=" + dstSavings +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            ",useDaylight=" + useDaylightTime() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            ",transitions=" + ((transitions != null) ? transitions.length : 0) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            ",lastRule=" + (lastRule == null ? getLastRuleInstance() : lastRule) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * Gets all available IDs supported in the Java run-time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * @return an array of time zone IDs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    public static String[] getAvailableIDs() {
16852
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents: 15658
diff changeset
   564
        return ZoneInfoFile.getZoneIds();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * Gets all available IDs that have the same value as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * specified raw GMT offset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * @param rawOffset the GMT offset in milliseconds. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * value should not include any daylight saving time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * @return an array of time zone IDs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    public static String[] getAvailableIDs(int rawOffset) {
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11986
diff changeset
   577
        return ZoneInfoFile.getZoneIds(rawOffset);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * Gets the ZoneInfo for the given ID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * @param ID the ID for a ZoneInfo. See TimeZone for detail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * @return the specified ZoneInfo object, or null if there is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * time zone of the ID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    public static TimeZone getTimeZone(String ID) {
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11986
diff changeset
   589
        return ZoneInfoFile.getZoneInfo(ID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    private transient SimpleTimeZone lastRule;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * Returns a SimpleTimeZone object representing the last GMT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * offset and DST schedule or null if this time zone doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * observe DST.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    private synchronized SimpleTimeZone getLastRule() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        if (lastRule == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            lastRule = getLastRuleInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        return lastRule;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * Returns a SimpleTimeZone object that represents the last
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * known daylight saving time rules.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * @return a SimpleTimeZone object or null if this time zone
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * doesn't observe DST.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    public SimpleTimeZone getLastRuleInstance() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        if (simpleTimeZoneParams == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        if (simpleTimeZoneParams.length == 10) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            return new SimpleTimeZone(getLastRawOffset(), getID(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                                      simpleTimeZoneParams[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                                      simpleTimeZoneParams[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                                      simpleTimeZoneParams[2],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                                      simpleTimeZoneParams[3],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                                      simpleTimeZoneParams[4],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                                      simpleTimeZoneParams[5],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                                      simpleTimeZoneParams[6],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                                      simpleTimeZoneParams[7],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                                      simpleTimeZoneParams[8],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                                      simpleTimeZoneParams[9],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                                      dstSavings);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        return new SimpleTimeZone(getLastRawOffset(), getID(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                                  simpleTimeZoneParams[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                                  simpleTimeZoneParams[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                                  simpleTimeZoneParams[2],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                                  simpleTimeZoneParams[3],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                                  simpleTimeZoneParams[4],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                                  simpleTimeZoneParams[5],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                                  simpleTimeZoneParams[6],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                                  simpleTimeZoneParams[7],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                                  dstSavings);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * Returns a copy of this <code>ZoneInfo</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        ZoneInfo zi = (ZoneInfo) super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        zi.lastRule = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        return zi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * Returns a hash code value calculated from the GMT offset and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * transitions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * @return a hash code of this time zone
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        return getLastRawOffset() ^ checksum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * Compares the equity of two ZoneInfo objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * @param obj the object to be compared with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * @return true if given object is same as this ZoneInfo object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        if (this == obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        if (!(obj instanceof ZoneInfo)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        ZoneInfo that = (ZoneInfo) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        return (getID().equals(that.getID())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                && (getLastRawOffset() == that.getLastRawOffset())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                && (checksum == that.checksum));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * Returns true if this zone has the same raw GMT offset value and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * transition table as another zone info. If the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * TimeZone object is not a ZoneInfo instance, this method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * true if the specified TimeZone object has the same raw GMT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * offset value with no daylight saving time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * @param other the ZoneInfo object to be compared with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * @return true if the given <code>TimeZone</code> has the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * GMT offset and transition information; false, otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    public boolean hasSameRules(TimeZone other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        if (this == other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        if (other == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        if (!(other instanceof ZoneInfo)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            if (getRawOffset() != other.getRawOffset()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            // if both have the same raw offset and neither observes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            // DST, they have the same rule.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            if ((transitions == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                && (useDaylightTime() == false)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                && (other.useDaylightTime() == false)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        if (getLastRawOffset() != ((ZoneInfo)other).getLastRawOffset()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        return (checksum == ((ZoneInfo)other).checksum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * Returns a Map from alias time zone IDs to their standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * time zone IDs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * @return the Map that holds the mappings from alias time zone IDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     *    to their standard time zone IDs, or null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     *    <code>ZoneInfoMappings</code> file is not available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     */
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11986
diff changeset
   726
    public static Map<String, String> getAliasTable() {
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11986
diff changeset
   727
         return ZoneInfoFile.getAliasMap();
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11986
diff changeset
   728
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
57956
e0b8b019d2f5 8229997: Apply java.io.Serial annotations in java.base
darcy
parents: 57544
diff changeset
   730
    @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
    private void readObject(ObjectInputStream stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            throws IOException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        stream.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        // We don't know how this object from 1.4.x or earlier has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        // been mutated. So it should always be marked as `dirty'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        dirty = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
}