Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/util/Date/DateRegression.java
41149 views
1
/*
2
* Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 4023247 4027685 4032037 4072029 4073003 4118010 4120606 4133833 4136916 6274757 6314387
27
* @library /java/text/testlib
28
*/
29
30
import java.util.*;
31
32
@SuppressWarnings("deprecation")
33
public class DateRegression extends IntlTest {
34
35
public static void main(String[] args) throws Exception {
36
new DateRegression().run(args);
37
}
38
39
/**
40
* @bug 4023247
41
*/
42
public void Test4023247() {
43
Date d1 = new Date(0);
44
Date d2 = new Date(0);
45
46
d1.setYear(96);
47
d1.setMonth(11);
48
d1.setDate(22);
49
d1.setHours(0);
50
d1.setMinutes(0);
51
d1.setSeconds(0);
52
53
d2.setYear(96);
54
d2.setMonth(11);
55
d2.setDate(22);
56
d2.setHours(0);
57
d2.setMinutes(0);
58
d2.setSeconds(0);
59
60
if (d1.hashCode() != d2.hashCode())
61
errln("Fail: Date hashCode misbehaves");
62
}
63
64
/**
65
* @bug 4027685
66
*/
67
public void Test4027685() {
68
// Should be 01/16/97 00:00:00
69
Date nite = new Date("16-JAN-97 12:00 AM");
70
// Should be 01/16/97 12:00:00
71
Date noon = new Date("16-JAN-97 12:00 PM");
72
73
logln("Midnight = " + nite + ", Noon = " + noon);
74
if (!nite.equals(new Date(97, Calendar.JANUARY, 16, 0, 0)) ||
75
!noon.equals(new Date(97, Calendar.JANUARY, 16, 12, 0)))
76
errln("Fail: Nite/Noon confused");
77
}
78
79
/**
80
* @bug 4032037
81
*/
82
public void Test4032037() {
83
Date ref = new Date(97, 1, 10);
84
Date d = new Date(Date.parse("2/10/97"));
85
logln("Date.parse(2/10/97) => " + d);
86
if (!d.equals(ref)) errln("Fail: Want " + ref + " Got " + d);
87
d = new Date(Date.parse("10 feb 1997"));
88
logln("Date.parse(10 feb 1997) => " + d);
89
if (!d.equals(ref)) errln("Fail: Want " + ref + " Got " + d);
90
d = new Date("2/10/97");
91
logln("Date(2/10/97) => " + d);
92
if (!d.equals(ref)) errln("Fail: Want " + ref + " Got " + d);
93
d = new Date("10 feb 1997");
94
logln("Date(10 feb 1997) => " + d);
95
if (!d.equals(ref)) errln("Fail: Want " + ref + " Got " + d);
96
}
97
98
/**
99
* @bug 4072029
100
*/
101
public void Test4072029() {
102
TimeZone saveZone = TimeZone.getDefault();
103
104
try {
105
TimeZone.setDefault(TimeZone.getTimeZone("PST"));
106
Date now = new Date();
107
String s = now.toString();
108
Date now2 = new Date(now.toString());
109
String s2 = now2.toString(); // An hour's difference
110
111
if (!s.equals(s2) ||
112
Math.abs(now.getTime() - now2.getTime()) > 60000 /*one min*/) {
113
errln("Fail: Roundtrip toString/parse");
114
}
115
}
116
finally {
117
TimeZone.setDefault(saveZone);
118
}
119
}
120
121
/**
122
* @bug 4073003
123
*/
124
public void Test4073003() {
125
Date d = new Date(Date.parse("01/02/1984"));
126
if (!d.equals(new Date(84, 0, 2)))
127
errln("Fail: Want 1/2/1984 Got " + d);
128
d = new Date(Date.parse("02/03/2012"));
129
if (!d.equals(new Date(112, 1, 3)))
130
errln("Fail: Want 2/3/2012 Got " + d);
131
d = new Date(Date.parse("03/04/15"));
132
if (!d.equals(new Date(115, 2, 4)))
133
errln("Fail: Want 3/4/2015 Got " + d);
134
}
135
136
/**
137
* @bug 4118010
138
* Regress bug:
139
* Feb. 2000 has 29 days, but Date(2000, 1, 29) returns March 01, 2000
140
* NOTE: This turned out to be a user error (passing in 2000 instead
141
* of 2000-1900 to the Date constructor).
142
*/
143
public void Test4118010() {
144
Date d=new java.util.Date(2000-1900, Calendar.FEBRUARY, 29);
145
int m=d.getMonth();
146
int date=d.getDate();
147
if (m != Calendar.FEBRUARY ||
148
date != 29)
149
errln("Fail: Want Feb 29, got " + d);
150
}
151
152
/**
153
* @bug 4120606
154
* Date objects share state after cloning.
155
*/
156
public void Test4120606() {
157
Date d = new Date(98, Calendar.JUNE, 24);
158
d.setMonth(Calendar.MAY);
159
Date e = (Date)d.clone();
160
d.setMonth(Calendar.FEBRUARY);
161
if (e.getMonth() != Calendar.MAY) {
162
errln("Cloned Date objects share state");
163
}
164
}
165
166
/**
167
* @bug 4133833
168
* Date constructor crashes with parameters out of range, when it should
169
* normalize.
170
*/
171
public void Test4133833() {
172
Date date = new java.util.Date(12,15,19);
173
Date exp = new Date(1913-1900, Calendar.APRIL, 19);
174
if (!date.equals(exp))
175
errln("Fail: Want " + exp +
176
"; got " + date);
177
}
178
179
/**
180
* @bug 4136916
181
* Date.toString() throws exception in 1.2b4-E
182
* CANNOT REPRODUCE this bug
183
*/
184
public void Test4136916() {
185
Date time = new Date();
186
logln(time.toString());
187
}
188
189
/**
190
* @bug 6274757
191
* Date getTime and toString interaction for some time values
192
*/
193
public void Test6274757() {
194
TimeZone savedTz = TimeZone.getDefault();
195
try {
196
// Use a time zone west of GMT.
197
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
198
TimeZone jdkGMT = TimeZone.getTimeZone("GMT");
199
Calendar jdkCal = Calendar.getInstance(jdkGMT);
200
jdkCal.clear();
201
jdkCal.set(1582, Calendar.OCTOBER, 15);
202
logln("JDK time: " + jdkCal.getTime().getTime() );
203
logln("JDK time (str): " + jdkCal.getTime() );
204
logln("Day of month: " + jdkCal.get(Calendar.DAY_OF_MONTH));
205
Date co = jdkCal.getTime();
206
logln("Change over (Oct 15 1582) = " + co + " (" +
207
co.getTime() + ")");
208
long a = jdkCal.getTime().getTime();
209
Date c = jdkCal.getTime();
210
c.toString();
211
long b = c.getTime();
212
213
if (a != b) {
214
errln("ERROR: " + a + " != " + b);
215
} else {
216
logln(a + " = " + b);
217
}
218
} finally {
219
TimeZone.setDefault(savedTz);
220
}
221
}
222
223
/**
224
* @bug 6314387
225
* JCK6.0: api/java_util/Date/index.html#misc fails, mustang
226
*/
227
public void Test6314387() {
228
Date d = new Date(Long.MAX_VALUE);
229
int y = d.getYear();
230
if (y != 292277094) {
231
errln("yesr: got " + y + ", expected 292277094");
232
}
233
d = new Date(Long.MIN_VALUE);
234
y = d.getYear();
235
if (y != 292267155) {
236
errln("yesr: got " + y + ", expected 292267155");
237
}
238
}
239
}
240
241
//eof
242
243