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