Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
naotoj committed Sep 19, 2024
1 parent 90e92f9 commit 02f6864
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 287 deletions.
11 changes: 1 addition & 10 deletions src/java.base/share/classes/java/util/TimeZone.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -593,15 +593,6 @@ private ZoneId toZoneId0() {
// delegate to default TZ which is effectively immutable
return defaultZone.toZoneId();
}
// derive it ourselves
if (ZoneInfoFile.useOldMapping() && id.length() == 3) {
if ("EST".equals(id))
return ZoneId.of("America/New_York");
if ("MST".equals(id))
return ZoneId.of("America/Denver");
if ("HST".equals(id))
return ZoneId.of("America/Honolulu");
}
return ZoneId.of(id, ZoneId.SHORT_IDS);
}

Expand Down
76 changes: 14 additions & 62 deletions src/java.base/share/classes/sun/util/calendar/ZoneInfoFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,20 @@
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.SimpleTimeZone;
import java.util.concurrent.ConcurrentHashMap;
import java.util.zip.CRC32;

import jdk.internal.util.StaticProperty;
import sun.security.action.GetPropertyAction;

/**
* Loads TZDB time-zone rules for j.u.TimeZone
Expand All @@ -65,19 +64,14 @@ public final class ZoneInfoFile {
* @return a set of time zone IDs.
*/
public static String[] getZoneIds() {
int len = regions.length + oldMappings.length;
if (!USE_OLDMAPPING) {
len += 3; // EST/HST/MST not in tzdb.dat
}
var shortIDs = ZoneId.SHORT_IDS.keySet();
int len = regions.length + nonTZDBIDs.length + shortIDs.size();
String[] ids = Arrays.copyOf(regions, len);
int i = regions.length;
if (!USE_OLDMAPPING) {
ids[i++] = "EST";
ids[i++] = "HST";
ids[i++] = "MST";
}
for (int j = 0; j < oldMappings.length; j++) {
ids[i++] = oldMappings[j][0];
System.arraycopy(nonTZDBIDs, 0, ids, i, nonTZDBIDs.length);
i += nonTZDBIDs.length;
for (var id : shortIDs) {
ids[i++] = id;
}
return ids;
}
Expand Down Expand Up @@ -216,42 +210,10 @@ private ZoneInfoFile() {
private static String[] regions;
private static int[] indices;

// Flag for supporting JDK backward compatible IDs, such as "EST".
private static final boolean USE_OLDMAPPING;

private static final String[][] oldMappings = new String[][] {
{ "ACT", "Australia/Darwin" },
{ "AET", "Australia/Sydney" },
{ "AGT", "America/Argentina/Buenos_Aires" },
{ "ART", "Africa/Cairo" },
{ "AST", "America/Anchorage" },
{ "BET", "America/Sao_Paulo" },
{ "BST", "Asia/Dhaka" },
{ "CAT", "Africa/Harare" },
{ "CNT", "America/St_Johns" },
{ "CST", "America/Chicago" },
{ "CTT", "Asia/Shanghai" },
{ "EAT", "Africa/Addis_Ababa" },
{ "ECT", "Europe/Paris" },
{ "IET", "America/Indiana/Indianapolis" },
{ "IST", "Asia/Kolkata" },
{ "JST", "Asia/Tokyo" },
{ "MIT", "Pacific/Apia" },
{ "NET", "Asia/Yerevan" },
{ "NST", "Pacific/Auckland" },
{ "PLT", "Asia/Karachi" },
{ "PNT", "America/Phoenix" },
{ "PRT", "America/Puerto_Rico" },
{ "PST", "America/Los_Angeles" },
{ "SST", "Pacific/Guadalcanal" },
{ "VST", "Asia/Ho_Chi_Minh" },
};
// EST/HST/MST not in tzdb.dat
private static final String[] nonTZDBIDs = { "EST", "MST", "HST" };

static {
String oldmapping = GetPropertyAction
.privilegedGetProperty("sun.timezone.ids.oldmapping", "false")
.toLowerCase(Locale.ROOT);
USE_OLDMAPPING = (oldmapping.equals("yes") || oldmapping.equals("true"));
loadTZDB();
}

Expand All @@ -275,22 +237,12 @@ public Void run() {
}

private static void addOldMapping() {
for (String[] alias : oldMappings) {
aliases.put(alias[0], alias[1]);
for (var key : ZoneId.SHORT_IDS.keySet()) {
aliases.put(key, ZoneId.SHORT_IDS.get(key));
}
if (USE_OLDMAPPING) {
aliases.put("EST", "America/New_York");
aliases.put("MST", "America/Denver");
aliases.put("HST", "Pacific/Honolulu");
} else {
zones.put("EST", new ZoneInfo("EST", -18000000));
zones.put("MST", new ZoneInfo("MST", -25200000));
zones.put("HST", new ZoneInfo("HST", -36000000));
}
}

public static boolean useOldMapping() {
return USE_OLDMAPPING;
zones.put("EST", new ZoneInfo("EST", -18000000));
zones.put("MST", new ZoneInfo("MST", -25200000));
zones.put("HST", new ZoneInfo("HST", -36000000));
}

/**
Expand Down
121 changes: 0 additions & 121 deletions test/jdk/java/util/TimeZone/OldIDMappingTest.java

This file was deleted.

64 changes: 0 additions & 64 deletions test/jdk/java/util/TimeZone/TzIDOldMapping.java

This file was deleted.

30 changes: 0 additions & 30 deletions test/jdk/sun/util/calendar/zi/ZoneInfoOld.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,6 @@ public class ZoneInfoOld extends TimeZone {
private static final long ABBR_MASK = 0xf00L;
private static final int TRANSITION_NSHIFT = 12;

// Flag for supporting JDK backward compatible IDs, such as "EST".
static final boolean USE_OLDMAPPING;
static {
String oldmapping = System.getProperty("sun.timezone.ids.oldmapping", "false").toLowerCase(Locale.ROOT);
USE_OLDMAPPING = (oldmapping.equals("yes") || oldmapping.equals("true"));
}

// IDs having conflicting data between Olson and JDK 1.1
static final String[] conflictingIDs = {
"EST", "MST", "HST"
};

private static final CalendarSystem gcal = CalendarSystem.getGregorianCalendar();

/**
Expand Down Expand Up @@ -653,18 +641,6 @@ public static String[] getAvailableIDs(int rawOffset) {
public static TimeZone getTimeZone(String ID) {
String givenID = null;

/*
* If old JDK compatibility is specified, get the old alias
* name.
*/
if (USE_OLDMAPPING) {
String compatibleID = TzIDOldMapping.MAP.get(ID);
if (compatibleID != null) {
givenID = ID;
ID = compatibleID;
}
}

ZoneInfoOld zi = ZoneInfoFile.getZoneInfoOld(ID);
if (zi == null) {
// if we can't create an object for the ID, try aliases.
Expand Down Expand Up @@ -842,12 +818,6 @@ public synchronized static Map<String, String> getAliasTable() {
if (aliases == null) {
aliases = ZoneInfoFile.getZoneAliases();
if (aliases != null) {
if (!USE_OLDMAPPING) {
// Remove the conflicting IDs from the alias table.
for (String key : conflictingIDs) {
aliases.remove(key);
}
}
aliasTable = new SoftReference<Map<String, String>>(aliases);
}
}
Expand Down

0 comments on commit 02f6864

Please sign in to comment.