Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/Calendar/bug4514831.java
47182 views
1
/*
2
* Copyright (c) 2002, 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 4514831
27
* @summary Confirm that GregorianCalendar.roll() works properly during transition from Daylight Saving Time to Standard Time.
28
*/
29
30
import java.util.*;
31
32
public class bug4514831 {
33
34
public static void main(String[] args) {
35
Locale savedLocale = Locale.getDefault();
36
TimeZone savedTimeZone = TimeZone.getDefault();
37
boolean err = false;
38
39
String golden_data1 ="27-28 28-29 29-30 30-31 31-1 1-2 2-3 ";
40
String golden_data2 ="27-28 28-29 29-30 30-31 31-25 25-26 26-27 ";
41
String golden_data3 ="1-8 8-15 15-22 22-29 29-1 1-8 8-15 ";
42
43
try {
44
Locale.setDefault(Locale.US);
45
TimeZone.setDefault(TimeZone.getTimeZone("US/Pacific"));
46
47
String test_roll = "";
48
GregorianCalendar c_roll = new GregorianCalendar(2001, Calendar.OCTOBER, 27);
49
for (int i=0; i < 7; i++) {
50
test_roll += c_roll.get(c_roll.DAY_OF_MONTH) + "-";
51
c_roll.roll(c_roll.DAY_OF_YEAR, true);
52
test_roll += c_roll.get(c_roll.DAY_OF_MONTH) + " ";
53
}
54
if (!test_roll.equals(golden_data1)) {
55
err = true;
56
System.err.println("Wrong roll(DAY_OF_YEAR) transition: got "+
57
test_roll + "expected " + golden_data1);
58
}
59
60
test_roll = "";
61
c_roll = new GregorianCalendar(2001, Calendar.OCTOBER, 27);
62
c_roll.setFirstDayOfWeek(Calendar.THURSDAY);
63
for (int i=0; i < 7; i++) {
64
test_roll += c_roll.get(c_roll.DAY_OF_MONTH) + "-";
65
c_roll.roll(c_roll.DAY_OF_WEEK, true);
66
test_roll += c_roll.get(c_roll.DAY_OF_MONTH) + " ";
67
}
68
if (!test_roll.equals(golden_data2)) {
69
err = true;
70
System.err.println("Wrong roll(DAY_OF_WEEK) transition: got "+
71
test_roll + "expected " + golden_data2);
72
}
73
74
test_roll = "";
75
c_roll = new GregorianCalendar(2001, Calendar.OCTOBER, 1);
76
for (int i=0; i < 7; i++) {
77
test_roll += c_roll.get(c_roll.DAY_OF_MONTH) + "-";
78
c_roll.roll(c_roll.DAY_OF_WEEK_IN_MONTH, true);
79
test_roll += c_roll.get(c_roll.DAY_OF_MONTH) + " ";
80
}
81
if (!test_roll.equals(golden_data3)) {
82
err = true;
83
System.err.println("Wrong roll(DAY_OF_WEEK_IN_MONTH) transition: got "+
84
test_roll + "expected " + golden_data3);
85
}
86
} finally {
87
Locale.setDefault(savedLocale);
88
TimeZone.setDefault(savedTimeZone);
89
}
90
91
if (err) {
92
throw new RuntimeException("Wrong roll() transition");
93
}
94
}
95
}
96
97