Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/Date/Bug4955000.java
38812 views
1
/*
2
* Copyright (c) 2005, 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 4955000
27
* @summary Make sure that a Date and a GregorianCalendar produce the
28
* same date/time. Both are new implementations in 1.5.
29
*/
30
31
import java.util.*;
32
import static java.util.GregorianCalendar.*;
33
34
@SuppressWarnings("deprecation")
35
public class Bug4955000 {
36
// Tests for Date.UTC(), derived from JCK
37
// Date.miscTests.Date1025 and Date2015
38
public static void main(String[] args) {
39
TimeZone defaultTZ = TimeZone.getDefault();
40
try {
41
TimeZone.setDefault(TimeZone.getTimeZone("NST"));
42
GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
43
// Date1025
44
int[] years1 = {
45
Integer.MIN_VALUE,
46
Integer.MIN_VALUE + 1,
47
gc.getMinimum(YEAR) - 1,
48
gc.getMaximum(YEAR) + 1,
49
Integer.MAX_VALUE - 1,
50
Integer.MAX_VALUE
51
};
52
for (int i = 0; i < years1.length; i++) {
53
gc.clear();
54
gc.set(years1[i], gc.JANUARY, 1);
55
long t = gc.getTimeInMillis();
56
long utc = Date.UTC(years1[i] - 1900, 1-1, 1,
57
0, 0, 0); // Jan 1 00:00:00
58
if (t != utc) {
59
throw new RuntimeException("t (" + t + ") != utc (" + utc +")");
60
}
61
}
62
63
// Date2015
64
int years[] = {
65
gc.getGreatestMinimum(YEAR),
66
gc.getGreatestMinimum(YEAR) + 1,
67
-1,
68
0,
69
1,
70
gc.getLeastMaximum(YEAR) - 1,
71
gc.getLeastMaximum(YEAR)
72
};
73
74
int months[] = {
75
gc.getMinimum(MONTH),
76
gc.getMinimum(MONTH) + 1,
77
gc.getMaximum(MONTH) - 1,
78
gc.getMaximum(MONTH)
79
};
80
81
int dates[] = {
82
gc.getMinimum(DAY_OF_MONTH),
83
gc.getMinimum(DAY_OF_MONTH) + 1,
84
gc.getMaximum(DAY_OF_MONTH) - 1,
85
gc.getMaximum(DAY_OF_MONTH)
86
};
87
88
int hs[] = {
89
gc.getMinimum(HOUR),
90
gc.getMinimum(HOUR) + 1,
91
gc.getMaximum(HOUR) - 1,
92
gc.getMaximum(HOUR)
93
};
94
95
int ms[] = {
96
gc.getMinimum(MINUTE),
97
gc.getMinimum(MINUTE) + 1,
98
gc.getMaximum(MINUTE) - 1,
99
gc.getMaximum(MINUTE)
100
};
101
102
int ss[] = {
103
gc.getMinimum(SECOND),
104
gc.getMinimum(SECOND) + 1,
105
gc.getMaximum(SECOND) - 1,
106
gc.getMaximum(SECOND)
107
};
108
109
for(int i = 0; i < years.length; i++) {
110
for(int j = 0; j < months.length; j++) {
111
for(int k = 0; k < dates.length; k++) {
112
for(int m = 0; m < hs.length; m++) {
113
for(int n = 0; n < ms.length; n++) {
114
for(int p = 0; p < ss.length; p++) {
115
int year = years[i] - 1900;
116
int month = months[j];
117
int date = dates[k];
118
int hours = hs[m];
119
int minutes = ms[n];
120
int seconds = ss[p];
121
122
long result = Date.UTC(year, month, date,
123
hours, minutes, seconds);
124
125
gc.clear();
126
gc.set(year + 1900, month, date, hours, minutes, seconds);
127
128
long expected = gc.getTime().getTime();
129
130
if (expected != result) {
131
throw new RuntimeException("expected (" + expected
132
+ ") != result (" + result +")");
133
}
134
}
135
}
136
}
137
}
138
}
139
}
140
} finally {
141
TimeZone.setDefault(defaultTZ);
142
}
143
}
144
}
145
146