8340073: Support "%z" time zone abbreviation format in TZ files

Reviewed-by: jlu, joehw, coffeys
This commit is contained in:
Naoto Sato 2024-09-16 20:03:00 +00:00
parent b26645f64b
commit 418bb42b95
2 changed files with 17 additions and 9 deletions

View File

@ -786,7 +786,10 @@ public class CLDRConverter {
String tzKey = Optional.ofNullable((String)handlerSupplMeta.get(tzid)) String tzKey = Optional.ofNullable((String)handlerSupplMeta.get(tzid))
.orElse(tzid); .orElse(tzid);
// Follow link, if needed // Follow link, if needed
var tzLink = tzdbLinks.get(tzKey); String tzLink = null;
for (var k = tzKey; tzdbLinks.containsKey(k);) {
k = tzLink = tzdbLinks.get(k);
}
if (tzLink == null && tzdbLinks.containsValue(tzKey)) { if (tzLink == null && tzdbLinks.containsValue(tzKey)) {
// reverse link search // reverse link search
// this is needed as in tzdb, "America/Buenos_Aires" links to // this is needed as in tzdb, "America/Buenos_Aires" links to
@ -1214,7 +1217,7 @@ public class CLDRConverter {
private static Set<String> getAvailableZoneIds() { private static Set<String> getAvailableZoneIds() {
assert handlerMetaZones != null; assert handlerMetaZones != null;
if (AVAILABLE_TZIDS == null) { if (AVAILABLE_TZIDS == null) {
AVAILABLE_TZIDS = new HashSet<>(ZoneId.getAvailableZoneIds()); AVAILABLE_TZIDS = new HashSet<>(Arrays.asList(TimeZone.getAvailableIDs()));
AVAILABLE_TZIDS.addAll(handlerMetaZones.keySet()); AVAILABLE_TZIDS.addAll(handlerMetaZones.keySet());
AVAILABLE_TZIDS.remove(MetaZonesParseHandler.NO_METAZONE_KEY); AVAILABLE_TZIDS.remove(MetaZonesParseHandler.NO_METAZONE_KEY);
} }
@ -1490,13 +1493,14 @@ public class CLDRConverter {
/* /*
* Convert TZDB offsets to JDK's offsets, eg, "-08" to "GMT-08:00". * Convert TZDB offsets to JDK's offsets, eg, "-08" to "GMT-08:00".
* If it cannot recognize the pattern, return the argument as is. * If it cannot recognize the pattern, return the argument as is.
* Returning null results in generating the GMT format at runtime.
*/ */
private static String convertGMTName(String f) { private static String convertGMTName(String f) {
try { try {
// Should pre-fill GMT format once COMPAT is gone. if (!f.equals("%z")) {
// Till then, fall back to GMT format at runtime, after COMPAT short // Validate if the format is an offset
// names are populated
ZoneOffset.of(f); ZoneOffset.of(f);
}
return null; return null;
} catch (DateTimeException dte) { } catch (DateTimeException dte) {
// textual representation. return as is // textual representation. return as is

View File

@ -264,7 +264,13 @@ public class CLDRTimeZoneNameProviderImpl extends TimeZoneNameProviderImpl {
} }
private String toGMTFormat(String id, boolean daylight, Locale l) { private String toGMTFormat(String id, boolean daylight, Locale l) {
var zr = ZoneInfoFile.getZoneInfo(id).toZoneId().getRules(); LocaleResources lr = LocaleProviderAdapter.forType(Type.CLDR).getLocaleResources(l);
ResourceBundle fd = lr.getJavaTimeFormatData();
var zi = ZoneInfoFile.getZoneInfo(id);
if (zi == null) {
return fd.getString("timezone.gmtZeroFormat");
}
var zr = zi.toZoneId().getRules();
var now = Instant.now(); var now = Instant.now();
var saving = zr.getTransitions().reversed().stream() var saving = zr.getTransitions().reversed().stream()
.dropWhile(zot -> zot.getInstant().isAfter(now)) .dropWhile(zot -> zot.getInstant().isAfter(now))
@ -276,8 +282,6 @@ public class CLDRTimeZoneNameProviderImpl extends TimeZoneNameProviderImpl {
.orElse(0); .orElse(0);
int offset = (zr.getStandardOffset(now).getTotalSeconds() + int offset = (zr.getStandardOffset(now).getTotalSeconds() +
(daylight ? saving : 0)) / 60; (daylight ? saving : 0)) / 60;
LocaleResources lr = LocaleProviderAdapter.forType(Type.CLDR).getLocaleResources(l);
ResourceBundle fd = lr.getJavaTimeFormatData();
if (offset == 0) { if (offset == 0) {
return fd.getString("timezone.gmtZeroFormat"); return fd.getString("timezone.gmtZeroFormat");