Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/text/Format/DateFormat/Bug6645292.java
41152 views
1
/*
2
* Copyright (c) 2008, 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 6645292
27
* @summary Make sure to parse a DST time zone name with which the
28
* last DST rule doesn't observe DST.
29
*/
30
31
import java.text.*;
32
import java.util.*;
33
import static java.util.Calendar.*;
34
35
public class Bug6645292 {
36
public static void main(String[] args) {
37
Locale loc = Locale.getDefault();
38
TimeZone zone = TimeZone.getDefault();
39
try {
40
Locale.setDefault(Locale.US);
41
// Use "Asia/Shanghai" with an old time stamp rather than
42
// "Australia/Perth" because if Perth decides to obserb DST
43
// permanently, that decision will make this test case
44
// useless. There's the same risk with China, though.
45
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai"));
46
Calendar cal = Calendar.getInstance();
47
cal.clear();
48
cal.set(1986, JUNE, 1);
49
Date d1 = cal.getTime();
50
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss zzzz");
51
String s = df.format(d1);
52
Date d2 = null;
53
try {
54
d2 = df.parse(s);
55
} catch (Exception e) {
56
throw new RuntimeException(e);
57
}
58
if (!d1.equals(d2)) {
59
throw new RuntimeException("d1 (" + d1 + ") != d2 (" + d2 + ")");
60
}
61
} finally {
62
Locale.setDefault(loc);
63
TimeZone.setDefault(zone);
64
}
65
}
66
}
67
68