Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/text/Format/DateFormat/Bug6530336.java
41152 views
1
/*
2
* Copyright (c) 2007, 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 6530336 6537997 8008577
27
* @library /java/text/testlib
28
* @run main/othervm -Djava.locale.providers=COMPAT,SPI Bug6530336
29
*/
30
31
import java.text.SimpleDateFormat;
32
import java.util.Calendar;
33
import java.util.Date;
34
import java.util.Locale;
35
import java.util.TimeZone;
36
37
public class Bug6530336 {
38
39
public static void main(String[] args) throws Exception {
40
Locale defaultLocale = Locale.getDefault();
41
TimeZone defaultTimeZone = TimeZone.getDefault();
42
43
boolean err = false;
44
45
try {
46
Locale locales[] = Locale.getAvailableLocales();
47
TimeZone timezone_LA = TimeZone.getTimeZone("America/Los_Angeles");
48
TimeZone.setDefault(timezone_LA);
49
50
TimeZone timezones[] = {
51
TimeZone.getTimeZone("America/New_York"),
52
TimeZone.getTimeZone("America/Denver"),
53
};
54
55
String[] expected = {
56
"Sun Jul 15 12:00:00 PDT 2007",
57
"Sun Jul 15 14:00:00 PDT 2007",
58
};
59
60
Date[] dates = new Date[2];
61
62
for (int i = 0; i < locales.length; i++) {
63
Locale locale = locales[i];
64
if (!TestUtils.usesGregorianCalendar(locale)) {
65
continue;
66
}
67
68
Locale.setDefault(locale);
69
70
for (int j = 0; j < timezones.length; j++) {
71
Calendar cal = Calendar.getInstance(timezones[j]);
72
cal.set(2007, 6, 15, 15, 0, 0);
73
dates[j] = cal.getTime();
74
}
75
76
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
77
78
for (int j = 0; j < timezones.length; j++) {
79
sdf.setTimeZone(timezones[j]);
80
String date = sdf.format(dates[j]);
81
sdf.setTimeZone(timezone_LA);
82
String date_LA = sdf.parse(date).toString();
83
84
if (!expected[j].equals(date_LA)) {
85
System.err.println("Got wrong Pacific time (" +
86
date_LA + ") for (" + date + ") in " + locale +
87
" in " + timezones[j] +
88
".\nExpected=" + expected[j]);
89
err = true;
90
}
91
}
92
}
93
}
94
catch (Exception e) {
95
e.printStackTrace();
96
err = true;
97
}
98
finally {
99
Locale.setDefault(defaultLocale);
100
TimeZone.setDefault(defaultTimeZone);
101
102
if (err) {
103
throw new RuntimeException("Failed.");
104
}
105
}
106
}
107
108
}
109
110