Skip to content

Commit 5e2de89

Browse files
author
Ichiroh Takiguchi
committed
8299194: CustomTzIDCheckDST.java may fail at future date
Reviewed-by: naoto
1 parent 6ccee83 commit 5e2de89

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

test/jdk/java/util/TimeZone/CustomTzIDCheckDST.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,32 +33,48 @@
3333
import java.util.Date;
3434
import java.util.List;
3535
import java.util.SimpleTimeZone;
36+
import java.util.TimeZone;
3637
import java.time.DayOfWeek;
3738
import java.time.ZonedDateTime;
3839
import java.time.temporal.TemporalAdjusters;
3940
import jdk.test.lib.process.ProcessTools;
4041
import jdk.test.lib.process.OutputAnalyzer;
4142
public class CustomTzIDCheckDST {
42-
private static String CUSTOM_TZ = "MEZ-1MESZ,M3.5.0,M10.5.0";
43+
// Northern Hemisphere
44+
private static String CUSTOM_TZ = "MEZ-1MESZ,M3.5.0,M10.5.0/3";
45+
// Simulate Southern Hemisphere
46+
private static String CUSTOM_TZ2 = "MEZ-1MESZ,M10.5.0,M3.5.0/3";
4347
public static void main(String args[]) throws Throwable {
4448
if (args.length == 0) {
4549
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(List.of("CustomTzIDCheckDST", "runTZTest"));
4650
pb.environment().put("TZ", CUSTOM_TZ);
4751
OutputAnalyzer output = ProcessTools.executeProcess(pb);
4852
output.shouldHaveExitValue(0);
53+
pb.environment().put("TZ", CUSTOM_TZ2);
54+
output = ProcessTools.executeProcess(pb);
55+
output.shouldHaveExitValue(0);
4956
} else {
5057
runTZTest();
5158
}
5259
}
5360

54-
/* TZ code will always be set to "MEZ-1MESZ,M3.5.0,M10.5.0".
61+
/* TZ is set to "MEZ-1MESZ,M3.5.0,M10.5.0/3", it will be the northern hemisphere.
5562
* This ensures the transition periods for Daylights Savings should be at March's last
5663
* Sunday and October's last Sunday.
5764
*/
5865
private static void runTZTest() {
5966
Date time = new Date();
60-
if (new SimpleTimeZone(3600000, "MEZ-1MESZ", Calendar.MARCH, -1, Calendar.SUNDAY, 0,
61-
Calendar.OCTOBER, -1, Calendar.SUNDAY, 0).inDaylightTime(time)) {
67+
String tzStr = System.getenv("TZ");
68+
if (tzStr == null)
69+
throw new RuntimeException("Got unexpected timezone information: TZ is null");
70+
boolean nor = CUSTOM_TZ.equals(tzStr);
71+
TimeZone tz = new SimpleTimeZone(3600000, tzStr,
72+
nor ? Calendar.MARCH : Calendar.OCTOBER, -1,
73+
Calendar.SUNDAY, 3600000, SimpleTimeZone.UTC_TIME,
74+
nor ? Calendar.OCTOBER : Calendar.MARCH, -1,
75+
Calendar.SUNDAY, 3600000, SimpleTimeZone.UTC_TIME,
76+
3600000);
77+
if (tz.inDaylightTime(time)) {
6278
// We are in Daylight savings period.
6379
if (time.toString().endsWith("GMT+02:00 " + Integer.toString(time.getYear() + 1900)))
6480
return;
@@ -68,7 +84,7 @@ private static void runTZTest() {
6884
}
6985

7086
// Reaching here means time zone did not match up as expected.
71-
throw new RuntimeException("Got unexpected timezone information: " + time);
87+
throw new RuntimeException("Got unexpected timezone information: " + tzStr + " " + time);
7288
}
7389

7490
private static ZonedDateTime getLastSundayOfMonth(ZonedDateTime date) {

0 commit comments

Comments
 (0)