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

@ -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");