|
26 | 26 | import java.time.ZoneOffset; |
27 | 27 | import java.time.ZonedDateTime; |
28 | 28 | import java.time.format.DateTimeFormatter; |
| 29 | +import java.time.format.DateTimeParseException; |
29 | 30 | import java.time.temporal.TemporalAccessor; |
30 | 31 | import java.util.Date; |
31 | 32 | import java.util.HashMap; |
@@ -1064,43 +1065,37 @@ public void testAKSTZone() throws IOException { |
1064 | 1065 | final String inputString = "Thu Nov 13 04:35:51 AKST 2008"; // asctime + timezone1 |
1065 | 1066 |
|
1066 | 1067 | final long expectTs = 1226583351000L; |
1067 | | - assertEquals( |
1068 | | - expectTs, |
1069 | | - DateTimeFormatter.ofPattern(dateFormat, Locale.ENGLISH) |
1070 | | - .withZone(ZoneId.of("UTC")) |
1071 | | - .parse(inputString, Instant::from) |
1072 | | - .toEpochMilli()); |
1073 | 1068 |
|
1074 | | - // ensure english locale and root locale return the same date |
1075 | | - assertEquals( |
1076 | | - expectTs + "", |
1077 | | - DateTimeFormatter.ofPattern(dateFormat, Locale.ENGLISH) |
1078 | | - .withZone(ZoneId.of("UTC")) |
1079 | | - .parse(inputString, Instant::from) |
1080 | | - .toEpochMilli(), |
1081 | | - DateTimeFormatter.ofPattern(dateFormat, Locale.ROOT) |
1082 | | - .withZone(ZoneId.of("UTC")) |
1083 | | - .parse(inputString, Instant::from) |
1084 | | - .toEpochMilli()); |
| 1069 | + try { |
| 1070 | + // ensure english locale and root locale return the same date |
| 1071 | + assertEquals( |
| 1072 | + expectTs, |
| 1073 | + DateTimeFormatter.ofPattern(dateFormat, Locale.ENGLISH) |
| 1074 | + .withZone(ZoneId.of("UTC")) |
| 1075 | + .parse(inputString, Instant::from) |
| 1076 | + .toEpochMilli()); |
| 1077 | + |
| 1078 | + assertEquals( |
| 1079 | + expectTs, |
| 1080 | + DateTimeFormatter.ofPattern(dateFormat, Locale.ROOT) |
| 1081 | + .withZone(ZoneId.of("UTC")) |
| 1082 | + .parse(inputString, Instant::from) |
| 1083 | + .toEpochMilli()); |
| 1084 | + } catch (DateTimeParseException e) { |
| 1085 | + // If the JVM's java.locale.providers can't parse these, there is no hope of this test passing |
| 1086 | + assumeNoException("JVM's Locale provider is incompatible with this test", e); |
| 1087 | + } |
1085 | 1088 |
|
1086 | 1089 | assertParsedDate( |
1087 | 1090 | inputString, |
1088 | 1091 | Date.from(Instant.ofEpochMilli(expectTs)), |
1089 | 1092 | "parse-date-patterns-default-config"); |
1090 | 1093 |
|
1091 | | - // A bug in Java 9 (not in 8) causes this to fail! (not fixed yet?!) |
1092 | | - // see https://bugs.openjdk.java.net/browse/JDK-8189784 |
1093 | | - if (System.getProperty("java.version").startsWith("1.8.")) { |
1094 | | - // with daylight savings time timezone |
1095 | | - assertParsedDate( |
1096 | | - "Fri Oct 7 05:14:15 AKDT 2005", |
1097 | | - Date.from(inst20051007131415()), |
1098 | | - "parse-date-patterns-default-config"); |
1099 | | - } else { |
1100 | | - System.err.println( |
1101 | | - "Didn't test AKDT because only Java 1.8 does this right! This Java version is: " |
1102 | | - + System.getProperty("java.version")); |
1103 | | - } |
| 1094 | + // with daylight savings time timezone |
| 1095 | + assertParsedDate( |
| 1096 | + "Fri Oct 7 05:14:15 AKDT 2005", |
| 1097 | + Date.from(inst20051007131415()), |
| 1098 | + "parse-date-patterns-default-config"); |
1104 | 1099 | } |
1105 | 1100 |
|
1106 | 1101 | public void testEDTZone() throws IOException { |
|
0 commit comments