src/java.base/share/classes/java/util/Date.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58242 94bb65cb37d3
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
57956
e0b8b019d2f5 8229997: Apply java.io.Serial annotations in java.base
darcy
parents: 52772
diff changeset
     2
 * Copyright (c) 1994, 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: 4847
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: 4847
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: 4847
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4847
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4847
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.text.DateFormat;
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
    29
import java.time.LocalDate;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.lang.ref.SoftReference;
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
    34
import java.time.Instant;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.util.calendar.BaseCalendar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.util.calendar.CalendarDate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.util.calendar.CalendarSystem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.util.calendar.CalendarUtils;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.util.calendar.Era;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.util.calendar.Gregorian;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import sun.util.calendar.ZoneInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
    44
 * The class {@code Date} represents a specific instant
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * in time, with millisecond precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <p>
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
    47
 * Prior to JDK&nbsp;1.1, the class {@code Date} had two additional
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * functions.  It allowed the interpretation of dates as year, month, day, hour,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * minute, and second values.  It also allowed the formatting and parsing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * of date strings.  Unfortunately, the API for these functions was not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * amenable to internationalization.  As of JDK&nbsp;1.1, the
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
    52
 * {@code Calendar} class should be used to convert between dates and time
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
    53
 * fields and the {@code DateFormat} class should be used to format and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * parse date strings.
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
    55
 * The corresponding methods in {@code Date} are deprecated.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <p>
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
    57
 * Although the {@code Date} class is intended to reflect
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * coordinated universal time (UTC), it may not do so exactly,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * depending on the host environment of the Java Virtual Machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * Nearly all modern operating systems assume that 1&nbsp;day&nbsp;=
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * 24&nbsp;&times;&nbsp;60&nbsp;&times;&nbsp;60&nbsp;= 86400 seconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * in all cases. In UTC, however, about once every year or two there
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * is an extra second, called a "leap second." The leap
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * second is always added as the last second of the day, and always
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * on December 31 or June 30. For example, the last minute of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * year 1995 was 61 seconds long, thanks to an added leap second.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * Most computer clocks are not accurate enough to be able to reflect
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * the leap-second distinction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * Some computer standards are defined in terms of Greenwich mean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * time (GMT), which is equivalent to universal time (UT).  GMT is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * the "civil" name for the standard; UT is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * "scientific" name for the same standard. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * distinction between UTC and UT is that UTC is based on an atomic
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * clock and UT is based on astronomical observations, which for all
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * practical purposes is an invisibly fine hair to split. Because the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * earth's rotation is not uniform (it slows down and speeds up
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * in complicated ways), UT does not always flow uniformly. Leap
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * seconds are introduced as needed into UTC so as to keep UTC within
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * 0.9 seconds of UT1, which is a version of UT with certain
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * corrections applied. There are other time and date systems as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * well; for example, the time scale used by the satellite-based
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * global positioning system (GPS) is synchronized to UTC but is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * <i>not</i> adjusted for leap seconds. An interesting source of
43102
02f12903b22c 8172221: Directorate of Time has been superseded
smarks
parents: 41493
diff changeset
    85
 * further information is the United States Naval Observatory (USNO):
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * <blockquote><pre>
52772
beb2b88a118e 8212870: Broken links for www.usno.navy.mil
naoto
parents: 47216
diff changeset
    87
 *     <a href="https://www.usno.navy.mil/USNO">https://www.usno.navy.mil/USNO</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * <p>
43102
02f12903b22c 8172221: Directorate of Time has been superseded
smarks
parents: 41493
diff changeset
    90
 * and the material regarding "Systems of Time" at:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * <blockquote><pre>
52772
beb2b88a118e 8212870: Broken links for www.usno.navy.mil
naoto
parents: 47216
diff changeset
    92
 *     <a href="https://www.usno.navy.mil/USNO/time/master-clock/systems-of-time">https://www.usno.navy.mil/USNO/time/master-clock/systems-of-time</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * <p>
43102
02f12903b22c 8172221: Directorate of Time has been superseded
smarks
parents: 41493
diff changeset
    95
 * which has descriptions of various different time systems including
02f12903b22c 8172221: Directorate of Time has been superseded
smarks
parents: 41493
diff changeset
    96
 * UT, UT1, and UTC.
02f12903b22c 8172221: Directorate of Time has been superseded
smarks
parents: 41493
diff changeset
    97
 * <p>
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
    98
 * In all methods of class {@code Date} that accept or return
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * year, month, date, hours, minutes, and seconds values, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * following representations are used:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * <li>A year <i>y</i> is represented by the integer
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   103
 *     <i>y</i>&nbsp;{@code - 1900}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * <li>A month is represented by an integer from 0 to 11; 0 is January,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 *     1 is February, and so forth; thus 11 is December.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * <li>A date (day of month) is represented by an integer from 1 to 31
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 *     in the usual manner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * <li>An hour is represented by an integer from 0 to 23. Thus, the hour
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 *     from midnight to 1 a.m. is hour 0, and the hour from noon to 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 *     p.m. is hour 12.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * <li>A minute is represented by an integer from 0 to 59 in the usual manner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * <li>A second is represented by an integer from 0 to 61; the values 60 and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 *     61 occur only for leap seconds and even then only in Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 *     implementations that actually track leap seconds correctly. Because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 *     of the manner in which leap seconds are currently introduced, it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 *     extremely unlikely that two leap seconds will occur in the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 *     minute, but this specification follows the date and time conventions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 *     for ISO C.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * In all cases, arguments given to methods for these purposes need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * not fall within the indicated ranges; for example, a date may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * specified as January 32 and is interpreted as meaning February 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * @author  James Gosling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * @author  Arthur van Hoff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * @author  Alan Liu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * @see     java.text.DateFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * @see     java.util.Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * @see     java.util.TimeZone
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23010
diff changeset
   131
 * @since   1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
public class Date
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    implements java.io.Serializable, Cloneable, Comparable<Date>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    private static final BaseCalendar gcal =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                                CalendarSystem.getGregorianCalendar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    private static BaseCalendar jcal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    private transient long fastTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * If cdate is null, then fastTime indicates the time in millis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * If cdate.isNormalized() is true, then fastTime and cdate are in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * synch. Otherwise, fastTime is ignored, and cdate indicates the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    private transient BaseCalendar.Date cdate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    // Initialized just before the value is used. See parse().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    private static int defaultCenturyStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /* use serialVersionUID from modified java.util.Date for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * interoperability with JDK1.1. The Date was modified to write
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * and read only the UTC time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     */
57956
e0b8b019d2f5 8229997: Apply java.io.Serial annotations in java.base
darcy
parents: 52772
diff changeset
   157
    @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    private static final long serialVersionUID = 7523967970034938905L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /**
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   161
     * Allocates a {@code Date} object and initializes it so that
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * it represents the time at which it was allocated, measured to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * nearest millisecond.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @see     java.lang.System#currentTimeMillis()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public Date() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        this(System.currentTimeMillis());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    /**
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   172
     * Allocates a {@code Date} object and initializes it to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * represent the specified number of milliseconds since the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * standard base time known as "the epoch", namely January 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * 1970, 00:00:00 GMT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @param   date   the milliseconds since January 1, 1970, 00:00:00 GMT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @see     java.lang.System#currentTimeMillis()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    public Date(long date) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        fastTime = date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /**
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   185
     * Allocates a {@code Date} object and initializes it so that
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * it represents midnight, local time, at the beginning of the day
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   187
     * specified by the {@code year}, {@code month}, and
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   188
     * {@code date} arguments.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @param   year    the year minus 1900.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @param   month   the month between 0-11.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @param   date    the day of the month between 1-31.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @see     java.util.Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @deprecated As of JDK version 1.1,
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   195
     * replaced by {@code Calendar.set(year + 1900, month, date)}
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   196
     * or {@code GregorianCalendar(year + 1900, month, date)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    public Date(int year, int month, int date) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        this(year, month, date, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    /**
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   204
     * Allocates a {@code Date} object and initializes it so that
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * it represents the instant at the start of the minute specified by
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   206
     * the {@code year}, {@code month}, {@code date},
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   207
     * {@code hrs}, and {@code min} arguments, in the local
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * time zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @param   year    the year minus 1900.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @param   month   the month between 0-11.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @param   date    the day of the month between 1-31.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @param   hrs     the hours between 0-23.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @param   min     the minutes between 0-59.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @see     java.util.Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @deprecated As of JDK version 1.1,
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   217
     * replaced by {@code Calendar.set(year + 1900, month, date, hrs, min)}
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   218
     * or {@code GregorianCalendar(year + 1900, month, date, hrs, min)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    public Date(int year, int month, int date, int hrs, int min) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        this(year, month, date, hrs, min, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    /**
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   226
     * Allocates a {@code Date} object and initializes it so that
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * it represents the instant at the start of the second specified
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   228
     * by the {@code year}, {@code month}, {@code date},
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   229
     * {@code hrs}, {@code min}, and {@code sec} arguments,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * in the local time zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @param   year    the year minus 1900.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @param   month   the month between 0-11.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @param   date    the day of the month between 1-31.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @param   hrs     the hours between 0-23.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @param   min     the minutes between 0-59.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @param   sec     the seconds between 0-59.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @see     java.util.Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @deprecated As of JDK version 1.1,
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   240
     * replaced by {@code Calendar.set(year + 1900, month, date, hrs, min, sec)}
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   241
     * or {@code GregorianCalendar(year + 1900, month, date, hrs, min, sec)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public Date(int year, int month, int date, int hrs, int min, int sec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        int y = year + 1900;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        // month is 0-based. So we have to normalize month to support Long.MAX_VALUE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        if (month >= 12) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            y += month / 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            month %= 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        } else if (month < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            y += CalendarUtils.floorDivide(month, 12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            month = CalendarUtils.mod(month, 12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        BaseCalendar cal = getCalendarSystem(y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.getDefaultRef());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        cdate.setNormalizedDate(y, month + 1, date).setTimeOfDay(hrs, min, sec, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        getTimeImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        cdate = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /**
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   262
     * Allocates a {@code Date} object and initializes it so that
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * it represents the date and time indicated by the string
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   264
     * {@code s}, which is interpreted as if by the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * {@link Date#parse} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @param   s   a string representation of the date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @see     java.text.DateFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @see     java.util.Date#parse(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @deprecated As of JDK version 1.1,
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   271
     * replaced by {@code DateFormat.parse(String s)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    public Date(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        this(parse(s));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * Return a copy of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        Date d = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            d = (Date)super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            if (cdate != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                d.cdate = (BaseCalendar.Date) cdate.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        } catch (CloneNotSupportedException e) {} // Won't happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        return d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * Determines the date and time based on the arguments. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * arguments are interpreted as a year, month, day of the month,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * hour of the day, minute within the hour, and second within the
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   296
     * minute, exactly as for the {@code Date} constructor with six
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * arguments, except that the arguments are interpreted relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * to UTC rather than to the local time zone. The time indicated is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * returned represented as the distance, measured in milliseconds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * of that time from the epoch (00:00:00 GMT on January 1, 1970).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @param   year    the year minus 1900.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @param   month   the month between 0-11.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @param   date    the day of the month between 1-31.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @param   hrs     the hours between 0-23.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @param   min     the minutes between 0-59.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @param   sec     the seconds between 0-59.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @return  the number of milliseconds since January 1, 1970, 00:00:00 GMT for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     *          the date and time specified by the arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * @see     java.util.Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @deprecated As of JDK version 1.1,
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   312
     * replaced by {@code Calendar.set(year + 1900, month, date, hrs, min, sec)}
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   313
     * or {@code GregorianCalendar(year + 1900, month, date, hrs, min, sec)}, using a UTC
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   314
     * {@code TimeZone}, followed by {@code Calendar.getTime().getTime()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    public static long UTC(int year, int month, int date,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                           int hrs, int min, int sec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        int y = year + 1900;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        // month is 0-based. So we have to normalize month to support Long.MAX_VALUE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        if (month >= 12) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            y += month / 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            month %= 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        } else if (month < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            y += CalendarUtils.floorDivide(month, 12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            month = CalendarUtils.mod(month, 12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        int m = month + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        BaseCalendar cal = getCalendarSystem(y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        BaseCalendar.Date udate = (BaseCalendar.Date) cal.newCalendarDate(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        udate.setNormalizedDate(y, m, date).setTimeOfDay(hrs, min, sec, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        // Use a Date instance to perform normalization. Its fastTime
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        // is the UTC value after the normalization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        Date d = new Date(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        d.normalize(udate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        return d.fastTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    /**
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   341
     * Attempts to interpret the string {@code s} as a representation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * of a date and time. If the attempt is successful, the time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * indicated is returned represented as the distance, measured in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * milliseconds, of that time from the epoch (00:00:00 GMT on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * January 1, 1970). If the attempt fails, an
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   346
     * {@code IllegalArgumentException} is thrown.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * It accepts many syntaxes; in particular, it recognizes the IETF
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * standard date syntax: "Sat, 12 Aug 1995 13:30:00 GMT". It also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * understands the continental U.S. time-zone abbreviations, but for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * general use, a time-zone offset should be used: "Sat, 12 Aug 1995
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * 13:30:00 GMT+0430" (4 hours, 30 minutes west of the Greenwich
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * meridian). If no time zone is specified, the local time zone is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * assumed. GMT and UTC are considered equivalent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * <p>
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   356
     * The string {@code s} is processed from left to right, looking for
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   357
     * data of interest. Any material in {@code s} that is within the
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   358
     * ASCII parenthesis characters {@code (} and {@code )} is ignored.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * Parentheses may be nested. Otherwise, the only characters permitted
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   360
     * within {@code s} are these ASCII characters:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * abcdefghijklmnopqrstuvwxyz
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * ABCDEFGHIJKLMNOPQRSTUVWXYZ
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * 0123456789,+-:/</pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * and whitespace characters.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * A consecutive sequence of decimal digits is treated as a decimal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * number:<ul>
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   368
     * <li>If a number is preceded by {@code +} or {@code -} and a year
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     *     has already been recognized, then the number is a time-zone
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     *     offset. If the number is less than 24, it is an offset measured
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     *     in hours. Otherwise, it is regarded as an offset in minutes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     *     expressed in 24-hour time format without punctuation. A
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   373
     *     preceding {@code -} means a westward offset. Time zone offsets
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *     are always relative to UTC (Greenwich). Thus, for example,
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   375
     *     {@code -5} occurring in the string would mean "five hours west
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   376
     *     of Greenwich" and {@code +0430} would mean "four hours and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     *     thirty minutes east of Greenwich." It is permitted for the
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   378
     *     string to specify {@code GMT}, {@code UT}, or {@code UTC}
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   379
     *     redundantly-for example, {@code GMT-5} or {@code utc+0430}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * <li>The number is regarded as a year number if one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     *     following conditions is true:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     *     <li>The number is equal to or greater than 70 and followed by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     *         space, comma, slash, or end of string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     *     <li>The number is less than 70, and both a month and a day of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     *         the month have already been recognized</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     *     If the recognized year number is less than 100, it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     *     interpreted as an abbreviated year relative to a century of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     *     which dates are within 80 years before and 19 years after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     *     the time when the Date class is initialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     *     After adjusting the year number, 1900 is subtracted from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     *     it. For example, if the current year is 1999 then years in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     *     the range 19 to 99 are assumed to mean 1919 to 1999, while
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     *     years from 0 to 18 are assumed to mean 2000 to 2018.  Note
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     *     that this is slightly different from the interpretation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     *     years less than 100 that is used in {@link java.text.SimpleDateFormat}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * <li>If the number is followed by a colon, it is regarded as an hour,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     *     unless an hour has already been recognized, in which case it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     *     regarded as a minute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * <li>If the number is followed by a slash, it is regarded as a month
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   402
     *     (it is decreased by 1 to produce a number in the range {@code 0}
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   403
     *     to {@code 11}), unless a month has already been recognized, in
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     *     which case it is regarded as a day of the month.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * <li>If the number is followed by whitespace, a comma, a hyphen, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     *     end of string, then if an hour has been recognized but not a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     *     minute, it is regarded as a minute; otherwise, if a minute has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     *     been recognized but not a second, it is regarded as a second;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     *     otherwise, it is regarded as a day of the month. </ul><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * A consecutive sequence of letters is regarded as a word and treated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * as follows:<ul>
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   412
     * <li>A word that matches {@code AM}, ignoring case, is ignored (but
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     *     the parse fails if an hour has not been recognized or is less
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   414
     *     than {@code 1} or greater than {@code 12}).
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   415
     * <li>A word that matches {@code PM}, ignoring case, adds {@code 12}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     *     to the hour (but the parse fails if an hour has not been
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   417
     *     recognized or is less than {@code 1} or greater than {@code 12}).
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   418
     * <li>Any word that matches any prefix of {@code SUNDAY, MONDAY, TUESDAY,
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   419
     *     WEDNESDAY, THURSDAY, FRIDAY}, or {@code SATURDAY}, ignoring
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   420
     *     case, is ignored. For example, {@code sat, Friday, TUE}, and
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   421
     *     {@code Thurs} are ignored.
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   422
     * <li>Otherwise, any word that matches any prefix of {@code JANUARY,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     *     FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER,
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   424
     *     OCTOBER, NOVEMBER}, or {@code DECEMBER}, ignoring case, and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     *     considering them in the order given here, is recognized as
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   426
     *     specifying a month and is converted to a number ({@code 0} to
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   427
     *     {@code 11}). For example, {@code aug, Sept, april}, and
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   428
     *     {@code NOV} are recognized as months. So is {@code Ma}, which
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   429
     *     is recognized as {@code MARCH}, not {@code MAY}.
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   430
     * <li>Any word that matches {@code GMT, UT}, or {@code UTC}, ignoring
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     *     case, is treated as referring to UTC.
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   432
     * <li>Any word that matches {@code EST, CST, MST}, or {@code PST},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     *     ignoring case, is recognized as referring to the time zone in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     *     North America that is five, six, seven, or eight hours west of
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   435
     *     Greenwich, respectively. Any word that matches {@code EDT, CDT,
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   436
     *     MDT}, or {@code PDT}, ignoring case, is recognized as
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     *     referring to the same time zone, respectively, during daylight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     *     saving time.</ul><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * Once the entire string s has been scanned, it is converted to a time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * result in one of two ways. If a time zone or time-zone offset has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * recognized, then the year, month, day of month, hour, minute, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * second are interpreted in UTC and then the time-zone offset is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * applied. Otherwise, the year, month, day of month, hour, minute, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * second are interpreted in the local time zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * @param   s   a string to be parsed as a date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @return  the number of milliseconds since January 1, 1970, 00:00:00 GMT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     *          represented by the string argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * @see     java.text.DateFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * @deprecated As of JDK version 1.1,
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   451
     * replaced by {@code DateFormat.parse(String s)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    public static long parse(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        int year = Integer.MIN_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        int mon = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        int mday = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        int hour = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        int min = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        int sec = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        int millis = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        int c = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        int n = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        int wst = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        int tzoffset = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        int prevc = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    syntax:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            if (s == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                break syntax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            int limit = s.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            while (i < limit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                c = s.charAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                if (c <= ' ' || c == ',')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                if (c == '(') { // skip comments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                    int depth = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                    while (i < limit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                        c = s.charAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                        i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                        if (c == '(') depth++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                        else if (c == ')')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                            if (--depth <= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                if ('0' <= c && c <= '9') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                    n = c - '0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                    while (i < limit && '0' <= (c = s.charAt(i)) && c <= '9') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                        n = n * 10 + c - '0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                        i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                    if (prevc == '+' || prevc == '-' && year != Integer.MIN_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                        // timezone offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                        if (n < 24)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                            n = n * 60; // EG. "GMT-3"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                            n = n % 100 + n / 100 * 60; // eg "GMT-0430"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                        if (prevc == '+')   // plus means east of GMT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                            n = -n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                        if (tzoffset != 0 && tzoffset != -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                            break syntax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                        tzoffset = n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                    } else if (n >= 70)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                        if (year != Integer.MIN_VALUE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                            break syntax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                        else if (c <= ' ' || c == ',' || c == '/' || i >= limit)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                            // year = n < 1900 ? n : n - 1900;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                            year = n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                            break syntax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                    else if (c == ':')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                        if (hour < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                            hour = (byte) n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                        else if (min < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                            min = (byte) n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                            break syntax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                    else if (c == '/')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                        if (mon < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                            mon = (byte) (n - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                        else if (mday < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                            mday = (byte) n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                            break syntax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                    else if (i < limit && c != ',' && c > ' ' && c != '-')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                        break syntax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                    else if (hour >= 0 && min < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                        min = (byte) n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                    else if (min >= 0 && sec < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                        sec = (byte) n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                    else if (mday < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                        mday = (byte) n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                    // Handle two-digit years < 70 (70-99 handled above).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                    else if (year == Integer.MIN_VALUE && mon >= 0 && mday >= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                        year = n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                        break syntax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                    prevc = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                } else if (c == '/' || c == ':' || c == '+' || c == '-')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                    prevc = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                    int st = i - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                    while (i < limit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                        c = s.charAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                        if (!('A' <= c && c <= 'Z' || 'a' <= c && c <= 'z'))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                        i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                    if (i <= st + 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                        break syntax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                    int k;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                    for (k = wtb.length; --k >= 0;)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                        if (wtb[k].regionMatches(true, 0, s, st, i - st)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                            int action = ttb[k];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                            if (action != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                                if (action == 1) {  // pm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                                    if (hour > 12 || hour < 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                                        break syntax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                                    else if (hour < 12)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                                        hour += 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                                } else if (action == 14) {  // am
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                                    if (hour > 12 || hour < 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                                        break syntax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                                    else if (hour == 12)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                                        hour = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                                } else if (action <= 13) {  // month!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                                    if (mon < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                                        mon = (byte) (action - 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                                        break syntax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                                    tzoffset = action - 10000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                    if (k < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                        break syntax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                    prevc = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            if (year == Integer.MIN_VALUE || mon < 0 || mday < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                break syntax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            // Parse 2-digit years within the correct default century.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            if (year < 100) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                synchronized (Date.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                    if (defaultCenturyStart == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                        defaultCenturyStart = gcal.getCalendarDate().getYear() - 80;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                year += (defaultCenturyStart / 100) * 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                if (year < defaultCenturyStart) year += 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            if (sec < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                sec = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            if (min < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                min = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            if (hour < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                hour = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            BaseCalendar cal = getCalendarSystem(year);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            if (tzoffset == -1)  { // no time zone specified, have to use local
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                BaseCalendar.Date ldate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.getDefaultRef());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                ldate.setDate(year, mon + 1, mday);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                ldate.setTimeOfDay(hour, min, sec, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                return cal.getTime(ldate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            BaseCalendar.Date udate = (BaseCalendar.Date) cal.newCalendarDate(null); // no time zone
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            udate.setDate(year, mon + 1, mday);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            udate.setTimeOfDay(hour, min, sec, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            return cal.getTime(udate) + tzoffset * (60 * 1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        // syntax error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    }
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 29614
diff changeset
   619
    private static final String wtb[] = {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        "am", "pm",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        "monday", "tuesday", "wednesday", "thursday", "friday",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        "saturday", "sunday",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        "january", "february", "march", "april", "may", "june",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        "july", "august", "september", "october", "november", "december",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        "gmt", "ut", "utc", "est", "edt", "cst", "cdt",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        "mst", "mdt", "pst", "pdt"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    };
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 29614
diff changeset
   628
    private static final int ttb[] = {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        14, 1, 0, 0, 0, 0, 0, 0, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        10000 + 0, 10000 + 0, 10000 + 0,    // GMT/UT/UTC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        10000 + 5 * 60, 10000 + 4 * 60,     // EST/EDT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        10000 + 6 * 60, 10000 + 5 * 60,     // CST/CDT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        10000 + 7 * 60, 10000 + 6 * 60,     // MST/MDT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        10000 + 8 * 60, 10000 + 7 * 60      // PST/PDT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * Returns a value that is the result of subtracting 1900 from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * year that contains or begins with the instant in time represented
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   641
     * by this {@code Date} object, as interpreted in the local
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * time zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * @return  the year represented by this date, minus 1900.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * @see     java.util.Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * @deprecated As of JDK version 1.1,
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   647
     * replaced by {@code Calendar.get(Calendar.YEAR) - 1900}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    public int getYear() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        return normalize().getYear() - 1900;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    /**
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   655
     * Sets the year of this {@code Date} object to be the specified
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   656
     * value plus 1900. This {@code Date} object is modified so
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * that it represents a point in time within the specified year,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * with the month, date, hour, minute, and second the same as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * before, as interpreted in the local time zone. (Of course, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * the date was February 29, for example, and the year is set to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * non-leap year, then the new date will be treated as if it were
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * on March 1.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * @param   year    the year value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * @see     java.util.Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * @deprecated As of JDK version 1.1,
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   667
     * replaced by {@code Calendar.set(Calendar.YEAR, year + 1900)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    public void setYear(int year) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        getCalendarDate().setNormalizedYear(year + 1900);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * Returns a number representing the month that contains or begins
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   676
     * with the instant in time represented by this {@code Date} object.
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   677
     * The value returned is between {@code 0} and {@code 11},
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   678
     * with the value {@code 0} representing January.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * @return  the month represented by this date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * @see     java.util.Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * @deprecated As of JDK version 1.1,
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   683
     * replaced by {@code Calendar.get(Calendar.MONTH)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    public int getMonth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        return normalize().getMonth() - 1; // adjust 1-based to 0-based
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * Sets the month of this date to the specified value. This
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   692
     * {@code Date} object is modified so that it represents a point
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * in time within the specified month, with the year, date, hour,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * minute, and second the same as before, as interpreted in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * local time zone. If the date was October 31, for example, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * the month is set to June, then the new date will be treated as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * if it were on July 1, because June has only 30 days.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * @param   month   the month value between 0-11.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * @see     java.util.Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * @deprecated As of JDK version 1.1,
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   702
     * replaced by {@code Calendar.set(Calendar.MONTH, int month)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    public void setMonth(int month) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        int y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        if (month >= 12) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            y = month / 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            month %= 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        } else if (month < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            y = CalendarUtils.floorDivide(month, 12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            month = CalendarUtils.mod(month, 12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        BaseCalendar.Date d = getCalendarDate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        if (y != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            d.setNormalizedYear(d.getNormalizedYear() + y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        d.setMonth(month + 1); // adjust 0-based to 1-based month numbering
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    /**
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   722
     * Returns the day of the month represented by this {@code Date} object.
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   723
     * The value returned is between {@code 1} and {@code 31}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * representing the day of the month that contains or begins with the
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   725
     * instant in time represented by this {@code Date} object, as
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * interpreted in the local time zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * @return  the day of the month represented by this date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * @see     java.util.Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * @deprecated As of JDK version 1.1,
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   731
     * replaced by {@code Calendar.get(Calendar.DAY_OF_MONTH)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    public int getDate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        return normalize().getDayOfMonth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    /**
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   739
     * Sets the day of the month of this {@code Date} object to the
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   740
     * specified value. This {@code Date} object is modified so that
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * it represents a point in time within the specified day of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * month, with the year, month, hour, minute, and second the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * as before, as interpreted in the local time zone. If the date
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * was April 30, for example, and the date is set to 31, then it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * will be treated as if it were on May 1, because April has only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * 30 days.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     * @param   date   the day of the month value between 1-31.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * @see     java.util.Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     * @deprecated As of JDK version 1.1,
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   751
     * replaced by {@code Calendar.set(Calendar.DAY_OF_MONTH, int date)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    public void setDate(int date) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        getCalendarDate().setDayOfMonth(date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * Returns the day of the week represented by this date. The
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   760
     * returned value ({@code 0} = Sunday, {@code 1} = Monday,
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   761
     * {@code 2} = Tuesday, {@code 3} = Wednesday, {@code 4} =
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   762
     * Thursday, {@code 5} = Friday, {@code 6} = Saturday)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * represents the day of the week that contains or begins with
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   764
     * the instant in time represented by this {@code Date} object,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * as interpreted in the local time zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     * @return  the day of the week represented by this date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     * @see     java.util.Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * @deprecated As of JDK version 1.1,
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   770
     * replaced by {@code Calendar.get(Calendar.DAY_OF_WEEK)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    public int getDay() {
11130
c7093e306a34 7117487: Warnings Cleanup: some i18n classes in java.util and sun.util
okutsu
parents: 7668
diff changeset
   774
        return normalize().getDayOfWeek() - BaseCalendar.SUNDAY;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    /**
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   778
     * Returns the hour represented by this {@code Date} object. The
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   779
     * returned value is a number ({@code 0} through {@code 23})
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * representing the hour within the day that contains or begins
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   781
     * with the instant in time represented by this {@code Date}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * object, as interpreted in the local time zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     * @return  the hour represented by this date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * @see     java.util.Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * @deprecated As of JDK version 1.1,
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   787
     * replaced by {@code Calendar.get(Calendar.HOUR_OF_DAY)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
    public int getHours() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        return normalize().getHours();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    /**
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   795
     * Sets the hour of this {@code Date} object to the specified value.
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   796
     * This {@code Date} object is modified so that it represents a point
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * in time within the specified hour of the day, with the year, month,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * date, minute, and second the same as before, as interpreted in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * local time zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * @param   hours   the hour value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * @see     java.util.Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * @deprecated As of JDK version 1.1,
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   804
     * replaced by {@code Calendar.set(Calendar.HOUR_OF_DAY, int hours)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    public void setHours(int hours) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        getCalendarDate().setHours(hours);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * Returns the number of minutes past the hour represented by this date,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     * as interpreted in the local time zone.
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   814
     * The value returned is between {@code 0} and {@code 59}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * @return  the number of minutes past the hour represented by this date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     * @see     java.util.Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     * @deprecated As of JDK version 1.1,
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   819
     * replaced by {@code Calendar.get(Calendar.MINUTE)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    public int getMinutes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        return normalize().getMinutes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    /**
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   827
     * Sets the minutes of this {@code Date} object to the specified value.
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   828
     * This {@code Date} object is modified so that it represents a point
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * in time within the specified minute of the hour, with the year, month,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * date, hour, and second the same as before, as interpreted in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * local time zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * @param   minutes   the value of the minutes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * @see     java.util.Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * @deprecated As of JDK version 1.1,
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   836
     * replaced by {@code Calendar.set(Calendar.MINUTE, int minutes)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
    public void setMinutes(int minutes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        getCalendarDate().setMinutes(minutes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * Returns the number of seconds past the minute represented by this date.
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   845
     * The value returned is between {@code 0} and {@code 61}. The
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   846
     * values {@code 60} and {@code 61} can only occur on those
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * Java Virtual Machines that take leap seconds into account.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * @return  the number of seconds past the minute represented by this date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * @see     java.util.Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * @deprecated As of JDK version 1.1,
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   852
     * replaced by {@code Calendar.get(Calendar.SECOND)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
    public int getSeconds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        return normalize().getSeconds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
    /**
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   860
     * Sets the seconds of this {@code Date} to the specified value.
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   861
     * This {@code Date} object is modified so that it represents a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * point in time within the specified second of the minute, with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * the year, month, date, hour, and minute the same as before, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     * interpreted in the local time zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     * @param   seconds   the seconds value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     * @see     java.util.Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     * @deprecated As of JDK version 1.1,
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   869
     * replaced by {@code Calendar.set(Calendar.SECOND, int seconds)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    public void setSeconds(int seconds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        getCalendarDate().setSeconds(seconds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   878
     * represented by this {@code Date} object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     * @return  the number of milliseconds since January 1, 1970, 00:00:00 GMT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     *          represented by this date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
    public long getTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        return getTimeImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
    private final long getTimeImpl() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        if (cdate != null && !cdate.isNormalized()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
            normalize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        return fastTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
    /**
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   895
     * Sets this {@code Date} object to represent a point in time that is
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   896
     * {@code time} milliseconds after January 1, 1970 00:00:00 GMT.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     * @param   time   the number of milliseconds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    public void setTime(long time) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        fastTime = time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        cdate = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     * Tests if this date is before the specified date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     * @param   when   a date.
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   909
     * @return  {@code true} if and only if the instant of time
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   910
     *            represented by this {@code Date} object is strictly
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   911
     *            earlier than the instant represented by {@code when};
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   912
     *          {@code false} otherwise.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   913
     * @throws    NullPointerException if {@code when} is null.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
    public boolean before(Date when) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        return getMillisOf(this) < getMillisOf(when);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     * Tests if this date is after the specified date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * @param   when   a date.
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   923
     * @return  {@code true} if and only if the instant represented
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   924
     *          by this {@code Date} object is strictly later than the
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   925
     *          instant represented by {@code when};
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   926
     *          {@code false} otherwise.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   927
     * @throws    NullPointerException if {@code when} is null.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    public boolean after(Date when) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        return getMillisOf(this) > getMillisOf(when);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     * Compares two dates for equality.
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   935
     * The result is {@code true} if and only if the argument is
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   936
     * not {@code null} and is a {@code Date} object that
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
     * represents the same point in time, to the millisecond, as this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     * <p>
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   939
     * Thus, two {@code Date} objects are equal if and only if the
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   940
     * {@code getTime} method returns the same {@code long}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     * value for both.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     * @param   obj   the object to compare with.
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   944
     * @return  {@code true} if the objects are the same;
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   945
     *          {@code false} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     * @see     java.util.Date#getTime()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        return obj instanceof Date && getTime() == ((Date) obj).getTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
    /**
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   953
     * Returns the millisecond value of this {@code Date} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
     * without affecting its internal state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
    static final long getMillisOf(Date date) {
40457
21ae06f40614 8135055: java.util.Date.after(java.sql.Timestamp ) does not return correct results
rgoel
parents: 32649
diff changeset
   957
        if (date.getClass() != Date.class) {
21ae06f40614 8135055: java.util.Date.after(java.sql.Timestamp ) does not return correct results
rgoel
parents: 32649
diff changeset
   958
            return date.getTime();
21ae06f40614 8135055: java.util.Date.after(java.sql.Timestamp ) does not return correct results
rgoel
parents: 32649
diff changeset
   959
        }
4847
22fbbcbcab1d 6912866: (date) java.util.Date.before / after may be expensive
okutsu
parents: 2
diff changeset
   960
        if (date.cdate == null || date.cdate.isNormalized()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            return date.fastTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        BaseCalendar.Date d = (BaseCalendar.Date) date.cdate.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        return gcal.getTime(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
     * Compares two Dates for ordering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     *
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   970
     * @param   anotherDate   the {@code Date} to be compared.
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   971
     * @return  the value {@code 0} if the argument Date is equal to
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   972
     *          this Date; a value less than {@code 0} if this Date
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
     *          is before the Date argument; and a value greater than
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   974
     *      {@code 0} if this Date is after the Date argument.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     * @since   1.2
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   976
     * @throws    NullPointerException if {@code anotherDate} is null.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
    public int compareTo(Date anotherDate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        long thisTime = getMillisOf(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        long anotherTime = getMillisOf(anotherDate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        return (thisTime<anotherTime ? -1 : (thisTime==anotherTime ? 0 : 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * Returns a hash code value for this object. The result is the
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
   986
     * exclusive OR of the two halves of the primitive {@code long}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     * value returned by the {@link Date#getTime}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     * method. That is, the hash code is the value of the expression:
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 15658
diff changeset
   989
     * <blockquote><pre>{@code
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 15658
diff changeset
   990
     * (int)(this.getTime()^(this.getTime() >>> 32))
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 15658
diff changeset
   991
     * }</pre></blockquote>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     * @return  a hash code value for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        long ht = this.getTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        return (int) ht ^ (int) (ht >> 32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
    /**
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1001
     * Converts this {@code Date} object to a {@code String}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * of the form:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * dow mon dd hh:mm:ss zzz yyyy</pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     * where:<ul>
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1006
     * <li>{@code dow} is the day of the week ({@code Sun, Mon, Tue, Wed,
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1007
     *     Thu, Fri, Sat}).
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1008
     * <li>{@code mon} is the month ({@code Jan, Feb, Mar, Apr, May, Jun,
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1009
     *     Jul, Aug, Sep, Oct, Nov, Dec}).
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1010
     * <li>{@code dd} is the day of the month ({@code 01} through
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1011
     *     {@code 31}), as two decimal digits.
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1012
     * <li>{@code hh} is the hour of the day ({@code 00} through
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1013
     *     {@code 23}), as two decimal digits.
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1014
     * <li>{@code mm} is the minute within the hour ({@code 00} through
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1015
     *     {@code 59}), as two decimal digits.
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1016
     * <li>{@code ss} is the second within the minute ({@code 00} through
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1017
     *     {@code 61}, as two decimal digits.
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1018
     * <li>{@code zzz} is the time zone (and may reflect daylight saving
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     *     time). Standard time zone abbreviations include those
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1020
     *     recognized by the method {@code parse}. If time zone
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1021
     *     information is not available, then {@code zzz} is empty -
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     *     that is, it consists of no characters at all.
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1023
     * <li>{@code yyyy} is the year, as four decimal digits.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     * @return  a string representation of this date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     * @see     java.util.Date#toLocaleString()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     * @see     java.util.Date#toGMTString()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        // "EEE MMM dd HH:mm:ss zzz yyyy";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
        BaseCalendar.Date date = normalize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        StringBuilder sb = new StringBuilder(28);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        int index = date.getDayOfWeek();
11130
c7093e306a34 7117487: Warnings Cleanup: some i18n classes in java.util and sun.util
okutsu
parents: 7668
diff changeset
  1035
        if (index == BaseCalendar.SUNDAY) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
            index = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        convertToAbbr(sb, wtb[index]).append(' ');                        // EEE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        convertToAbbr(sb, wtb[date.getMonth() - 1 + 2 + 7]).append(' ');  // MMM
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        CalendarUtils.sprintf0d(sb, date.getDayOfMonth(), 2).append(' '); // dd
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        CalendarUtils.sprintf0d(sb, date.getHours(), 2).append(':');   // HH
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        CalendarUtils.sprintf0d(sb, date.getMinutes(), 2).append(':'); // mm
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        CalendarUtils.sprintf0d(sb, date.getSeconds(), 2).append(' '); // ss
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        TimeZone zi = date.getZone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        if (zi != null) {
11130
c7093e306a34 7117487: Warnings Cleanup: some i18n classes in java.util and sun.util
okutsu
parents: 7668
diff changeset
  1047
            sb.append(zi.getDisplayName(date.isDaylightTime(), TimeZone.SHORT, Locale.US)); // zzz
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
            sb.append("GMT");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        sb.append(' ').append(date.getYear());  // yyyy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
        return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
     * Converts the given name to its 3-letter abbreviation (e.g.,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
     * "monday" -> "Mon") and stored the abbreviation in the given
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1058
     * {@code StringBuilder}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
    private static final StringBuilder convertToAbbr(StringBuilder sb, String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        sb.append(Character.toUpperCase(name.charAt(0)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
        sb.append(name.charAt(1)).append(name.charAt(2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
        return sb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
    /**
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1067
     * Creates a string representation of this {@code Date} object in an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     * implementation-dependent form. The intent is that the form should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
     * be familiar to the user of the Java application, wherever it may
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
     * happen to be running. The intent is comparable to that of the
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1071
     * "{@code %c}" format supported by the {@code strftime()}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     * function of ISO&nbsp;C.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     * @return  a string representation of this date, using the locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     *          conventions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     * @see     java.text.DateFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     * @see     java.util.Date#toString()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     * @see     java.util.Date#toGMTString()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
     * @deprecated As of JDK version 1.1,
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1080
     * replaced by {@code DateFormat.format(Date date)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
    public String toLocaleString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        DateFormat formatter = DateFormat.getDateTimeInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        return formatter.format(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
    /**
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1089
     * Creates a string representation of this {@code Date} object of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
     * the form:
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 15658
diff changeset
  1091
     * <blockquote><pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
     * d mon yyyy hh:mm:ss GMT</pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
     * where:<ul>
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1094
     * <li><i>d</i> is the day of the month ({@code 1} through {@code 31}),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
     *     as one or two decimal digits.
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1096
     * <li><i>mon</i> is the month ({@code Jan, Feb, Mar, Apr, May, Jun, Jul,
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1097
     *     Aug, Sep, Oct, Nov, Dec}).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
     * <li><i>yyyy</i> is the year, as four decimal digits.
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1099
     * <li><i>hh</i> is the hour of the day ({@code 00} through {@code 23}),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
     *     as two decimal digits.
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1101
     * <li><i>mm</i> is the minute within the hour ({@code 00} through
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1102
     *     {@code 59}), as two decimal digits.
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1103
     * <li><i>ss</i> is the second within the minute ({@code 00} through
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1104
     *     {@code 61}), as two decimal digits.
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1105
     * <li><i>GMT</i> is exactly the ASCII letters "{@code GMT}" to indicate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
     *     Greenwich Mean Time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
     * </ul><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
     * The result does not depend on the local time zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
     * @return  a string representation of this date, using the Internet GMT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
     *          conventions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
     * @see     java.text.DateFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
     * @see     java.util.Date#toString()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
     * @see     java.util.Date#toLocaleString()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
     * @deprecated As of JDK version 1.1,
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1116
     * replaced by {@code DateFormat.format(Date date)}, using a
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1117
     * GMT {@code TimeZone}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
    public String toGMTString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        // d MMM yyyy HH:mm:ss 'GMT'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        long t = getTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        BaseCalendar cal = getCalendarSystem(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        BaseCalendar.Date date =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
            (BaseCalendar.Date) cal.getCalendarDate(getTime(), (TimeZone)null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        StringBuilder sb = new StringBuilder(32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        CalendarUtils.sprintf0d(sb, date.getDayOfMonth(), 1).append(' '); // d
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        convertToAbbr(sb, wtb[date.getMonth() - 1 + 2 + 7]).append(' ');  // MMM
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        sb.append(date.getYear()).append(' ');                            // yyyy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        CalendarUtils.sprintf0d(sb, date.getHours(), 2).append(':');      // HH
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
        CalendarUtils.sprintf0d(sb, date.getMinutes(), 2).append(':');    // mm
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
        CalendarUtils.sprintf0d(sb, date.getSeconds(), 2);                // ss
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        sb.append(" GMT");                                                // ' GMT'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
     * Returns the offset, measured in minutes, for the local time zone
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
     * relative to UTC that is appropriate for the time represented by
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1140
     * this {@code Date} object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     * For example, in Massachusetts, five time zones west of Greenwich:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     * new Date(96, 1, 14).getTimezoneOffset() returns 300</pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     * because on February 14, 1996, standard time (Eastern Standard Time)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     * is in use, which is offset five hours from UTC; but:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
     * new Date(96, 5, 1).getTimezoneOffset() returns 240</pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
     * because on June 1, 1996, daylight saving time (Eastern Daylight Time)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
     * is in use, which is offset only four hours from UTC.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
     * This method produces the same result as if it computed:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
     * (this.getTime() - UTC(this.getYear(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
     *                       this.getMonth(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
     *                       this.getDate(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
     *                       this.getHours(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
     *                       this.getMinutes(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
     *                       this.getSeconds())) / (60 * 1000)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
     * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
     * @return  the time-zone offset, in minutes, for the current time zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
     * @see     java.util.Calendar#ZONE_OFFSET
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
     * @see     java.util.Calendar#DST_OFFSET
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
     * @see     java.util.TimeZone#getDefault
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     * @deprecated As of JDK version 1.1,
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1166
     * replaced by {@code -(Calendar.get(Calendar.ZONE_OFFSET) +
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1167
     * Calendar.get(Calendar.DST_OFFSET)) / (60 * 1000)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
    public int getTimezoneOffset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        int zoneOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
        if (cdate == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
            TimeZone tz = TimeZone.getDefaultRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
            if (tz instanceof ZoneInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
                zoneOffset = ((ZoneInfo)tz).getOffsets(fastTime, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
                zoneOffset = tz.getOffset(fastTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
            normalize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
            zoneOffset = cdate.getZoneOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
        return -zoneOffset/60000;  // convert to minutes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
    private final BaseCalendar.Date getCalendarDate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
        if (cdate == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
            BaseCalendar cal = getCalendarSystem(fastTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
            cdate = (BaseCalendar.Date) cal.getCalendarDate(fastTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
                                                            TimeZone.getDefaultRef());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
        return cdate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
    private final BaseCalendar.Date normalize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        if (cdate == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
            BaseCalendar cal = getCalendarSystem(fastTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
            cdate = (BaseCalendar.Date) cal.getCalendarDate(fastTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
                                                            TimeZone.getDefaultRef());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
            return cdate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
        // Normalize cdate with the TimeZone in cdate first. This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
        // required for the compatible behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
        if (!cdate.isNormalized()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
            cdate = normalize(cdate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
        // If the default TimeZone has changed, then recalculate the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
        // fields with the new TimeZone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
        TimeZone tz = TimeZone.getDefaultRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
        if (tz != cdate.getZone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
            cdate.setZone(tz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
            CalendarSystem cal = getCalendarSystem(cdate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
            cal.getCalendarDate(fastTime, cdate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
        return cdate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
    // fastTime and the returned data are in sync upon return.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
    private final BaseCalendar.Date normalize(BaseCalendar.Date date) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        int y = date.getNormalizedYear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
        int m = date.getMonth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
        int d = date.getDayOfMonth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        int hh = date.getHours();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        int mm = date.getMinutes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        int ss = date.getSeconds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
        int ms = date.getMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
        TimeZone tz = date.getZone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
        // If the specified year can't be handled using a long value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
        // in milliseconds, GregorianCalendar is used for full
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        // compatibility with underflow and overflow. This is required
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        // by some JCK tests. The limits are based max year values -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        // years that can be represented by max values of d, hh, mm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
        // ss and ms. Also, let GregorianCalendar handle the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
        // cutover year so that we don't need to worry about the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        // transition here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
        if (y == 1582 || y > 280000000 || y < -280000000) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
            if (tz == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
                tz = TimeZone.getTimeZone("GMT");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
            GregorianCalendar gc = new GregorianCalendar(tz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
            gc.clear();
11130
c7093e306a34 7117487: Warnings Cleanup: some i18n classes in java.util and sun.util
okutsu
parents: 7668
diff changeset
  1245
            gc.set(GregorianCalendar.MILLISECOND, ms);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
            gc.set(y, m-1, d, hh, mm, ss);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
            fastTime = gc.getTimeInMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
            BaseCalendar cal = getCalendarSystem(fastTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
            date = (BaseCalendar.Date) cal.getCalendarDate(fastTime, tz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
            return date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
        BaseCalendar cal = getCalendarSystem(y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
        if (cal != getCalendarSystem(date)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
            date = (BaseCalendar.Date) cal.newCalendarDate(tz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
            date.setNormalizedDate(y, m, d).setTimeOfDay(hh, mm, ss, ms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
        // Perform the GregorianCalendar-style normalization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
        fastTime = cal.getTime(date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
        // In case the normalized date requires the other calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
        // system, we need to recalculate it using the other one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
        BaseCalendar ncal = getCalendarSystem(fastTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
        if (ncal != cal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
            date = (BaseCalendar.Date) ncal.newCalendarDate(tz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
            date.setNormalizedDate(y, m, d).setTimeOfDay(hh, mm, ss, ms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
            fastTime = ncal.getTime(date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
        return date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
     * Returns the Gregorian or Julian calendar system to use with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
     * given date. Use Gregorian from October 15, 1582.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
     * @param year normalized calendar year (not -1900)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
     * @return the CalendarSystem to use for the specified date
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
    private static final BaseCalendar getCalendarSystem(int year) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
        if (year >= 1582) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
            return gcal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        return getJulianCalendar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
    private static final BaseCalendar getCalendarSystem(long utc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        // Quickly check if the time stamp given by `utc' is the Epoch
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
        // or later. If it's before 1970, we convert the cutover to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        // local time to compare.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
        if (utc >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
            || utc >= GregorianCalendar.DEFAULT_GREGORIAN_CUTOVER
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
                        - TimeZone.getDefaultRef().getOffset(utc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
            return gcal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
        return getJulianCalendar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
    private static final BaseCalendar getCalendarSystem(BaseCalendar.Date cdate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
        if (jcal == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
            return gcal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
        if (cdate.getEra() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
            return jcal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
        return gcal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 29614
diff changeset
  1308
    private static final synchronized BaseCalendar getJulianCalendar() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
        if (jcal == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
            jcal = (BaseCalendar) CalendarSystem.forName("julian");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
        return jcal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
     * Save the state of this object to a stream (i.e., serialize it).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
     *
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1318
     * @serialData The value returned by {@code getTime()}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
     *             is emitted (long).  This represents the offset from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
     *             January 1, 1970, 00:00:00 GMT in milliseconds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
     */
57956
e0b8b019d2f5 8229997: Apply java.io.Serial annotations in java.base
darcy
parents: 52772
diff changeset
  1322
    @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
    private void writeObject(ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
         throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
    {
29614
c95b4a5f89d6 8075824: Add default[Read|Write]Object to java.util.Date
chegar
parents: 25859
diff changeset
  1326
        s.defaultWriteObject();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
        s.writeLong(getTimeImpl());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
     * Reconstitute this object from a stream (i.e., deserialize it).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
     */
57956
e0b8b019d2f5 8229997: Apply java.io.Serial annotations in java.base
darcy
parents: 52772
diff changeset
  1333
    @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
         throws IOException, ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
    {
29614
c95b4a5f89d6 8075824: Add default[Read|Write]Object to java.util.Date
chegar
parents: 25859
diff changeset
  1337
        s.defaultReadObject();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
        fastTime = s.readLong();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
    }
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1340
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1341
    /**
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1342
     * Obtains an instance of {@code Date} from an {@code Instant} object.
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1343
     * <p>
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1344
     * {@code Instant} uses a precision of nanoseconds, whereas {@code Date}
22629
c9ef7086f8ff 8032221: Typo in java.util.date
rriggs
parents: 18156
diff changeset
  1345
     * uses a precision of milliseconds.  The conversion will truncate any
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1346
     * excess precision information as though the amount in nanoseconds was
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1347
     * subject to integer division by one million.
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1348
     * <p>
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1349
     * {@code Instant} can store points on the time-line further in the future
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1350
     * and further in the past than {@code Date}. In this scenario, this method
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1351
     * will throw an exception.
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1352
     *
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1353
     * @param instant  the instant to convert
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1354
     * @return a {@code Date} representing the same point on the time-line as
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1355
     *  the provided instant
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
  1356
     * @throws    NullPointerException if {@code instant} is null.
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
  1357
     * @throws    IllegalArgumentException if the instant is too large to
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1358
     *  represent as a {@code Date}
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1359
     * @since 1.8
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1360
     */
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1361
    public static Date from(Instant instant) {
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1362
        try {
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1363
            return new Date(instant.toEpochMilli());
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1364
        } catch (ArithmeticException ex) {
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1365
            throw new IllegalArgumentException(ex);
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1366
        }
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1367
    }
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1368
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1369
    /**
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1370
     * Converts this {@code Date} object to an {@code Instant}.
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1371
     * <p>
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1372
     * The conversion creates an {@code Instant} that represents the same
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1373
     * point on the time-line as this {@code Date}.
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1374
     *
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1375
     * @return an instant representing the same point on the time-line as
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1376
     *  this {@code Date} object
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1377
     * @since 1.8
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1378
     */
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1379
    public Instant toInstant() {
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1380
        return Instant.ofEpochMilli(getTime());
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
  1381
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
}