src/java.base/share/classes/sun/util/calendar/ZoneInfo.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 40541 jdk/src/java.base/share/classes/sun/util/calendar/ZoneInfo.java@8850531a2beb
child 57544 99d2dd7b84a8
child 58678 9cf78a70fa4f
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 16852
diff changeset
     2
 * Copyright (c) 2000, 2013, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    private static final long serialVersionUID = 2653134537216586139L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * A constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    public ZoneInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * A Constructor for CustomID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    public ZoneInfo(String ID, int rawOffset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        this(ID, rawOffset, 0, 0, null, null, null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * Constructs a ZoneInfo instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @param ID time zone name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @param rawOffset GMT offset in milliseconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @param dstSavings daylight saving value in milliseconds or 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * (zero) if this time zone doesn't observe Daylight Saving Time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @param checksum CRC32 value with all transitions table entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @param transitions transition table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @param offsets offset value table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @param simpleTimeZoneParams parameter values for constructing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * SimpleTimeZone
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @param willGMTOffsetChange the value of willGMTOffsetChange
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    ZoneInfo(String ID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
             int rawOffset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
             int dstSavings,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
             int checksum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
             long[] transitions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
             int[] offsets,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
             int[] simpleTimeZoneParams,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
             boolean willGMTOffsetChange) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        setID(ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        this.rawOffset = rawOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        this.dstSavings = dstSavings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        this.checksum = checksum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        this.transitions = transitions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        this.offsets = offsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        this.simpleTimeZoneParams = simpleTimeZoneParams;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        this.willGMTOffsetChange = willGMTOffsetChange;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * Returns the difference in milliseconds between local time and UTC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * of given time, taking into account both the raw offset and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * effect of daylight savings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @param date the milliseconds in UTC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @return the milliseconds to add to UTC to get local wall time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public int getOffset(long date) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        return getOffsets(date, null, UTC_TIME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public int getOffsets(long utc, int[] offsets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        return getOffsets(utc, offsets, UTC_TIME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    public int getOffsetsByStandard(long standard, int[] offsets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        return getOffsets(standard, offsets, STANDARD_TIME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public int getOffsetsByWall(long wall, int[] offsets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        return getOffsets(wall, offsets, WALL_TIME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    private int getOffsets(long date, int[] offsets, int type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        // if dst is never observed, there is no transition.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if (transitions == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            int offset = getLastRawOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            if (offsets != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                offsets[0] = offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                offsets[1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            return offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        date -= rawOffsetDiff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        int index = getTransitionIndex(date, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        // prior to the transition table, returns the raw offset.
8522
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   253
        // FIXME: should support LMT.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        if (index < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            int offset = getLastRawOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            if (offsets != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                offsets[0] = offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                offsets[1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            return offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        if (index < transitions.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            long val = transitions[index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            int offset = this.offsets[(int)(val & OFFSET_MASK)] + rawOffsetDiff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            if (offsets != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                int dst = (int)((val >>> DST_NSHIFT) & 0xfL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                int save = (dst == 0) ? 0 : this.offsets[dst];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                offsets[0] = offset - save;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                offsets[1] = save;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            return offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        // beyond the transitions, delegate to SimpleTimeZone if there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        // is a rule; otherwise, return rawOffset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        SimpleTimeZone tz = getLastRule();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        if (tz != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            int rawoffset = tz.getRawOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            long msec = date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            if (type != UTC_TIME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                msec -= rawOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            }
8523
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents: 8522
diff changeset
   284
            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
   285
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents: 8522
diff changeset
   286
            // 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
   287
            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
   288
                dstoffset = 0;
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents: 8522
diff changeset
   289
            }
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents: 8522
diff changeset
   290
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            if (offsets != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                offsets[0] = rawoffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                offsets[1] = dstoffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            return rawoffset + dstoffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        int offset = getLastRawOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        if (offsets != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            offsets[0] = offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            offsets[1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        return offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
11130
c7093e306a34 7117487: Warnings Cleanup: some i18n classes in java.util and sun.util
okutsu
parents: 8523
diff changeset
   305
    private int getTransitionIndex(long date, int type) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        int low = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        int high = transitions.length - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        while (low <= high) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            int mid = (low + high) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            long val = transitions[mid];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            long midVal = val >> TRANSITION_NSHIFT; // sign extended
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            if (type != UTC_TIME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                midVal += offsets[(int)(val & OFFSET_MASK)]; // wall time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            if (type == STANDARD_TIME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                int dstIndex = (int)((val >>> DST_NSHIFT) & 0xfL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                if (dstIndex != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                    midVal -= offsets[dstIndex]; // make it standard time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            if (midVal < date) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                low = mid + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            } else if (midVal > date) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                high = mid - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                return mid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        // if beyond the transitions, returns that index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        if (low >= transitions.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            return low;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        return low - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * Returns the difference in milliseconds between local time and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * UTC, taking into account both the raw offset and the effect of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * daylight savings, for the specified date and time.  This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * assumes that the start and end month are distinct.  This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * assumes a Gregorian calendar for calculations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * <em>Note: In general, clients should use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * {@link Calendar#ZONE_OFFSET Calendar.get(ZONE_OFFSET)} +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * {@link Calendar#DST_OFFSET Calendar.get(DST_OFFSET)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * instead of calling this method.</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @param era       The era of the given date. The value must be either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     *                  GregorianCalendar.AD or GregorianCalendar.BC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @param year      The year in the given date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @param month     The month in the given date. Month is 0-based. e.g.,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     *                  0 for January.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * @param day       The day-in-month of the given date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * @param dayOfWeek The day-of-week of the given date.
31061
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
   358
     * @param milliseconds The milliseconds in day in <em>standard</em> local time.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * @return The milliseconds to add to UTC to get local time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    public int getOffset(int era, int year, int month, int day,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                         int dayOfWeek, int milliseconds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        if (milliseconds < 0 || milliseconds >= AbstractCalendar.DAY_IN_MILLIS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        if (era == java.util.GregorianCalendar.BC) { // BC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            year = 1 - year;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        } else if (era != java.util.GregorianCalendar.AD) {
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
40541
8850531a2beb 8164669: Lazier initialization of java.time
redestad
parents: 32649
diff changeset
   373
        Gregorian gcal = CalendarSystem.getGregorianCalendar();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        CalendarDate date = gcal.newCalendarDate(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        date.setDate(year, month + 1, day);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        if (gcal.validate(date) == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        // bug-for-bug compatible argument checking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        if (dayOfWeek < java.util.GregorianCalendar.SUNDAY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            || dayOfWeek > java.util.GregorianCalendar.SATURDAY) {
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
        if (transitions == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            return getLastRawOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        long dateInMillis = gcal.getTime(date) + milliseconds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        dateInMillis -= (long) rawOffset; // make it UTC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        return getOffsets(dateInMillis, null, UTC_TIME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * Sets the base time zone offset from GMT. This operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * modifies all the transitions of this ZoneInfo object, including
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * historical ones, if applicable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * @param offsetMillis the base time zone offset to GMT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * @see getRawOffset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    public synchronized void setRawOffset(int offsetMillis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        if (offsetMillis == rawOffset + rawOffsetDiff) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        rawOffsetDiff = offsetMillis - rawOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        if (lastRule != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            lastRule.setRawOffset(offsetMillis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        dirty = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * Returns the GMT offset of the current date. This GMT offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * value is not modified during Daylight Saving Time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * @return the GMT offset value in milliseconds to add to UTC time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * to get local standard time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    public int getRawOffset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        if (!willGMTOffsetChange) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            return rawOffset + rawOffsetDiff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        int[] offsets = new int[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        getOffsets(System.currentTimeMillis(), offsets, UTC_TIME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        return offsets[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    public boolean isDirty() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        return dirty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    private int getLastRawOffset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        return rawOffset + rawOffsetDiff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * Queries if this time zone uses Daylight Saving Time in the last known rule.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    public boolean useDaylightTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        return (simpleTimeZoneParams != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
8522
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   446
    @Override
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   447
    public boolean observesDaylightTime() {
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   448
        if (simpleTimeZoneParams != null) {
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   449
            return true;
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   450
        }
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   451
        if (transitions == null) {
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   452
            return false;
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   453
        }
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   454
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   455
        // 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
   456
        // now or if there's any standard-to-daylight transition at
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   457
        // any future.
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   458
        long utc = System.currentTimeMillis() - rawOffsetDiff;
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   459
        int index = getTransitionIndex(utc, UTC_TIME);
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
        // before transitions in the transition table
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   462
        if (index < 0) {
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   463
            return false;
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   464
        }
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   465
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   466
        // the time is in the table range.
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   467
        for (int i = index; i < transitions.length; i++) {
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   468
            if ((transitions[i] & DST_MASK) != 0) {
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   469
                return true;
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
        // No further DST is observed.
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   473
        return false;
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   474
    }
281cf853ef7a 7021989: Missing observesDaylightTime override in ZoneInfo
okutsu
parents: 5506
diff changeset
   475
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * Queries if the specified date is in Daylight Saving Time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    public boolean inDaylightTime(Date date) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        if (date == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        if (transitions == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        long utc = date.getTime() - rawOffsetDiff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        int index = getTransitionIndex(utc, UTC_TIME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        // before transitions in the transition table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        if (index < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        // the time is in the table range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        if (index < transitions.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            return (transitions[index] & DST_MASK) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        // beyond the transition table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        SimpleTimeZone tz = getLastRule();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        if (tz != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            return tz.inDaylightTime(date);
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11986
diff changeset
   505
       }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * Returns the amount of time in milliseconds that the clock is advanced
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * during daylight saving time is in effect in its last daylight saving time rule.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * @return the number of milliseconds the time is advanced with respect to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * standard time when daylight saving time is in effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    public int getDSTSavings() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        return dstSavings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
//    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
//     * @return the last year in the transition table or -1 if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
//     * time zone doesn't observe any daylight saving time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
//     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
//    public int getMaxTransitionYear() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
//      if (transitions == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
//          return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
//      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
//      long val = transitions[transitions.length - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
//      int offset = this.offsets[(int)(val & OFFSET_MASK)] + rawOffsetDiff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
//      val = (val >> TRANSITION_NSHIFT) + offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
//      CalendarDate lastDate = Gregorian.getCalendarDate(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
//      return lastDate.getYear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
//    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * Returns a string representation of this time zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * @return the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        return getClass().getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            "[id=\"" + getID() + "\"" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            ",offset=" + getLastRawOffset() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            ",dstSavings=" + dstSavings +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            ",useDaylight=" + useDaylightTime() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            ",transitions=" + ((transitions != null) ? transitions.length : 0) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            ",lastRule=" + (lastRule == null ? getLastRuleInstance() : lastRule) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * Gets all available IDs supported in the Java run-time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * @return an array of time zone IDs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    public static String[] getAvailableIDs() {
16852
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents: 15658
diff changeset
   556
        return ZoneInfoFile.getZoneIds();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * Gets all available IDs that have the same value as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * specified raw GMT offset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * @param rawOffset the GMT offset in milliseconds. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * value should not include any daylight saving time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * @return an array of time zone IDs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    public static String[] getAvailableIDs(int rawOffset) {
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11986
diff changeset
   569
        return ZoneInfoFile.getZoneIds(rawOffset);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * Gets the ZoneInfo for the given ID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * @param ID the ID for a ZoneInfo. See TimeZone for detail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * @return the specified ZoneInfo object, or null if there is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * time zone of the ID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    public static TimeZone getTimeZone(String ID) {
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11986
diff changeset
   581
        return ZoneInfoFile.getZoneInfo(ID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    private transient SimpleTimeZone lastRule;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * Returns a SimpleTimeZone object representing the last GMT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * offset and DST schedule or null if this time zone doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * observe DST.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    private synchronized SimpleTimeZone getLastRule() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        if (lastRule == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            lastRule = getLastRuleInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        return lastRule;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * Returns a SimpleTimeZone object that represents the last
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * known daylight saving time rules.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * @return a SimpleTimeZone object or null if this time zone
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * doesn't observe DST.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    public SimpleTimeZone getLastRuleInstance() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        if (simpleTimeZoneParams == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        if (simpleTimeZoneParams.length == 10) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            return new SimpleTimeZone(getLastRawOffset(), getID(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                                      simpleTimeZoneParams[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                                      simpleTimeZoneParams[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                                      simpleTimeZoneParams[2],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                                      simpleTimeZoneParams[3],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                                      simpleTimeZoneParams[4],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                                      simpleTimeZoneParams[5],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                                      simpleTimeZoneParams[6],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                                      simpleTimeZoneParams[7],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                                      simpleTimeZoneParams[8],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                                      simpleTimeZoneParams[9],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                                      dstSavings);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        return new SimpleTimeZone(getLastRawOffset(), getID(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                                  simpleTimeZoneParams[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                                  simpleTimeZoneParams[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                                  simpleTimeZoneParams[2],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                                  simpleTimeZoneParams[3],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                                  simpleTimeZoneParams[4],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                                  simpleTimeZoneParams[5],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                                  simpleTimeZoneParams[6],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                                  simpleTimeZoneParams[7],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                                  dstSavings);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * Returns a copy of this <code>ZoneInfo</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        ZoneInfo zi = (ZoneInfo) super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        zi.lastRule = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        return zi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * Returns a hash code value calculated from the GMT offset and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * transitions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * @return a hash code of this time zone
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        return getLastRawOffset() ^ checksum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * Compares the equity of two ZoneInfo objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * @param obj the object to be compared with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * @return true if given object is same as this ZoneInfo object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        if (this == obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        if (!(obj instanceof ZoneInfo)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        ZoneInfo that = (ZoneInfo) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        return (getID().equals(that.getID())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                && (getLastRawOffset() == that.getLastRawOffset())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                && (checksum == that.checksum));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * Returns true if this zone has the same raw GMT offset value and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * transition table as another zone info. If the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * TimeZone object is not a ZoneInfo instance, this method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * true if the specified TimeZone object has the same raw GMT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * offset value with no daylight saving time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * @param other the ZoneInfo object to be compared with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * @return true if the given <code>TimeZone</code> has the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * GMT offset and transition information; false, otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    public boolean hasSameRules(TimeZone other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        if (this == other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        if (other == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        if (!(other instanceof ZoneInfo)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            if (getRawOffset() != other.getRawOffset()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            // if both have the same raw offset and neither observes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            // DST, they have the same rule.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            if ((transitions == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                && (useDaylightTime() == false)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                && (other.useDaylightTime() == false)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        if (getLastRawOffset() != ((ZoneInfo)other).getLastRawOffset()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        return (checksum == ((ZoneInfo)other).checksum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * Returns a Map from alias time zone IDs to their standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * time zone IDs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * @return the Map that holds the mappings from alias time zone IDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     *    to their standard time zone IDs, or null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     *    <code>ZoneInfoMappings</code> file is not available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     */
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11986
diff changeset
   718
    public static Map<String, String> getAliasTable() {
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11986
diff changeset
   719
         return ZoneInfoFile.getAliasMap();
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11986
diff changeset
   720
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    private void readObject(ObjectInputStream stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            throws IOException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        stream.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        // We don't know how this object from 1.4.x or earlier has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        // been mutated. So it should always be marked as `dirty'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        dirty = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
}