33
33
import java .util .Date ;
34
34
import java .util .List ;
35
35
import java .util .SimpleTimeZone ;
36
+ import java .util .TimeZone ;
36
37
import java .time .DayOfWeek ;
37
38
import java .time .ZonedDateTime ;
38
39
import java .time .temporal .TemporalAdjusters ;
39
40
import jdk .test .lib .process .ProcessTools ;
40
41
import jdk .test .lib .process .OutputAnalyzer ;
41
42
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" ;
43
47
public static void main (String args []) throws Throwable {
44
48
if (args .length == 0 ) {
45
49
ProcessBuilder pb = ProcessTools .createJavaProcessBuilder (List .of ("CustomTzIDCheckDST" , "runTZTest" ));
46
50
pb .environment ().put ("TZ" , CUSTOM_TZ );
47
51
OutputAnalyzer output = ProcessTools .executeProcess (pb );
48
52
output .shouldHaveExitValue (0 );
53
+ pb .environment ().put ("TZ" , CUSTOM_TZ2 );
54
+ output = ProcessTools .executeProcess (pb );
55
+ output .shouldHaveExitValue (0 );
49
56
} else {
50
57
runTZTest ();
51
58
}
52
59
}
53
60
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 .
55
62
* This ensures the transition periods for Daylights Savings should be at March's last
56
63
* Sunday and October's last Sunday.
57
64
*/
58
65
private static void runTZTest () {
59
66
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 )) {
62
78
// We are in Daylight savings period.
63
79
if (time .toString ().endsWith ("GMT+02:00 " + Integer .toString (time .getYear () + 1900 )))
64
80
return ;
@@ -68,7 +84,7 @@ private static void runTZTest() {
68
84
}
69
85
70
86
// 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 );
72
88
}
73
89
74
90
private static ZonedDateTime getLastSundayOfMonth (ZonedDateTime date ) {
0 commit comments