|
24 | 24 | /* |
25 | 25 | * @test |
26 | 26 | * @bug 8181157 8202537 8234347 8236548 8261279 8322647 8174269 8346948 |
27 | | - * 8354548 |
| 27 | + * 8354548 8381379 |
28 | 28 | * @modules jdk.localedata |
29 | 29 | * @summary Checks CLDR time zone names are generated correctly at |
30 | 30 | * either build or runtime |
31 | 31 | * @run junit TimeZoneNamesTest |
32 | 32 | */ |
33 | 33 |
|
34 | 34 | import java.text.DateFormatSymbols; |
| 35 | +import java.text.SimpleDateFormat; |
35 | 36 | import java.time.ZoneId; |
| 37 | +import java.time.ZonedDateTime; |
| 38 | +import java.time.format.DateTimeFormatter; |
36 | 39 | import java.time.format.TextStyle; |
37 | 40 | import java.util.Arrays; |
| 41 | +import java.util.Date; |
38 | 42 | import java.util.Locale; |
39 | 43 | import java.util.Objects; |
40 | 44 | import java.util.TimeZone; |
| 45 | +import java.util.stream.Stream; |
41 | 46 |
|
42 | 47 | import org.junit.jupiter.api.Test; |
43 | 48 | import org.junit.jupiter.params.ParameterizedTest; |
| 49 | +import org.junit.jupiter.params.provider.Arguments; |
44 | 50 | import org.junit.jupiter.params.provider.MethodSource; |
45 | 51 | import static org.junit.jupiter.api.Assertions.assertEquals; |
46 | 52 | import static org.junit.jupiter.api.Assertions.assertFalse; |
@@ -217,6 +223,18 @@ private static Object[][] sampleTZs() { |
217 | 223 | }; |
218 | 224 | } |
219 | 225 |
|
| 226 | + private static Stream<Arguments> explicitDstOffsets() { |
| 227 | + return Stream.of( |
| 228 | + Arguments.of(ZonedDateTime.of(2026, 4, 5, 0, 0, 0, 0, ZoneId.of("Europe/Dublin")), "Irish Standard Time"), |
| 229 | + Arguments.of(ZonedDateTime.of(2026, 12, 5, 0, 0, 0, 0, ZoneId.of("Europe/Dublin")), "Greenwich Mean Time"), |
| 230 | + Arguments.of(ZonedDateTime.of(2026, 4, 5, 0, 0, 0, 0, ZoneId.of("Eire")), "Irish Standard Time"), |
| 231 | + Arguments.of(ZonedDateTime.of(2026, 12, 5, 0, 0, 0, 0, ZoneId.of("Eire")), "Greenwich Mean Time"), |
| 232 | + Arguments.of(ZonedDateTime.of(2026, 4, 5, 0, 0, 0, 0, ZoneId.of("America/Vancouver")), "Pacific Daylight Time"), |
| 233 | + // This needs to change once TZDB adopts -7 offset year round, and CLDR uses explicit dst offset |
| 234 | + // namely, "Pacific Standard Time" -> "Pacific Daylight Time" |
| 235 | + Arguments.of(ZonedDateTime.of(2026, 12, 5, 0, 0, 0, 0, ZoneId.of("America/Vancouver")), "Pacific Standard Time") |
| 236 | + ); |
| 237 | + } |
220 | 238 |
|
221 | 239 | @ParameterizedTest |
222 | 240 | @MethodSource("sampleTZs") |
@@ -248,4 +266,19 @@ public void test_getZoneStrings() { |
248 | 266 | .anyMatch(name -> Objects.isNull(name) || name.isEmpty()), |
249 | 267 | "getZoneStrings() returned array containing non-empty string element(s)"); |
250 | 268 | } |
| 269 | + |
| 270 | + // Explicit metazone dst offset test. As of CLDR v48, only Europe/Dublin utilizes |
| 271 | + // this attribute, but will be used for America/Vancouver once CLDR adopts the |
| 272 | + // explicit offset for that zone, which warrants the test data modification. |
| 273 | + @ParameterizedTest |
| 274 | + @MethodSource("explicitDstOffsets") |
| 275 | + public void test_ExplicitMetazoneOffsets(ZonedDateTime zdt, String expected) { |
| 276 | + // java.time |
| 277 | + assertEquals(expected, DateTimeFormatter.ofPattern("zzzz").format(zdt)); |
| 278 | + |
| 279 | + // java.text/util |
| 280 | + var sdf = new SimpleDateFormat("zzzz"); |
| 281 | + sdf.setTimeZone(TimeZone.getTimeZone(zdt.getZone())); |
| 282 | + assertEquals(expected, sdf.format(Date.from(zdt.toInstant()))); |
| 283 | + } |
251 | 284 | } |
0 commit comments