mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8235238: Parsing a time string ignores any custom TimeZoneNameProvider
Reviewed-by: joehw, rriggs
This commit is contained in:
parent
57ece4c21a
commit
20b1410d0c
6 changed files with 248 additions and 3 deletions
|
@ -4123,7 +4123,8 @@ public final class DateTimeFormatterBuilder {
|
|||
}
|
||||
Locale locale = context.getLocale();
|
||||
boolean isCaseSensitive = context.isCaseSensitive();
|
||||
Set<String> regionIds = ZoneRulesProvider.getAvailableZoneIds();
|
||||
Set<String> regionIds = new HashSet<>(ZoneRulesProvider.getAvailableZoneIds());
|
||||
Set<String> nonRegionIds = new HashSet<>(64);
|
||||
int regionIdsSize = regionIds.size();
|
||||
|
||||
Map<Locale, Entry<Integer, SoftReference<PrefixTree>>> cached =
|
||||
|
@ -4139,7 +4140,8 @@ public final class DateTimeFormatterBuilder {
|
|||
zoneStrings = TimeZoneNameUtility.getZoneStrings(locale);
|
||||
for (String[] names : zoneStrings) {
|
||||
String zid = names[0];
|
||||
if (!regionIds.contains(zid)) {
|
||||
if (!regionIds.remove(zid)) {
|
||||
nonRegionIds.add(zid);
|
||||
continue;
|
||||
}
|
||||
tree.add(zid, zid); // don't convert zid -> metazone
|
||||
|
@ -4149,12 +4151,27 @@ public final class DateTimeFormatterBuilder {
|
|||
tree.add(names[i], zid);
|
||||
}
|
||||
}
|
||||
|
||||
// add names for provider's custom ids
|
||||
final PrefixTree t = tree;
|
||||
regionIds.stream()
|
||||
.filter(zid -> !zid.startsWith("Etc") && !zid.startsWith("GMT"))
|
||||
.forEach(cid -> {
|
||||
String[] cidNames = TimeZoneNameUtility.retrieveDisplayNames(cid, locale);
|
||||
int i = textStyle == TextStyle.FULL ? 1 : 2;
|
||||
for (; i < cidNames.length; i += 2) {
|
||||
if (cidNames[i] != null && !cidNames[i].isEmpty()) {
|
||||
t.add(cidNames[i], cid);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// if we have a set of preferred zones, need a copy and
|
||||
// add the preferred zones again to overwrite
|
||||
if (preferredZones != null) {
|
||||
for (String[] names : zoneStrings) {
|
||||
String zid = names[0];
|
||||
if (!preferredZones.contains(zid) || !regionIds.contains(zid)) {
|
||||
if (!preferredZones.contains(zid) || nonRegionIds.contains(zid)) {
|
||||
continue;
|
||||
}
|
||||
int i = textStyle == TextStyle.FULL ? 1 : 2;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue