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