From 07373561800683407b14132f9a2e9448406e854b Mon Sep 17 00:00:00 2001 From: Naoto Sato Date: Fri, 13 Oct 2023 13:10:32 -0700 Subject: [PATCH] substitute letters --- .../tools/cldrconverter/CLDRConverter.java | 89 +++++++++++-------- .../test/java/time/format/TestUTCParse.java | 10 +-- .../util/TimeZone/CLDRDisplayNamesTest.java | 16 ++-- test/jdk/sun/text/resources/LocaleData.cldr | 4 +- .../sun/text/resources/LocaleDataTest.java | 2 +- 5 files changed, 67 insertions(+), 54 deletions(-) diff --git a/make/jdk/src/classes/build/tools/cldrconverter/CLDRConverter.java b/make/jdk/src/classes/build/tools/cldrconverter/CLDRConverter.java index e7699b0348181..4578be46f42ac 100644 --- a/make/jdk/src/classes/build/tools/cldrconverter/CLDRConverter.java +++ b/make/jdk/src/classes/build/tools/cldrconverter/CLDRConverter.java @@ -30,7 +30,6 @@ import java.io.IOException; import java.io.UncheckedIOException; import java.nio.file.*; -import java.text.MessageFormat; import java.time.*; import java.util.*; import java.util.ResourceBundle.Control; @@ -92,6 +91,8 @@ public class CLDRConverter { static final String META_EMPTY_ZONE_NAME = "EMPTY_ZONE"; static final String[] EMPTY_ZONE = {"", "", "", "", "", ""}; static final String META_ETCUTC_ZONE_NAME = "ETC_UTC"; + private static final String SEP = "\u00A0"; // NBSP + private static final Pattern OFFSET_PATTERN = Pattern.compile(("([-+]\\d{2})(\\d{2})*")); private static SupplementDataParseHandler handlerSuppl; private static LikelySubtagsParseHandler handlerLikelySubtags; @@ -125,7 +126,8 @@ public class CLDRConverter { static Map dayPeriodRules; // TZDB Short Names Map - private static Map tzdbShortNamesMap; + private static final Map tzdbShortNamesMap = HashMap.newHashMap(512); + private static final Map tzdbSubstLetters = HashMap.newHashMap(512); static enum DraftType { UNCONFIRMED, @@ -289,7 +291,7 @@ public static void main(String[] args) throws Exception { dayPeriodRules = generateRules(handlerDayPeriodRule); // TZDB short names map - tzdbShortNamesMap = generateTZDBShortNamesMap(); + generateTZDBShortNamesMap(); List bundles = readBundleList(); convertBundles(bundles); @@ -1257,48 +1259,60 @@ private static Map coverageLevelsMap() throws Exception { return covMap; } - private static Map generateTZDBShortNamesMap() throws IOException { - final Map shortNameMap = HashMap.newHashMap(1024); + private static void generateTZDBShortNamesMap() throws IOException { Files.walk(Path.of(tzDataDir), 1, FileVisitOption.FOLLOW_LINKS) - .map(Path::toFile) - .filter(File::isFile) - .forEach(f -> { - try { - String zone = null; - String format = null; - for (var line : Files.readAllLines(f.toPath())) { - if (line.contains("#STDOFF")) continue; - line = line.replaceAll("[ \t]*#.*", ""); - if (line.startsWith("Zone")) { - var s = line.split("[ \t]+", -1); - zone = s[1]; - format = s[4]; - } else { - if (zone != null) { - if (line.isBlank()) { - shortNameMap.put(zone, format); - zone = null; - format = null; - } else { - format = line.split("[ \t]+", -1)[3]; - } + .map(Path::toFile) + .filter(File::isFile) + .forEach(f -> { + try { + String zone = null; + String rule = null; + String format = null; + for (var line : Files.readAllLines(f.toPath())) { + if (line.contains("#STDOFF")) continue; + line = line.replaceAll("[ \t]*#.*", ""); + + // Zone + if (line.startsWith("Zone")) { + var zl = line.split("[ \t]+", -1); + zone = zl[1]; + rule = zl[3]; + format = zl[4]; + } else { + if (zone != null) { + if (line.isBlank()) { + tzdbShortNamesMap.put(zone, format + SEP + rule); + zone = null; + rule = null; + format = null; + } else { + var s = line.split("[ \t]+", -1); + rule = s[2]; + format = s[3]; } } + } + // Rule + if (line.startsWith("Rule")) { + var rl = line.split("[ \t]+", -1); + tzdbSubstLetters.put(rl[1] + SEP + (rl[8].equals("0") ? "std" : "dst"), rl[9].replace("-", "")); } - } catch (IOException ioe) { - throw new UncheckedIOException(ioe); } - }); - return shortNameMap; + } catch (IOException ioe) { + throw new UncheckedIOException(ioe); + } + }); } // private static void fillTZDBShortNames(String tzid, String[] names) { - var format = tzdbShortNamesMap.get(tzid); - if (format != null) { + var val = tzdbShortNamesMap.get(tzid); + if (val != null) { + var format = val.split(SEP)[0]; + var rule = val.split(SEP)[1]; IntStream.of(1, 3, 5).forEach(i -> { if (names[i] == null) { - names[i] = getTZDBShortName(format, i); + names[i] = getTZDBShortName(format, rule, i); } }); } @@ -1306,11 +1320,11 @@ private static void fillTZDBShortNames(String tzid, String[] names) { // fmt could be either // X%sT, +XX/+YY, or +XX - private static final String getTZDBShortName(String f, int i) { + private static String getTZDBShortName(String f, String r, int i) { if (f.contains("%s")) { return switch (i) { - case 1 -> f.formatted("S"); - case 3 -> f.formatted("D"); + case 1 -> f.formatted(tzdbSubstLetters.get(r + SEP + "std")); + case 3 -> f.formatted(tzdbSubstLetters.get(r + SEP + "dst")); case 5 -> f.formatted(""); default -> throw new InternalError(); }; @@ -1325,7 +1339,6 @@ private static final String getTZDBShortName(String f, int i) { } } - private final static Pattern OFFSET_PATTERN = Pattern.compile(("([-+]\\d{2})(\\d{2})*")); private static String convertGMTName(String f) { var m = OFFSET_PATTERN.matcher(f); diff --git a/test/jdk/java/time/test/java/time/format/TestUTCParse.java b/test/jdk/java/time/test/java/time/format/TestUTCParse.java index 3f991810f8b2b..6da94f04f0413 100644 --- a/test/jdk/java/time/test/java/time/format/TestUTCParse.java +++ b/test/jdk/java/time/test/java/time/format/TestUTCParse.java @@ -23,7 +23,7 @@ /* * @test * @modules jdk.localedata - * @bug 8303440 + * @bug 8303440 8317979 * @summary Test parsing "UTC-XX:XX" text works correctly */ package test.java.time.format; @@ -43,8 +43,8 @@ public class TestUTCParse { static { - // Assuming CLDR's SHORT name for "America/Los_Angeles" - // produces "UTC\u212208:00" + // Assuming CLDR's SHORT name for "America/Juneau" + // produces "UTC\u212209:00" System.setProperty("java.locale.providers", "CLDR"); } @@ -60,9 +60,9 @@ public Object[][] utcZoneIdStrings() { @Test public void testUTCShortNameRoundTrip() { var fmt = DateTimeFormatter.ofPattern("z", Locale.FRANCE); - var zdt = ZonedDateTime.of(2023, 3, 3, 0, 0, 0, 0, ZoneId.of("America/Los_Angeles")); + var zdt = ZonedDateTime.of(2023, 3, 3, 0, 0, 0, 0, ZoneId.of("America/Juneau")); var formatted = fmt.format(zdt); - assertEquals(formatted, "UTC\u221208:00"); + assertEquals(formatted, "UTC\u221209:00"); assertEquals(fmt.parse(formatted).query(TemporalQueries.zoneId()), zdt.getZone()); } diff --git a/test/jdk/java/util/TimeZone/CLDRDisplayNamesTest.java b/test/jdk/java/util/TimeZone/CLDRDisplayNamesTest.java index 67a082410ecbf..2ff278a583c33 100644 --- a/test/jdk/java/util/TimeZone/CLDRDisplayNamesTest.java +++ b/test/jdk/java/util/TimeZone/CLDRDisplayNamesTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,7 +24,7 @@ /* * @test * @bug 8005471 8008577 8129881 8130845 8136518 8181157 8210490 8220037 - * 8234347 8236548 + * 8234347 8236548 8317979 * @modules jdk.localedata * @run main/othervm -Djava.locale.providers=CLDR CLDRDisplayNamesTest * @summary Make sure that localized time zone names of CLDR are used @@ -48,27 +48,27 @@ public class CLDRDisplayNamesTest { { "ja-JP", "\u30a2\u30e1\u30ea\u30ab\u592a\u5e73\u6d0b\u6a19\u6e96\u6642", - "GMT-08:00", + "PST", "\u30a2\u30e1\u30ea\u30ab\u592a\u5e73\u6d0b\u590f\u6642\u9593", - "GMT-07:00", + "PDT", //"\u30a2\u30e1\u30ea\u30ab\u592a\u5e73\u6d0b\u6642\u9593", //"PT" }, { "zh-CN", "\u5317\u7f8e\u592a\u5e73\u6d0b\u6807\u51c6\u65f6\u95f4", - "GMT-08:00", + "PST", "\u5317\u7f8e\u592a\u5e73\u6d0b\u590f\u4ee4\u65f6\u95f4", - "GMT-07:00", + "PDT", //"\u5317\u7f8e\u592a\u5e73\u6d0b\u65f6\u95f4", //"PT", }, { "de-DE", "Nordamerikanische Westk\u00fcsten-Normalzeit", - "GMT-08:00", + "PST", "Nordamerikanische Westk\u00fcsten-Sommerzeit", - "GMT-07:00", + "PDT", //"Nordamerikanische Westk\u00fcstenzeit", //"PT", }, diff --git a/test/jdk/sun/text/resources/LocaleData.cldr b/test/jdk/sun/text/resources/LocaleData.cldr index 21f1d016cfc37..a6b62961a07e7 100644 --- a/test/jdk/sun/text/resources/LocaleData.cldr +++ b/test/jdk/sun/text/resources/LocaleData.cldr @@ -5240,9 +5240,9 @@ FormatData/de/TimePatterns/0=HH:mm:ss zzzz FormatData/fi/AmPmMarkers/0=ap. FormatData/fi/AmPmMarkers/1=ip. -# bug 6507067 +# bug 6507067 8317979 TimeZoneNames/zh_TW/Asia\/Taipei/1=\u53f0\u5317\u6a19\u6e96\u6642\u9593 -TimeZoneNames/zh_TW/Asia\/Taipei/2= +TimeZoneNames/zh_TW/Asia\/Taipei/2=CST # bug 6645271 FormatData/hr_HR/DatePatterns/2=d. MMM y. diff --git a/test/jdk/sun/text/resources/LocaleDataTest.java b/test/jdk/sun/text/resources/LocaleDataTest.java index 2d76ca9e2eacd..0d40ef9bde0de 100644 --- a/test/jdk/sun/text/resources/LocaleDataTest.java +++ b/test/jdk/sun/text/resources/LocaleDataTest.java @@ -41,7 +41,7 @@ * 8187946 8195478 8181157 8179071 8193552 8202026 8204269 8202537 8208746 * 8209775 8221432 8227127 8230284 8231273 8233579 8234288 8250665 8255086 * 8251317 8274658 8283277 8283805 8265315 8287868 8295564 8284840 8296715 - * 8301206 8303472 + * 8301206 8303472 8317979 * @summary Verify locale data * @modules java.base/sun.util.resources * @modules jdk.localedata