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