8340073: Support "%z" time zone abbreviation format in TZ files
Reviewed-by: jlu, joehw, coffeys
This commit is contained in:
parent
b26645f64b
commit
418bb42b95
@ -786,7 +786,10 @@ public class CLDRConverter {
|
||||
String tzKey = Optional.ofNullable((String)handlerSupplMeta.get(tzid))
|
||||
.orElse(tzid);
|
||||
// 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)) {
|
||||
// reverse link search
|
||||
// this is needed as in tzdb, "America/Buenos_Aires" links to
|
||||
@ -1214,7 +1217,7 @@ public class CLDRConverter {
|
||||
private static Set<String> getAvailableZoneIds() {
|
||||
assert handlerMetaZones != 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.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".
|
||||
* 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) {
|
||||
try {
|
||||
// Should pre-fill GMT format once COMPAT is gone.
|
||||
// Till then, fall back to GMT format at runtime, after COMPAT short
|
||||
// names are populated
|
||||
ZoneOffset.of(f);
|
||||
if (!f.equals("%z")) {
|
||||
// Validate if the format is an offset
|
||||
ZoneOffset.of(f);
|
||||
}
|
||||
return null;
|
||||
} catch (DateTimeException dte) {
|
||||
// textual representation. return as is
|
||||
|
@ -264,7 +264,13 @@ public class CLDRTimeZoneNameProviderImpl extends TimeZoneNameProviderImpl {
|
||||
}
|
||||
|
||||
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 saving = zr.getTransitions().reversed().stream()
|
||||
.dropWhile(zot -> zot.getInstant().isAfter(now))
|
||||
@ -276,8 +282,6 @@ public class CLDRTimeZoneNameProviderImpl extends TimeZoneNameProviderImpl {
|
||||
.orElse(0);
|
||||
int offset = (zr.getStandardOffset(now).getTotalSeconds() +
|
||||
(daylight ? saving : 0)) / 60;
|
||||
LocaleResources lr = LocaleProviderAdapter.forType(Type.CLDR).getLocaleResources(l);
|
||||
ResourceBundle fd = lr.getJavaTimeFormatData();
|
||||
|
||||
if (offset == 0) {
|
||||
return fd.getString("timezone.gmtZeroFormat");
|
||||
|
Loading…
Reference in New Issue
Block a user