Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-aarch32-jdk8u
Path: blob/jdk8u272-b10-aarch32-20201026/jdk/test/java/text/Format/DateFormat/Bug8141243.java
48795 views
1
/*
2
* Copyright (c) 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 8141243
27
* @summary Make sure that SimpleDateFormat parses "UTC" as the UTC time zone.
28
* @run main Bug8141243
29
*/
30
31
import java.text.DateFormat;
32
import java.text.ParseException;
33
import java.text.SimpleDateFormat;
34
import java.util.ArrayList;
35
import java.util.Date;
36
import java.util.List;
37
import java.util.Locale;
38
import java.util.TimeZone;
39
import static java.util.TimeZone.*;
40
41
public class Bug8141243 {
42
public static void main(String[] args) {
43
TimeZone UTC = TimeZone.getTimeZone("UTC");
44
TimeZone initTz = TimeZone.getDefault();
45
46
List<String> errors = new ArrayList<>();
47
try {
48
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
49
for (Locale locale : DateFormat.getAvailableLocales()) {
50
// exclude any locales which localize "UTC".
51
String utc = UTC.getDisplayName(false, SHORT, locale);
52
if (!"UTC".equals(utc)) {
53
System.out.println("Skipping " + locale + " due to localized UTC name: " + utc);
54
continue;
55
}
56
SimpleDateFormat fmt = new SimpleDateFormat("z", locale);
57
try {
58
Date date = fmt.parse("UTC");
59
// Parsed one may not exactly be UTC. Universal, UCT, etc. are equivalents.
60
if (!fmt.getTimeZone().getID().matches("(Etc/)?(UTC|Universal|UCT|Zulu)")) {
61
errors.add("timezone: " + fmt.getTimeZone().getID()
62
+ ", locale: " + locale);
63
}
64
} catch (ParseException e) {
65
errors.add("parse exception: " + e + ", locale: " + locale);
66
}
67
}
68
} finally {
69
// Restore the default time zone
70
TimeZone.setDefault(initTz);
71
}
72
73
if (!errors.isEmpty()) {
74
System.out.println("Got unexpected results:");
75
for (String s : errors) {
76
System.out.println(" " + s);
77
}
78
throw new RuntimeException("Test failed.");
79
} else {
80
System.out.println("Test passed.");
81
}
82
}
83
}
84
85