Skip to content

Commit

Permalink
temp fix
Browse files Browse the repository at this point in the history
  • Loading branch information
naotoj committed Jan 10, 2024
1 parent d37d403 commit 4036926
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 38 deletions.
60 changes: 56 additions & 4 deletions make/jdk/src/classes/build/tools/cldrconverter/CLDRConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,10 @@ private static Map<String, Object> extractZoneNames(Map<String, Object> map, Str
.orElse(tzid);
Object data = map.get(TIMEZONE_ID_PREFIX + tzKey);

//if (id.equals("en") && (tzid.contains("Gambier") || tzid.contains("YST9"))) {
//if (id.equals("en") && (tzid.contains("Moscow"))) {
//int ika =5;
//}
if (data instanceof String[] tznames) {
// Hack for UTC. UTC is an alias to Etc/UTC in CLDR
if (tzid.equals("Etc/UTC") && !map.containsKey(TIMEZONE_ID_PREFIX + "UTC")) {
Expand All @@ -777,20 +781,41 @@ private static Map<String, Object> extractZoneNames(Map<String, Object> map, Str
names.put("UTC", META_ETCUTC_ZONE_NAME);
} else {
// TZDB short names
tznames = Arrays.copyOf(tznames, tznames.length);
fillTZDBShortNames(tzid, tznames);
names.put(tzid, tznames);
}
} else {
String meta = handlerMetaZones.get(tzKey);
//if (id.equals("en") && (tzid.contains("Midway") || tzid.contains("Pago_Pago"))) {
//int ika =5;
//}
if (meta != null) {
String metaKey = METAZONE_ID_PREFIX + meta;
if (id.equals("en") && (meta.equals("Moscow"))) {
int ika =5;
}
data = map.get(metaKey);
if (data instanceof String[] tznames) {
// TZDB short names
tznames = Arrays.copyOf((String[])names.getOrDefault(metaKey, tznames), 6);
fillTZDBShortNames(tzid, tznames);
// if (tzKey.equals(tzid)) {
// Keep the metazone prefix here.
names.putIfAbsent(metaKey, tznames);
names.put(tzid, meta);
// } else {
// // deprecated tzid. Do not use metazone names as they may be different,
// // e.g. SystemV/YST9 vs. Pacific/Gambier
// names.put(tzid, tznames);
// }
}
} else if (id.equals("root")) {
// supply TZDB short names if available
if (tzdbShortNamesMap.containsKey(tzid)) {
var tznames = new String[6];
fillTZDBShortNames(tzid, tznames);
// Keep the metazone prefix here.
names.put(metaKey, data);
names.put(tzid, meta);
names.put(tzid, tznames);
}
}
}
Expand Down Expand Up @@ -1273,6 +1298,11 @@ private static Map<Locale, String> coverageLevelsMap() throws Exception {
*
* "America/Los_Angeles" -> "P%sT<NBSP>US"
*
* `tzdbShortNamesMap` can also retain `Link`s of time zones. if the value
* does not contain <NBSP>, then it is a link, e.g.
*
* "US/Hawaii" -> "Pacific/Honolulu"
*
* The other map, `tzdbSubstLetters` maps the Rule to its substitution letters.
* The key of the map is the Rule name, appended with "<NBSP>std" or "<NBSP>dst"
* depending on the savings, e.g.,
Expand All @@ -1289,7 +1319,8 @@ private static Map<Locale, String> coverageLevelsMap() throws Exception {
*/
private static void generateTZDBShortNamesMap() throws IOException {
Files.walk(Path.of(tzDataDir), 1, FileVisitOption.FOLLOW_LINKS)
.filter(p -> p.toFile().isFile() && !p.endsWith("jdk11_backward"))
// .filter(p -> p.toFile().isFile() && !p.endsWith("jdk11_backward"))
.filter(p -> p.toFile().isFile())
.forEach(p -> {
try {
String zone = null;
Expand Down Expand Up @@ -1337,6 +1368,9 @@ private static void generateTZDBShortNamesMap() throws IOException {
zone = zl[1];
rule = zl[3];
format = zl[4];
if (zone.contains("Moscow")) {
int baka = 4;
}
} else {
if (zone != null) {
if (line.startsWith("Rule") ||
Expand All @@ -1359,6 +1393,20 @@ private static void generateTZDBShortNamesMap() throws IOException {
tzdbSubstLetters.put(rl[1] + NBSP + (rl[8].equals("0") ? STD : DST),
rl[9].replace(NO_SUBST, ""));
}

if (line.contains("Zaporo")) {
int baka = 4;
}
// Link line
if (line.startsWith("Link")) {
var ll = line.split("[ \t]+", -1);
tzdbShortNamesMap.put(ll[2], ll[1]);
}
}

// Last entry
if (zone != null) {
tzdbShortNamesMap.put(zone, format + NBSP + rule);
}
} catch (IOException ioe) {
throw new UncheckedIOException(ioe);
Expand All @@ -1372,6 +1420,10 @@ private static void generateTZDBShortNamesMap() throws IOException {
private static void fillTZDBShortNames(String tzid, String[] names) {
var val = tzdbShortNamesMap.get(tzid);
if (val != null) {
while (!val.contains(NBSP)) {
// Link
val = tzdbShortNamesMap.get(val);
}
var format = val.split(NBSP)[0];
var rule = val.split(NBSP)[1];
IntStream.of(1, 3, 5).forEach(i -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4677,10 +4677,14 @@ public int parse(DateTimeParseContext context, CharSequence text, int position)
if (length >= position + 3 && context.charEquals(text.charAt(position + 2), 'C')) {
// There are localized zone texts that start with "UTC", e.g.
// "UTC\u221210:00" (MINUS SIGN instead of HYPHEN-MINUS) in French.
// Exclude those cases.
if (length == position + 3 ||
context.charEquals(text.charAt(position + 3), '+') ||
context.charEquals(text.charAt(position + 3), '-')) {
// Treat them as normal '-' with the offset parser (using text parser would
// be problematic due to std/dst distinction)
if (length > position + 3 && context.charEquals(text.charAt(position + 3), '\u2212')) {
var tmpText = "%s-%s".formatted(
text.subSequence(0, position + 3),
text.subSequence(position + 4, text.length()));
return parseOffsetBased(context, tmpText, position, position + 3, OffsetIdPrinterParser.INSTANCE_ID_ZERO);
} else {
return parseOffsetBased(context, text, position, position + 3, OffsetIdPrinterParser.INSTANCE_ID_ZERO);
}
} else {
Expand Down
8 changes: 6 additions & 2 deletions test/jdk/java/text/Format/DateFormat/DateFormatTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2024, 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 Down Expand Up @@ -130,7 +130,11 @@ public void TestWallyWedel()
String fmtDstOffset = null;
if (fmtOffset.startsWith("GMT"))
{
fmtDstOffset = fmtOffset.substring(3);
if (fmtOffset.length() > 3) {
fmtDstOffset = fmtOffset.substring(3);
} else {
fmtDstOffset = "+00:00";
}
}
/*
* Show our result.
Expand Down
20 changes: 1 addition & 19 deletions test/jdk/java/time/test/java/time/format/TestUTCParse.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,22 @@
/*
* @test
* @modules jdk.localedata
* @bug 8303440 8317979 8322647
* @bug 8303440 8317979 8322647 8174269
* @summary Test parsing "UTC-XX:XX" text works correctly
*/
package test.java.time.format;

import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.format.TextStyle;
import java.time.temporal.TemporalQueries;
import java.util.Locale;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;

public class TestUTCParse {

static {
// Assuming CLDR's SHORT name for "America/Manaus"
// produces "UTC\u221204:00"
System.setProperty("java.locale.providers", "CLDR");
}

@DataProvider
public Object[][] utcZoneIdStrings() {
return new Object[][] {
Expand All @@ -57,15 +48,6 @@ 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/Manaus"));
var formatted = fmt.format(zdt);
assertEquals(formatted, "UTC\u221204:00");
assertEquals(fmt.parse(formatted).query(TemporalQueries.zoneId()), zdt.getZone());
}

@Test(dataProvider = "utcZoneIdStrings")
public void testUTCOffsetRoundTrip(String zidString) {
var fmt = new DateTimeFormatterBuilder()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2024, 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 Down Expand Up @@ -52,6 +52,7 @@
/*
* @test
* @bug 8081022 8151876 8166875 8177819 8189784 8206980 8277049 8278434
* 8174269
* @key randomness
*/

Expand Down Expand Up @@ -94,6 +95,10 @@ public void test_printText() {
String shortDisplayName = tz.getDisplayName(isDST, TimeZone.SHORT, locale);
if ((longDisplayName.startsWith("GMT+") && shortDisplayName.startsWith("GMT+"))
|| (longDisplayName.startsWith("GMT-") && shortDisplayName.startsWith("GMT-"))) {
// exclude ROOT
if (locale.equals(Locale.ROOT)) {
continue;
}
printText(locale, zdt, TextStyle.FULL, tz, tz.getID());
printText(locale, zdt, TextStyle.SHORT, tz, tz.getID());
continue;
Expand Down
16 changes: 8 additions & 8 deletions test/jdk/sun/util/resources/cldr/TimeZoneNamesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

/*
* @test
* @bug 8181157 8202537 8234347 8236548 8261279 8322647
* @bug 8181157 8202537 8234347 8236548 8261279 8322647 8174269
* @modules jdk.localedata
* @summary Checks CLDR time zone names are generated correctly at
* either build or runtime
Expand Down Expand Up @@ -51,7 +51,7 @@ Object[][] sampleTZs() {
return new Object[][] {
// tzid, locale, style, expected

// This list is as of CLDR version 33, and should be examined
// This list is as of CLDR version 44, and should be examined
// on the CLDR data upgrade.

// no "metazone" zones
Expand Down Expand Up @@ -80,17 +80,17 @@ Object[][] sampleTZs() {
"heure : Punta Arenas",
"UTC\u221203:00"},
{"Asia/Famagusta", Locale.US, "Famagusta Standard Time",
"GMT+02:00",
"EET",
"Famagusta Daylight Time",
"GMT+03:00",
"EEST",
"Famagusta Time",
"GMT+02:00"},
"EET"},
{"Asia/Famagusta", Locale.FRANCE, "Famagouste (heure standard)",
"UTC+02:00",
"EET",
"Famagouste (heure d\u2019\u00e9t\u00e9)",
"UTC+03:00",
"EEST",
"heure : Famagouste",
"UTC+02:00"},
"EET"},
{"Europe/Astrakhan", Locale.US, "Astrakhan Standard Time",
"GMT+04:00",
"Astrakhan Daylight Time",
Expand Down

0 comments on commit 4036926

Please sign in to comment.