src/java.base/share/classes/java/util/TimeZone.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58288 48e480e56aad
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
54206
003cc64366da 8220249: fix headings in java.compiler
jjg
parents: 50817
diff changeset
     2
 * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * (C) Copyright Taligent, Inc. 1996 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * (C) Copyright IBM Corp. 1996 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *   The original version of this source code and documentation is copyrighted
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * materials are provided under terms of a License Agreement between Taligent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * and Sun. This technology is protected by multiple US and International
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * patents. This notice and attribution to Taligent may not be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *   Taligent is a registered trademark of Taligent, Inc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
package java.util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.io.Serializable;
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15260
diff changeset
    42
import java.time.ZoneId;
50817
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 49939
diff changeset
    43
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 49939
diff changeset
    44
import jdk.internal.util.StaticProperty;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import sun.security.action.GetPropertyAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import sun.util.calendar.ZoneInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import sun.util.calendar.ZoneInfoFile;
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14169
diff changeset
    48
import sun.util.locale.provider.TimeZoneNameUtility;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
/**
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
    51
 * {@code TimeZone} represents a time zone offset, and also figures out daylight
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * savings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <p>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
    55
 * Typically, you get a {@code TimeZone} using {@code getDefault}
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
    56
 * which creates a {@code TimeZone} based on the time zone where the program
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
    57
 * is running. For example, for a program running in Japan, {@code getDefault}
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
    58
 * creates a {@code TimeZone} object based on Japanese Standard Time.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <p>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
    61
 * You can also get a {@code TimeZone} using {@code getTimeZone}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * along with a time zone ID. For instance, the time zone ID for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * U.S. Pacific Time zone is "America/Los_Angeles". So, you can get a
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
    64
 * U.S. Pacific Time {@code TimeZone} object with:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * </pre></blockquote>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
    68
 * You can use the {@code getAvailableIDs} method to iterate through
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * all the supported time zone IDs. You can then choose a
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
    70
 * supported ID to get a {@code TimeZone}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * If the time zone you want is not represented by one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * supported IDs, then a custom time zone ID can be specified to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * produce a TimeZone. The syntax of a custom time zone ID is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * <blockquote><pre>
44844
b2b4d98404ba 8179364: update "<a name=" in java.base module to use id attribute
jjg
parents: 37781
diff changeset
    76
 * <a id="CustomID"><i>CustomID:</i></a>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
    77
 *         {@code GMT} <i>Sign</i> <i>Hours</i> {@code :} <i>Minutes</i>
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
    78
 *         {@code GMT} <i>Sign</i> <i>Hours</i> <i>Minutes</i>
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
    79
 *         {@code GMT} <i>Sign</i> <i>Hours</i>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * <i>Sign:</i> one of
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
    81
 *         {@code + -}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * <i>Hours:</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *         <i>Digit</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *         <i>Digit</i> <i>Digit</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * <i>Minutes:</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *         <i>Digit</i> <i>Digit</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * <i>Digit:</i> one of
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
    88
 *         {@code 0 1 2 3 4 5 6 7 8 9}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * <i>Hours</i> must be between 0 to 23 and <i>Minutes</i> must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * between 00 to 59.  For example, "GMT+10" and "GMT+0010" mean ten
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * hours and ten minutes ahead of GMT, respectively.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * The format is locale independent and digits must be taken from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * Basic Latin block of the Unicode standard. No daylight saving time
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * transition schedule can be specified with a custom time zone ID. If
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
    98
 * the specified string doesn't match the syntax, {@code "GMT"}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * <p>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   101
 * When creating a {@code TimeZone}, the specified custom time
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * zone ID is normalized in the following syntax:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * <blockquote><pre>
44844
b2b4d98404ba 8179364: update "<a name=" in java.base module to use id attribute
jjg
parents: 37781
diff changeset
   104
 * <a id="NormalizedCustomID"><i>NormalizedCustomID:</i></a>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   105
 *         {@code GMT} <i>Sign</i> <i>TwoDigitHours</i> {@code :} <i>Minutes</i>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * <i>Sign:</i> one of
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   107
 *         {@code + -}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * <i>TwoDigitHours:</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 *         <i>Digit</i> <i>Digit</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * <i>Minutes:</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 *         <i>Digit</i> <i>Digit</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * <i>Digit:</i> one of
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   113
 *         {@code 0 1 2 3 4 5 6 7 8 9}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * For example, TimeZone.getTimeZone("GMT-8").getID() returns "GMT-08:00".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 *
54206
003cc64366da 8220249: fix headings in java.compiler
jjg
parents: 50817
diff changeset
   117
 * <h2>Three-letter time zone IDs</h2>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * For compatibility with JDK 1.1.x, some other three-letter time zone IDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * (such as "PST", "CTT", "AST") are also supported. However, <strong>their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * use is deprecated</strong> because the same abbreviation is often used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * for multiple time zones (for example, "CST" could be U.S. "Central Standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * Time" and "China Standard Time"), and the Java platform can then only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * recognize one of them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * @see          Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * @see          GregorianCalendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * @see          SimpleTimeZone
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * @author       Mark Davis, David Goldsmith, Chen-Lieh Huang, Alan Liu
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24508
diff changeset
   131
 * @since        1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30644
diff changeset
   133
public abstract class TimeZone implements Serializable, Cloneable {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Sole constructor.  (For invocation by subclass constructors, typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * implicit.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public TimeZone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   142
     * A style specifier for {@code getDisplayName()} indicating
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * a short name, such as "PST."
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @see #LONG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public static final int SHORT = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   150
     * A style specifier for {@code getDisplayName()} indicating
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * a long name, such as "Pacific Standard Time."
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @see #SHORT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    public static final int LONG  = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    // Constants used internally; unit is milliseconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    private static final int ONE_MINUTE = 60*1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    private static final int ONE_HOUR   = 60*ONE_MINUTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    private static final int ONE_DAY    = 24*ONE_HOUR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    // Proclaim serialization compatibility with JDK 1.1
57956
e0b8b019d2f5 8229997: Apply java.io.Serial annotations in java.base
darcy
parents: 54206
diff changeset
   163
    @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    static final long serialVersionUID = 3581463369166924961L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Gets the time zone offset, for current date, modified in case of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * daylight savings. This is the offset to add to UTC to get local time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * This method returns a historically correct offset if an
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   171
     * underlying {@code TimeZone} implementation subclass
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * supports historical Daylight Saving Time schedule and GMT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * offset changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @param era the era of the given date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @param year the year in the given date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @param month the month in the given date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * Month is 0-based. e.g., 0 for January.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @param day the day-in-month of the given date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @param dayOfWeek the day-of-week of the given date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @param milliseconds the milliseconds in day in <em>standard</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * local time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @return the offset in milliseconds to add to GMT to get local time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @see Calendar#ZONE_OFFSET
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @see Calendar#DST_OFFSET
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    public abstract int getOffset(int era, int year, int month, int day,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                                  int dayOfWeek, int milliseconds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * Returns the offset of this time zone from UTC at the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * date. If Daylight Saving Time is in effect at the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * date, the offset value is adjusted with the amount of daylight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * saving.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * This method returns a historically correct offset value if an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * underlying TimeZone implementation subclass supports historical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * Daylight Saving Time schedule and GMT offset changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @param date the date represented in milliseconds since January 1, 1970 00:00:00 GMT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @return the amount of time in milliseconds to add to UTC to get local time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @see Calendar#ZONE_OFFSET
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @see Calendar#DST_OFFSET
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public int getOffset(long date) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        if (inDaylightTime(new Date(date))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            return getRawOffset() + getDSTSavings();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        return getRawOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * Gets the raw GMT offset and the amount of daylight saving of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * time zone at the given time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @param date the milliseconds (since January 1, 1970,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * 00:00:00.000 GMT) at which the time zone offset and daylight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * saving amount are found
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 13583
diff changeset
   222
     * @param offsets an array of int where the raw GMT offset
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * (offset[0]) and daylight saving amount (offset[1]) are stored,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * or null if those values are not needed. The method assumes that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * the length of the given array is two or larger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @return the total amount of the raw GMT offset and daylight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * saving at the specified date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @see Calendar#ZONE_OFFSET
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @see Calendar#DST_OFFSET
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    int getOffsets(long date, int[] offsets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        int rawoffset = getRawOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        int dstoffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        if (inDaylightTime(new Date(date))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            dstoffset = getDSTSavings();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        if (offsets != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            offsets[0] = rawoffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            offsets[1] = dstoffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        return rawoffset + dstoffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * Sets the base time zone offset to GMT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * This is the offset to add to UTC to get local time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * <p>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   249
     * If an underlying {@code TimeZone} implementation subclass
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * supports historical GMT offset changes, the specified GMT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * offset is set as the latest GMT offset and the difference from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * the known latest GMT offset value is used to adjust all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * historical GMT offset values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @param offsetMillis the given base time zone offset to GMT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30644
diff changeset
   257
    public abstract void setRawOffset(int offsetMillis);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * Returns the amount of time in milliseconds to add to UTC to get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * standard time in this time zone. Because this value is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * affected by daylight saving time, it is called <I>raw
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * offset</I>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * <p>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   265
     * If an underlying {@code TimeZone} implementation subclass
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * supports historical GMT offset changes, the method returns the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * raw offset value of the current date. In Honolulu, for example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * its raw offset changed from GMT-10:30 to GMT-10:00 in 1947, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * this method always returns -36000000 milliseconds (i.e., -10
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * hours).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * @return the amount of raw offset time in milliseconds to add to UTC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * @see Calendar#ZONE_OFFSET
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    public abstract int getRawOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * Gets the ID of this time zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @return the ID of this time zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    public String getID()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        return ID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * Sets the time zone ID. This does not change any other data in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * the time zone object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @param ID the new time zone ID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    public void setID(String ID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        if (ID == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        this.ID = ID;
30644
cc05b944b2fa 8074002: java.time.ZoneId.systemDefault() should be faster
plevart
parents: 29986
diff changeset
   297
        this.zoneId = null;   // invalidate cache
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    /**
6841
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   301
     * Returns a long standard time name of this {@code TimeZone} suitable for
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   302
     * presentation to the user in the default locale.
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   303
     *
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   304
     * <p>This method is equivalent to:
19074
84a8d23e8f32 8020539: Clean up doclint problems in java.util package, part 2
bpb
parents: 18543
diff changeset
   305
     * <blockquote><pre>
6841
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   306
     * getDisplayName(false, {@link #LONG},
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   307
     *                Locale.getDefault({@link Locale.Category#DISPLAY}))
19074
84a8d23e8f32 8020539: Clean up doclint problems in java.util package, part 2
bpb
parents: 18543
diff changeset
   308
     * </pre></blockquote>
6841
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   309
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * @return the human-readable name of this time zone in the default locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @since 1.2
6841
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   312
     * @see #getDisplayName(boolean, int, Locale)
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   313
     * @see Locale#getDefault(Locale.Category)
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   314
     * @see Locale.Category
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    public final String getDisplayName() {
6841
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   317
        return getDisplayName(false, LONG,
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   318
                              Locale.getDefault(Locale.Category.DISPLAY));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    /**
6841
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   322
     * Returns a long standard time name of this {@code TimeZone} suitable for
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   323
     * presentation to the user in the specified {@code locale}.
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   324
     *
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   325
     * <p>This method is equivalent to:
19074
84a8d23e8f32 8020539: Clean up doclint problems in java.util package, part 2
bpb
parents: 18543
diff changeset
   326
     * <blockquote><pre>
6841
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   327
     * getDisplayName(false, {@link #LONG}, locale)
19074
84a8d23e8f32 8020539: Clean up doclint problems in java.util package, part 2
bpb
parents: 18543
diff changeset
   328
     * </pre></blockquote>
6841
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   329
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @param locale the locale in which to supply the display name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * @return the human-readable name of this time zone in the given locale.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   332
     * @throws    NullPointerException if {@code locale} is {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @since 1.2
6841
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   334
     * @see #getDisplayName(boolean, int, Locale)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    public final String getDisplayName(Locale locale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        return getDisplayName(false, LONG, locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    /**
6841
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   341
     * Returns a name in the specified {@code style} of this {@code TimeZone}
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   342
     * suitable for presentation to the user in the default locale. If the
8521
ab64b8d109b8 6955047: (tz) javadoc for TimeZone.getDisplayName(boolean daylight, int style, Locale locale) is not clear
okutsu
parents: 8375
diff changeset
   343
     * specified {@code daylight} is {@code true}, a Daylight Saving Time name
ab64b8d109b8 6955047: (tz) javadoc for TimeZone.getDisplayName(boolean daylight, int style, Locale locale) is not clear
okutsu
parents: 8375
diff changeset
   344
     * is returned (even if this {@code TimeZone} doesn't observe Daylight Saving
ab64b8d109b8 6955047: (tz) javadoc for TimeZone.getDisplayName(boolean daylight, int style, Locale locale) is not clear
okutsu
parents: 8375
diff changeset
   345
     * Time). Otherwise, a Standard Time name is returned.
6841
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   346
     *
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   347
     * <p>This method is equivalent to:
19074
84a8d23e8f32 8020539: Clean up doclint problems in java.util package, part 2
bpb
parents: 18543
diff changeset
   348
     * <blockquote><pre>
6841
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   349
     * getDisplayName(daylight, style,
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   350
     *                Locale.getDefault({@link Locale.Category#DISPLAY}))
19074
84a8d23e8f32 8020539: Clean up doclint problems in java.util package, part 2
bpb
parents: 18543
diff changeset
   351
     * </pre></blockquote>
6841
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   352
     *
8521
ab64b8d109b8 6955047: (tz) javadoc for TimeZone.getDisplayName(boolean daylight, int style, Locale locale) is not clear
okutsu
parents: 8375
diff changeset
   353
     * @param daylight {@code true} specifying a Daylight Saving Time name, or
ab64b8d109b8 6955047: (tz) javadoc for TimeZone.getDisplayName(boolean daylight, int style, Locale locale) is not clear
okutsu
parents: 8375
diff changeset
   354
     *                 {@code false} specifying a Standard Time name
6841
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   355
     * @param style either {@link #LONG} or {@link #SHORT}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * @return the human-readable name of this time zone in the default locale.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   357
     * @throws    IllegalArgumentException if {@code style} is invalid.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * @since 1.2
6841
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   359
     * @see #getDisplayName(boolean, int, Locale)
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   360
     * @see Locale#getDefault(Locale.Category)
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   361
     * @see Locale.Category
8521
ab64b8d109b8 6955047: (tz) javadoc for TimeZone.getDisplayName(boolean daylight, int style, Locale locale) is not clear
okutsu
parents: 8375
diff changeset
   362
     * @see java.text.DateFormatSymbols#getZoneStrings()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    public final String getDisplayName(boolean daylight, int style) {
6841
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   365
        return getDisplayName(daylight, style,
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   366
                              Locale.getDefault(Locale.Category.DISPLAY));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    /**
6841
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   370
     * Returns a name in the specified {@code style} of this {@code TimeZone}
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   371
     * suitable for presentation to the user in the specified {@code
8521
ab64b8d109b8 6955047: (tz) javadoc for TimeZone.getDisplayName(boolean daylight, int style, Locale locale) is not clear
okutsu
parents: 8375
diff changeset
   372
     * locale}. If the specified {@code daylight} is {@code true}, a Daylight
ab64b8d109b8 6955047: (tz) javadoc for TimeZone.getDisplayName(boolean daylight, int style, Locale locale) is not clear
okutsu
parents: 8375
diff changeset
   373
     * Saving Time name is returned (even if this {@code TimeZone} doesn't
ab64b8d109b8 6955047: (tz) javadoc for TimeZone.getDisplayName(boolean daylight, int style, Locale locale) is not clear
okutsu
parents: 8375
diff changeset
   374
     * observe Daylight Saving Time). Otherwise, a Standard Time name is
6841
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   375
     * returned.
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   376
     *
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   377
     * <p>When looking up a time zone name, the {@linkplain
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   378
     * ResourceBundle.Control#getCandidateLocales(String,Locale) default
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   379
     * {@code Locale} search path of {@code ResourceBundle}} derived
6841
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   380
     * from the specified {@code locale} is used. (No {@linkplain
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   381
     * ResourceBundle.Control#getFallbackLocale(String,Locale) fallback
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   382
     * {@code Locale}} search is performed.) If a time zone name in any
6841
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   383
     * {@code Locale} of the search path, including {@link Locale#ROOT}, is
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   384
     * found, the name is returned. Otherwise, a string in the
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   385
     * <a href="#NormalizedCustomID">normalized custom ID format</a> is returned.
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   386
     *
8521
ab64b8d109b8 6955047: (tz) javadoc for TimeZone.getDisplayName(boolean daylight, int style, Locale locale) is not clear
okutsu
parents: 8375
diff changeset
   387
     * @param daylight {@code true} specifying a Daylight Saving Time name, or
ab64b8d109b8 6955047: (tz) javadoc for TimeZone.getDisplayName(boolean daylight, int style, Locale locale) is not clear
okutsu
parents: 8375
diff changeset
   388
     *                 {@code false} specifying a Standard Time name
6841
3a4f3e399917 6638110: (tz) TimeZone.getDisplayName(...) spec is inconsistent with implementation for unavailable locales
okutsu
parents: 6489
diff changeset
   389
     * @param style either {@link #LONG} or {@link #SHORT}
8521
ab64b8d109b8 6955047: (tz) javadoc for TimeZone.getDisplayName(boolean daylight, int style, Locale locale) is not clear
okutsu
parents: 8375
diff changeset
   390
     * @param locale   the locale in which to supply the display name.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @return the human-readable name of this time zone in the given locale.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   392
     * @throws    IllegalArgumentException if {@code style} is invalid.
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   393
     * @throws    NullPointerException if {@code locale} is {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * @since 1.2
8521
ab64b8d109b8 6955047: (tz) javadoc for TimeZone.getDisplayName(boolean daylight, int style, Locale locale) is not clear
okutsu
parents: 8375
diff changeset
   395
     * @see java.text.DateFormatSymbols#getZoneStrings()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    public String getDisplayName(boolean daylight, int style, Locale locale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        if (style != SHORT && style != LONG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            throw new IllegalArgumentException("Illegal style: " + style);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        String id = getID();
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14169
diff changeset
   402
        String name = TimeZoneNameUtility.retrieveDisplayName(id, daylight, style, locale);
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14169
diff changeset
   403
        if (name != null) {
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14169
diff changeset
   404
            return name;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14169
diff changeset
   407
        if (id.startsWith("GMT") && id.length() > 3) {
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14169
diff changeset
   408
            char sign = id.charAt(3);
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14169
diff changeset
   409
            if (sign == '+' || sign == '-') {
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14169
diff changeset
   410
                return id;
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14169
diff changeset
   411
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        }
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14169
diff changeset
   413
        int offset = getRawOffset();
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14169
diff changeset
   414
        if (daylight) {
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14169
diff changeset
   415
            offset += getDSTSavings();
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14169
diff changeset
   416
        }
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14169
diff changeset
   417
        return ZoneInfoFile.toCustomID(offset);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14169
diff changeset
   420
    private static String[] getDisplayNames(String id, Locale locale) {
15260
7af2d7a87806 7162007: Clean up i18n related caches
naoto
parents: 14765
diff changeset
   421
        return TimeZoneNameUtility.retrieveDisplayNames(id, locale);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * Returns the amount of time to be added to local standard time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * to get local wall clock time.
8375
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   427
     *
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   428
     * <p>The default implementation returns 3600000 milliseconds
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   429
     * (i.e., one hour) if a call to {@link #useDaylightTime()}
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   430
     * returns {@code true}. Otherwise, 0 (zero) is returned.
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   431
     *
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   432
     * <p>If an underlying {@code TimeZone} implementation subclass
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   433
     * supports historical and future Daylight Saving Time schedule
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   434
     * changes, this method returns the amount of saving time of the
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   435
     * last known Daylight Saving Time rule that can be a future
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   436
     * prediction.
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   437
     *
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   438
     * <p>If the amount of saving time at any given time stamp is
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   439
     * required, construct a {@link Calendar} with this {@code
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   440
     * TimeZone} and the time stamp, and call {@link Calendar#get(int)
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   441
     * Calendar.get}{@code (}{@link Calendar#DST_OFFSET}{@code )}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * @return the amount of saving time in milliseconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * @since 1.4
8375
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   445
     * @see #inDaylightTime(Date)
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   446
     * @see #getOffset(long)
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   447
     * @see #getOffset(int,int,int,int,int,int)
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   448
     * @see Calendar#ZONE_OFFSET
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    public int getDSTSavings() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        if (useDaylightTime()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            return 3600000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    /**
8375
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   458
     * Queries if this {@code TimeZone} uses Daylight Saving Time.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     *
8375
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   460
     * <p>If an underlying {@code TimeZone} implementation subclass
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   461
     * supports historical and future Daylight Saving Time schedule
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   462
     * changes, this method refers to the last known Daylight Saving Time
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   463
     * rule that can be a future prediction and may not be the same as
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   464
     * the current rule. Consider calling {@link #observesDaylightTime()}
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   465
     * if the current rule should also be taken into account.
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   466
     *
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   467
     * @return {@code true} if this {@code TimeZone} uses Daylight Saving Time,
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   468
     *         {@code false}, otherwise.
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   469
     * @see #inDaylightTime(Date)
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   470
     * @see Calendar#DST_OFFSET
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    public abstract boolean useDaylightTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    /**
8375
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   475
     * Returns {@code true} if this {@code TimeZone} is currently in
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   476
     * Daylight Saving Time, or if a transition from Standard Time to
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   477
     * Daylight Saving Time occurs at any future time.
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   478
     *
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   479
     * <p>The default implementation returns {@code true} if
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   480
     * {@code useDaylightTime()} or {@code inDaylightTime(new Date())}
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   481
     * returns {@code true}.
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   482
     *
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   483
     * @return {@code true} if this {@code TimeZone} is currently in
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   484
     * Daylight Saving Time, or if a transition from Standard Time to
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   485
     * Daylight Saving Time occurs at any future time; {@code false}
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   486
     * otherwise.
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   487
     * @since 1.7
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   488
     * @see #useDaylightTime()
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   489
     * @see #inDaylightTime(Date)
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   490
     * @see Calendar#DST_OFFSET
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   491
     */
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   492
    public boolean observesDaylightTime() {
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   493
        return useDaylightTime() || inDaylightTime(new Date());
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   494
    }
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   495
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   496
    /**
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   497
     * Queries if the given {@code date} is in Daylight Saving Time in
8521
ab64b8d109b8 6955047: (tz) javadoc for TimeZone.getDisplayName(boolean daylight, int style, Locale locale) is not clear
okutsu
parents: 8375
diff changeset
   498
     * this time zone.
8375
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   499
     *
8521
ab64b8d109b8 6955047: (tz) javadoc for TimeZone.getDisplayName(boolean daylight, int style, Locale locale) is not clear
okutsu
parents: 8375
diff changeset
   500
     * @param date the given Date.
ab64b8d109b8 6955047: (tz) javadoc for TimeZone.getDisplayName(boolean daylight, int style, Locale locale) is not clear
okutsu
parents: 8375
diff changeset
   501
     * @return {@code true} if the given date is in Daylight Saving Time,
8375
7b37813b7461 6936350: API clarification needed on useDaylightTime() for timezones that have defined usage dates
okutsu
parents: 7003
diff changeset
   502
     *         {@code false}, otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30644
diff changeset
   504
    public abstract boolean inDaylightTime(Date date);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    /**
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   507
     * Gets the {@code TimeZone} for the given ID.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     *
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   509
     * @param ID the ID for a {@code TimeZone}, either an abbreviation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * such as "PST", a full name such as "America/Los_Angeles", or a custom
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * ID such as "GMT-8:00". Note that the support of abbreviations is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * for JDK 1.1.x compatibility only and full names should be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     *
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   514
     * @return the specified {@code TimeZone}, or the GMT zone if the given ID
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * cannot be understood.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    public static synchronized TimeZone getTimeZone(String ID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        return getTimeZone(ID, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15260
diff changeset
   521
    /**
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15260
diff changeset
   522
     * Gets the {@code TimeZone} for the given {@code zoneId}.
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15260
diff changeset
   523
     *
16005
b480157c22fe 8008434: Misc javadoc warning fixes in DateTimeFormatterBuilder and TimeZone
darcy
parents: 15658
diff changeset
   524
     * @param zoneId a {@link ZoneId} from which the time zone ID is obtained
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15260
diff changeset
   525
     * @return the specified {@code TimeZone}, or the GMT zone if the given ID
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15260
diff changeset
   526
     *         cannot be understood.
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15260
diff changeset
   527
     * @throws NullPointerException if {@code zoneId} is {@code null}
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15260
diff changeset
   528
     * @since 1.8
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15260
diff changeset
   529
     */
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15260
diff changeset
   530
    public static TimeZone getTimeZone(ZoneId zoneId) {
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15260
diff changeset
   531
        String tzid = zoneId.getId(); // throws an NPE if null
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15260
diff changeset
   532
        char c = tzid.charAt(0);
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15260
diff changeset
   533
        if (c == '+' || c == '-') {
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15260
diff changeset
   534
            tzid = "GMT" + tzid;
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15260
diff changeset
   535
        } else if (c == 'Z' && tzid.length() == 1) {
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15260
diff changeset
   536
            tzid = "UTC";
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15260
diff changeset
   537
        }
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15260
diff changeset
   538
        return getTimeZone(tzid, true);
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15260
diff changeset
   539
    }
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15260
diff changeset
   540
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15260
diff changeset
   541
    /**
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15260
diff changeset
   542
     * Converts this {@code TimeZone} object to a {@code ZoneId}.
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15260
diff changeset
   543
     *
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15260
diff changeset
   544
     * @return a {@code ZoneId} representing the same time zone as this
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15260
diff changeset
   545
     *         {@code TimeZone}
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15260
diff changeset
   546
     * @since 1.8
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15260
diff changeset
   547
     */
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15260
diff changeset
   548
    public ZoneId toZoneId() {
30644
cc05b944b2fa 8074002: java.time.ZoneId.systemDefault() should be faster
plevart
parents: 29986
diff changeset
   549
        ZoneId zId = zoneId;
cc05b944b2fa 8074002: java.time.ZoneId.systemDefault() should be faster
plevart
parents: 29986
diff changeset
   550
        if (zId == null) {
cc05b944b2fa 8074002: java.time.ZoneId.systemDefault() should be faster
plevart
parents: 29986
diff changeset
   551
            zoneId = zId = toZoneId0();
cc05b944b2fa 8074002: java.time.ZoneId.systemDefault() should be faster
plevart
parents: 29986
diff changeset
   552
        }
cc05b944b2fa 8074002: java.time.ZoneId.systemDefault() should be faster
plevart
parents: 29986
diff changeset
   553
        return zId;
cc05b944b2fa 8074002: java.time.ZoneId.systemDefault() should be faster
plevart
parents: 29986
diff changeset
   554
    }
cc05b944b2fa 8074002: java.time.ZoneId.systemDefault() should be faster
plevart
parents: 29986
diff changeset
   555
cc05b944b2fa 8074002: java.time.ZoneId.systemDefault() should be faster
plevart
parents: 29986
diff changeset
   556
    private ZoneId toZoneId0() {
21286
0641a36bb610 8025971: Remove ZoneId.OLD_SHORT_IDS
sherman
parents: 20839
diff changeset
   557
        String id = getID();
30644
cc05b944b2fa 8074002: java.time.ZoneId.systemDefault() should be faster
plevart
parents: 29986
diff changeset
   558
        TimeZone defaultZone = defaultTimeZone;
cc05b944b2fa 8074002: java.time.ZoneId.systemDefault() should be faster
plevart
parents: 29986
diff changeset
   559
        // are we not defaultTimeZone but our id is equal to default's?
cc05b944b2fa 8074002: java.time.ZoneId.systemDefault() should be faster
plevart
parents: 29986
diff changeset
   560
        if (defaultZone != this &&
cc05b944b2fa 8074002: java.time.ZoneId.systemDefault() should be faster
plevart
parents: 29986
diff changeset
   561
            defaultZone != null && id.equals(defaultZone.getID())) {
cc05b944b2fa 8074002: java.time.ZoneId.systemDefault() should be faster
plevart
parents: 29986
diff changeset
   562
            // delegate to default TZ which is effectively immutable
cc05b944b2fa 8074002: java.time.ZoneId.systemDefault() should be faster
plevart
parents: 29986
diff changeset
   563
            return defaultZone.toZoneId();
cc05b944b2fa 8074002: java.time.ZoneId.systemDefault() should be faster
plevart
parents: 29986
diff changeset
   564
        }
cc05b944b2fa 8074002: java.time.ZoneId.systemDefault() should be faster
plevart
parents: 29986
diff changeset
   565
        // derive it ourselves
21286
0641a36bb610 8025971: Remove ZoneId.OLD_SHORT_IDS
sherman
parents: 20839
diff changeset
   566
        if (ZoneInfoFile.useOldMapping() && id.length() == 3) {
0641a36bb610 8025971: Remove ZoneId.OLD_SHORT_IDS
sherman
parents: 20839
diff changeset
   567
            if ("EST".equals(id))
0641a36bb610 8025971: Remove ZoneId.OLD_SHORT_IDS
sherman
parents: 20839
diff changeset
   568
                return ZoneId.of("America/New_York");
0641a36bb610 8025971: Remove ZoneId.OLD_SHORT_IDS
sherman
parents: 20839
diff changeset
   569
            if ("MST".equals(id))
0641a36bb610 8025971: Remove ZoneId.OLD_SHORT_IDS
sherman
parents: 20839
diff changeset
   570
                return ZoneId.of("America/Denver");
0641a36bb610 8025971: Remove ZoneId.OLD_SHORT_IDS
sherman
parents: 20839
diff changeset
   571
            if ("HST".equals(id))
0641a36bb610 8025971: Remove ZoneId.OLD_SHORT_IDS
sherman
parents: 20839
diff changeset
   572
                return ZoneId.of("America/Honolulu");
0641a36bb610 8025971: Remove ZoneId.OLD_SHORT_IDS
sherman
parents: 20839
diff changeset
   573
        }
0641a36bb610 8025971: Remove ZoneId.OLD_SHORT_IDS
sherman
parents: 20839
diff changeset
   574
        return ZoneId.of(id, ZoneId.SHORT_IDS);
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15260
diff changeset
   575
    }
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15260
diff changeset
   576
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    private static TimeZone getTimeZone(String ID, boolean fallback) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        TimeZone tz = ZoneInfo.getTimeZone(ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        if (tz == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            tz = parseCustomTimeZone(ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            if (tz == null && fallback) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                tz = new ZoneInfo(GMT_ID, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        return tz;
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 the available IDs according to the given time zone offset in milliseconds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * @param rawOffset the given time zone GMT offset in milliseconds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * @return an array of IDs, where the time zone for that ID has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * the specified GMT offset. For example, "America/Phoenix" and "America/Denver"
8521
ab64b8d109b8 6955047: (tz) javadoc for TimeZone.getDisplayName(boolean daylight, int style, Locale locale) is not clear
okutsu
parents: 8375
diff changeset
   594
     * both have GMT-07:00, but differ in daylight saving behavior.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * @see #getRawOffset()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    public static synchronized String[] getAvailableIDs(int rawOffset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        return ZoneInfo.getAvailableIDs(rawOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * Gets all the available IDs supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * @return an array of IDs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    public static synchronized String[] getAvailableIDs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        return ZoneInfo.getAvailableIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * Gets the platform defined TimeZone ID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     **/
24508
b4afda4d4fa1 8032650: [parfait] warning from b124 for jdk/src/share/native/java/util: jni exception pending
okutsu
parents: 21334
diff changeset
   612
    private static native String getSystemTimeZoneID(String javaHome);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * Gets the custom time zone ID based on the GMT offset of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * platform. (e.g., "GMT+08:00")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    private static native String getSystemGMTOffsetID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    /**
20822
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   621
     * Gets the default {@code TimeZone} of the Java virtual machine. If the
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   622
     * cached default {@code TimeZone} is available, its clone is returned.
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   623
     * Otherwise, the method takes the following steps to determine the default
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   624
     * time zone.
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   625
     *
21334
c60dfce46a77 8026982: javadoc errors in core libs
rriggs
parents: 21286
diff changeset
   626
     * <ul>
20822
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   627
     * <li>Use the {@code user.timezone} property value as the default
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   628
     * time zone ID if it's available.</li>
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   629
     * <li>Detect the platform time zone ID. The source of the
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   630
     * platform time zone and ID mapping may vary with implementation.</li>
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   631
     * <li>Use {@code GMT} as the last resort if the given or detected
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   632
     * time zone ID is unknown.</li>
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   633
     * </ul>
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   634
     *
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   635
     * <p>The default {@code TimeZone} created from the ID is cached,
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   636
     * and its clone is returned. The {@code user.timezone} property
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   637
     * value is set to the ID upon return.
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   638
     *
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   639
     * @return the default {@code TimeZone}
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   640
     * @see #setDefault(TimeZone)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    public static TimeZone getDefault() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        return (TimeZone) getDefaultRef().clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * Returns the reference to the default TimeZone object. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * method doesn't create a clone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    static TimeZone getDefaultRef() {
20822
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   651
        TimeZone defaultZone = defaultTimeZone;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        if (defaultZone == null) {
20822
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   653
            // Need to initialize the default time zone.
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   654
            defaultZone = setDefaultZone();
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   655
            assert defaultZone != null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        // Don't clone here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        return defaultZone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    private static synchronized TimeZone setDefaultZone() {
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14169
diff changeset
   662
        TimeZone tz;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        // get the time zone ID from the system properties
37781
71ed5645f17c 8155775: Re-examine naming of privileged methods to access System properties
redestad
parents: 37593
diff changeset
   664
        Properties props = GetPropertyAction.privilegedGetProperties();
71ed5645f17c 8155775: Re-examine naming of privileged methods to access System properties
redestad
parents: 37593
diff changeset
   665
        String zoneID = props.getProperty("user.timezone");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        // if the time zone ID is not set (yet), perform the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        // platform to Java time zone ID mapping.
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14169
diff changeset
   669
        if (zoneID == null || zoneID.isEmpty()) {
50817
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 49939
diff changeset
   670
            String javaHome = StaticProperty.javaHome();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            try {
24508
b4afda4d4fa1 8032650: [parfait] warning from b124 for jdk/src/share/native/java/util: jni exception pending
okutsu
parents: 21334
diff changeset
   672
                zoneID = getSystemTimeZoneID(javaHome);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                if (zoneID == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                    zoneID = GMT_ID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            } catch (NullPointerException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                zoneID = GMT_ID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        // Get the time zone for zoneID. But not fall back to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        // "GMT" here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        tz = getTimeZone(zoneID, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        if (tz == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            // If the given zone ID is unknown in Java, try to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            // get the GMT-offset-based time zone ID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            // a.k.a. custom time zone ID (e.g., "GMT-08:00").
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            String gmtOffsetID = getSystemGMTOffsetID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            if (gmtOffsetID != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                zoneID = gmtOffsetID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            tz = getTimeZone(zoneID, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        assert tz != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        final String id = zoneID;
37781
71ed5645f17c 8155775: Re-examine naming of privileged methods to access System properties
redestad
parents: 37593
diff changeset
   698
        props.setProperty("user.timezone", id);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        defaultTimeZone = tz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        return tz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    /**
20822
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   705
     * Sets the {@code TimeZone} that is returned by the {@code getDefault}
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   706
     * method. {@code zone} is cached. If {@code zone} is null, the cached
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   707
     * default {@code TimeZone} is cleared. This method doesn't change the value
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   708
     * of the {@code user.timezone} property.
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   709
     *
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   710
     * @param zone the new default {@code TimeZone}, or null
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   711
     * @throws SecurityException if the security manager's {@code checkPermission}
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   712
     *                           denies {@code PropertyPermission("user.timezone",
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   713
     *                           "write")}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * @see #getDefault
20822
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   715
     * @see PropertyPermission
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    public static void setDefault(TimeZone zone)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    {
20822
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   719
        SecurityManager sm = System.getSecurityManager();
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   720
        if (sm != null) {
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   721
            sm.checkPermission(new PropertyPermission
2552851d9562 8001029: Add new date/time capability
okutsu
parents: 18543
diff changeset
   722
                               ("user.timezone", "write"));
11896
eb4d5334fccf 6351654: Problem with java/classes_util_i18n
okutsu
parents: 8521
diff changeset
   723
        }
30644
cc05b944b2fa 8074002: java.time.ZoneId.systemDefault() should be faster
plevart
parents: 29986
diff changeset
   724
        // by saving a defensive clone and returning a clone in getDefault() too,
cc05b944b2fa 8074002: java.time.ZoneId.systemDefault() should be faster
plevart
parents: 29986
diff changeset
   725
        // the defaultTimeZone instance is isolated from user code which makes it
cc05b944b2fa 8074002: java.time.ZoneId.systemDefault() should be faster
plevart
parents: 29986
diff changeset
   726
        // effectively immutable. This is important to avoid races when the
cc05b944b2fa 8074002: java.time.ZoneId.systemDefault() should be faster
plevart
parents: 29986
diff changeset
   727
        // following is evaluated in ZoneId.systemDefault():
cc05b944b2fa 8074002: java.time.ZoneId.systemDefault() should be faster
plevart
parents: 29986
diff changeset
   728
        // TimeZone.getDefault().toZoneId().
cc05b944b2fa 8074002: java.time.ZoneId.systemDefault() should be faster
plevart
parents: 29986
diff changeset
   729
        defaultTimeZone = (zone == null) ? null : (TimeZone) zone.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * Returns true if this zone has the same rule and offset as another zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     * That is, if this zone differs only in ID, if at all.  Returns false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * if the other zone is null.
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   736
     * @param other the {@code TimeZone} object to be compared with
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * @return true if the other zone is not null and is the same as this one,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * with the possible exception of the ID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    public boolean hasSameRules(TimeZone other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        return other != null && getRawOffset() == other.getRawOffset() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            useDaylightTime() == other.useDaylightTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    /**
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   747
     * Creates a copy of this {@code TimeZone}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     *
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   749
     * @return a clone of this {@code TimeZone}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    public Object clone()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        try {
30644
cc05b944b2fa 8074002: java.time.ZoneId.systemDefault() should be faster
plevart
parents: 29986
diff changeset
   754
            return super.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        } catch (CloneNotSupportedException e) {
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 8521
diff changeset
   756
            throw new InternalError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * The null constant as a TimeZone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    static final TimeZone NO_TIMEZONE = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    // =======================privates===============================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    /**
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   768
     * The string identifier of this {@code TimeZone}.  This is a
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   769
     * programmatic identifier used internally to look up {@code TimeZone}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     * objects from the system table and also to map them to their localized
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   771
     * display names.  {@code ID} values are unique in the system
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     * table but may not be for dynamically created zones.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    private String           ID;
30644
cc05b944b2fa 8074002: java.time.ZoneId.systemDefault() should be faster
plevart
parents: 29986
diff changeset
   776
cc05b944b2fa 8074002: java.time.ZoneId.systemDefault() should be faster
plevart
parents: 29986
diff changeset
   777
    /**
cc05b944b2fa 8074002: java.time.ZoneId.systemDefault() should be faster
plevart
parents: 29986
diff changeset
   778
     * Cached {@link ZoneId} for this TimeZone
cc05b944b2fa 8074002: java.time.ZoneId.systemDefault() should be faster
plevart
parents: 29986
diff changeset
   779
     */
cc05b944b2fa 8074002: java.time.ZoneId.systemDefault() should be faster
plevart
parents: 29986
diff changeset
   780
    private transient ZoneId zoneId;
cc05b944b2fa 8074002: java.time.ZoneId.systemDefault() should be faster
plevart
parents: 29986
diff changeset
   781
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    private static volatile TimeZone defaultTimeZone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    static final String         GMT_ID        = "GMT";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    private static final int    GMT_ID_LENGTH = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * Parses a custom time zone identifier and returns a corresponding zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * This method doesn't support the RFC 822 time zone format. (e.g., +hhmm)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * @param id a string of the <a href="#CustomID">custom ID form</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * @return a newly created TimeZone with the given offset and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * no daylight saving time, or null if the id cannot be parsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    private static final TimeZone parseCustomTimeZone(String id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        int length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        // Error if the length of id isn't long enough or id doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        // start with "GMT".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        if ((length = id.length()) < (GMT_ID_LENGTH + 2) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            id.indexOf(GMT_ID) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        ZoneInfo zi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        // First, we try to find it in the cache with the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        // id. Even the id is not normalized, the returned ZoneInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        // should have its normalized id.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        zi = ZoneInfoFile.getZoneInfo(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        if (zi != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            return zi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        int index = GMT_ID_LENGTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        boolean negative = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        char c = id.charAt(index++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        if (c == '-') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            negative = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        } else if (c != '+') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        int hours = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        int num = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        int countDelim = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        int len = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        while (index < length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            c = id.charAt(index++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            if (c == ':') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                if (countDelim > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                if (len > 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                hours = num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                countDelim++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
                num = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                len = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            if (c < '0' || c > '9') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
            num = num * 10 + (c - '0');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
            len++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        if (index != length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        if (countDelim == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            if (len <= 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
                hours = num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
                num = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                hours = num / 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                num %= 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
            if (len != 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        if (hours > 23 || num > 59) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        int gmtOffset =  (hours * 60 + num) * 60 * 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        if (gmtOffset == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
            zi = ZoneInfoFile.getZoneInfo(GMT_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            if (negative) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                zi.setID("GMT-00:00");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                zi.setID("GMT+00:00");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
            zi = ZoneInfoFile.getCustomTimeZone(id, negative ? -gmtOffset : gmtOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        return zi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
}