Skip to content

Commit

Permalink
substitute letters
Browse files Browse the repository at this point in the history
  • Loading branch information
naotoj committed Oct 16, 2023
1 parent 1f929d1 commit 0737356
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 54 deletions.
89 changes: 51 additions & 38 deletions make/jdk/src/classes/build/tools/cldrconverter/CLDRConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -125,7 +126,8 @@ public class CLDRConverter {
static Map<String, String> dayPeriodRules;

// TZDB Short Names Map
private static Map<String, String> tzdbShortNamesMap;
private static final Map<String, String> tzdbShortNamesMap = HashMap.newHashMap(512);
private static final Map<String, String> tzdbSubstLetters = HashMap.newHashMap(512);

static enum DraftType {
UNCONFIRMED,
Expand Down Expand Up @@ -289,7 +291,7 @@ public static void main(String[] args) throws Exception {
dayPeriodRules = generateRules(handlerDayPeriodRule);

// TZDB short names map
tzdbShortNamesMap = generateTZDBShortNamesMap();
generateTZDBShortNamesMap();

List<Bundle> bundles = readBundleList();
convertBundles(bundles);
Expand Down Expand Up @@ -1257,60 +1259,72 @@ private static Map<Locale, String> coverageLevelsMap() throws Exception {
return covMap;
}

private static Map<String, String> generateTZDBShortNamesMap() throws IOException {
final Map<String, String> 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);
}
});
}
}

// 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();
};
Expand All @@ -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);

Expand Down
10 changes: 5 additions & 5 deletions test/jdk/java/time/test/java/time/format/TestUTCParse.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
}

Expand All @@ -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());
}

Expand Down
16 changes: 8 additions & 8 deletions test/jdk/java/util/TimeZone/CLDRDisplayNamesTest.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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",
},
Expand Down
4 changes: 2 additions & 2 deletions test/jdk/sun/text/resources/LocaleData.cldr
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test/jdk/sun/text/resources/LocaleDataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0737356

Please sign in to comment.