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