Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/text/Format/DateFormat/Bug4845901.java
41152 views
1
/*
2
* Copyright (c) 2004, 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 4845901
27
* @summary Make sure that SimpleDateFormat.parse() can distinguish
28
* the same time zone abbreviation for standard and daylight saving
29
* time.
30
* @library /java/text/testlib
31
* @run main Bug4845901
32
*/
33
34
import java.util.*;
35
import java.text.SimpleDateFormat;
36
37
public class Bug4845901 {
38
public static void main (String args[]) {
39
Locale locale = Locale.getDefault();
40
if (!TestUtils.usesGregorianCalendar(locale)) {
41
System.out.println("Skipping this test because locale is " + locale);
42
return;
43
}
44
45
TimeZone savedTZ = TimeZone.getDefault();
46
TimeZone.setDefault(TimeZone.getTimeZone("Australia/Sydney"));
47
SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss.SSS z");
48
try {
49
testParse(sdf, "2003.01.13 11:10:00.802 AEDT", 11);
50
testParse(sdf, "2003.06.12 11:10:00.802 AEST", 11);
51
testParse(sdf, "2004.12.24 10:10:00.002 AEDT", 10);
52
testParse(sdf, "2004.08.10 10:10:00.002 AEST", 10);
53
} finally {
54
TimeZone.setDefault(savedTZ);
55
}
56
}
57
58
@SuppressWarnings("deprecation")
59
static void testParse(SimpleDateFormat sdf, String str, int expectedHour) {
60
try {
61
Date parsedDate = sdf.parse(str);
62
if (parsedDate.getHours() != expectedHour) {
63
throw new RuntimeException(
64
"parsed date has wrong hour: " + parsedDate.getHours()
65
+ ", expected: " + expectedHour
66
+ "\ngiven string: " + str
67
+ "\nparsedDate = " + parsedDate);
68
}
69
} catch (java.text.ParseException e) {
70
throw new RuntimeException("parse exception", e);
71
}
72
}
73
}
74
75