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