Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.
/ jdk23u Public archive

Commit f9c82e4

Browse files
johnyjose30coffeys
authored andcommitted
8340073: Support "%z" time zone abbreviation format in TZ files
Backport-of: 418bb42
1 parent 35290fa commit f9c82e4

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
}
@@ -1491,13 +1494,14 @@ private static void fillTZDBShortNames(String tzid, String[] names) {
14911494
/*
14921495
* Convert TZDB offsets to JDK's offsets, eg, "-08" to "GMT-08:00".
14931496
* If it cannot recognize the pattern, return the argument as is.
1497+
* Returning null results in generating the GMT format at runtime.
14941498
*/
14951499
private static String convertGMTName(String f) {
14961500
try {
1497-
// Should pre-fill GMT format once COMPAT is gone.
1498-
// Till then, fall back to GMT format at runtime, after COMPAT short
1499-
// names are populated
1500-
ZoneOffset.of(f);
1501+
if (!f.equals("%z")) {
1502+
// Validate if the format is an offset
1503+
ZoneOffset.of(f);
1504+
}
15011505
return null;
15021506
} catch (DateTimeException dte) {
15031507
// 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)