Skip to content

Commit 418bb42

Browse files
committed
8340073: Support "%z" time zone abbreviation format in TZ files
Reviewed-by: jlu, joehw, coffeys
1 parent b26645f commit 418bb42

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

make/jdk/src/classes/build/tools/cldrconverter/CLDRConverter.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,10 @@ private static Map<String, Object> extractZoneNames(Map<String, Object> map, Str
786786
String tzKey = Optional.ofNullable((String)handlerSupplMeta.get(tzid))
787787
.orElse(tzid);
788788
// Follow link, if needed
789-
var tzLink = tzdbLinks.get(tzKey);
789+
String tzLink = null;
790+
for (var k = tzKey; tzdbLinks.containsKey(k);) {
791+
k = tzLink = tzdbLinks.get(k);
792+
}
790793
if (tzLink == null && tzdbLinks.containsValue(tzKey)) {
791794
// reverse link search
792795
// this is needed as in tzdb, "America/Buenos_Aires" links to
@@ -1214,7 +1217,7 @@ private static void generateZoneName() throws Exception {
12141217
private static Set<String> getAvailableZoneIds() {
12151218
assert handlerMetaZones != null;
12161219
if (AVAILABLE_TZIDS == null) {
1217-
AVAILABLE_TZIDS = new HashSet<>(ZoneId.getAvailableZoneIds());
1220+
AVAILABLE_TZIDS = new HashSet<>(Arrays.asList(TimeZone.getAvailableIDs()));
12181221
AVAILABLE_TZIDS.addAll(handlerMetaZones.keySet());
12191222
AVAILABLE_TZIDS.remove(MetaZonesParseHandler.NO_METAZONE_KEY);
12201223
}
@@ -1490,13 +1493,14 @@ private static void fillTZDBShortNames(String tzid, String[] names) {
14901493
/*
14911494
* Convert TZDB offsets to JDK's offsets, eg, "-08" to "GMT-08:00".
14921495
* If it cannot recognize the pattern, return the argument as is.
1496+
* Returning null results in generating the GMT format at runtime.
14931497
*/
14941498
private static String convertGMTName(String f) {
14951499
try {
1496-
// Should pre-fill GMT format once COMPAT is gone.
1497-
// Till then, fall back to GMT format at runtime, after COMPAT short
1498-
// names are populated
1499-
ZoneOffset.of(f);
1500+
if (!f.equals("%z")) {
1501+
// Validate if the format is an offset
1502+
ZoneOffset.of(f);
1503+
}
15001504
return null;
15011505
} catch (DateTimeException dte) {
15021506
// textual representation. return as is

src/java.base/share/classes/sun/util/cldr/CLDRTimeZoneNameProviderImpl.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,13 @@ private boolean regionFormatFallback(String[] names, int index, Locale l) {
264264
}
265265

266266
private String toGMTFormat(String id, boolean daylight, Locale l) {
267-
var zr = ZoneInfoFile.getZoneInfo(id).toZoneId().getRules();
267+
LocaleResources lr = LocaleProviderAdapter.forType(Type.CLDR).getLocaleResources(l);
268+
ResourceBundle fd = lr.getJavaTimeFormatData();
269+
var zi = ZoneInfoFile.getZoneInfo(id);
270+
if (zi == null) {
271+
return fd.getString("timezone.gmtZeroFormat");
272+
}
273+
var zr = zi.toZoneId().getRules();
268274
var now = Instant.now();
269275
var saving = zr.getTransitions().reversed().stream()
270276
.dropWhile(zot -> zot.getInstant().isAfter(now))
@@ -276,8 +282,6 @@ private String toGMTFormat(String id, boolean daylight, Locale l) {
276282
.orElse(0);
277283
int offset = (zr.getStandardOffset(now).getTotalSeconds() +
278284
(daylight ? saving : 0)) / 60;
279-
LocaleResources lr = LocaleProviderAdapter.forType(Type.CLDR).getLocaleResources(l);
280-
ResourceBundle fd = lr.getJavaTimeFormatData();
281285

282286
if (offset == 0) {
283287
return fd.getString("timezone.gmtZeroFormat");

0 commit comments

Comments
 (0)