diff --git a/test/jdk/java/util/TimeZone/AssureTzdataVersion.java b/test/jdk/java/util/TimeZone/AssureTzdataVersion.java new file mode 100644 index 00000000000..86ba720bdc8 --- /dev/null +++ b/test/jdk/java/util/TimeZone/AssureTzdataVersion.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2015, 2022, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8060126 + * @summary Make sure that the tzdata version matches between the run-time and tests. + */ +import java.time.zone.ZoneRules; +import java.time.zone.ZoneRulesProvider; +import java.util.NavigableMap; + +public class AssureTzdataVersion { + public static void main(String... args) throws Exception { + // get the tzdata version for the run-time + NavigableMap map; + map = ZoneRulesProvider.getVersions("America/Los_Angeles"); + if (map.isEmpty()) { + throw new RuntimeException("Unknown runtime tzdata version"); + } + String runtime = map.lastEntry().getKey(); + + // get the tzdata version for regression tests + String testdata = null; + try (TextFileReader textreader = new TextFileReader("VERSION")) { + testdata = textreader.getLine().substring("tzdata".length()); + } + if (!testdata.equals(runtime)) { + throw new RuntimeException("tzdata versions don't match: run-time=" + runtime + + ", tests=" + testdata); + } + } +} diff --git a/test/jdk/java/util/TimeZone/Bug6329116.java b/test/jdk/java/util/TimeZone/Bug6329116.java new file mode 100644 index 00000000000..32105881194 --- /dev/null +++ b/test/jdk/java/util/TimeZone/Bug6329116.java @@ -0,0 +1,246 @@ +/* + * Copyright (c) 2005, 2022, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 6329116 6756569 6757131 6758988 6764308 6796489 6834474 6609737 6507067 + * 7039469 7090843 7103108 7103405 7158483 8008577 8059206 8064560 8072042 + * 8077685 8151876 8166875 8169191 8170316 8176044 + * @summary Make sure that timezone short display names are idenical to Olson's data. + * @library /java/text/testlib + * @build Bug6329116 TextFileReader + * @run main/othervm -Djava.locale.providers=COMPAT,SPI Bug6329116 + */ + +import java.io.*; +import java.text.*; +import java.util.*; + +public class Bug6329116 extends IntlTest { + + static Locale[] locales = Locale.getAvailableLocales(); + static String[] timezones = TimeZone.getAvailableIDs(); + + public static void main(String[] args) throws IOException { + if (bug6329116()) { + throw new RuntimeException("At least one timezone display name is incorrect."); + } + } + + static boolean bug6329116() throws IOException { + boolean err = false; + + HashMap aliasTable = new HashMap<>(); + HashSet timezoneTable = new HashSet<>(); + for (String t : timezones) { + timezoneTable.add(t); + } + + String line, key, value; + StringTokenizer st; + + try (TextFileReader in = new TextFileReader("aliases.txt")) { + while ((line = in.readLine()) != null) { + st = new StringTokenizer(line); + st.nextToken(); + key = st.nextToken(); + value = st.nextToken(); + + if (!value.equals("ROC")) { + if (aliasTable.containsKey(key)) { + aliasTable.put(key, aliasTable.get(key) + " " + value); + } else { + aliasTable.put(key, value); + } + } + } + } + + try (TextFileReader in = new TextFileReader("displaynames.txt")) { + String timezoneID, expected, expected_DST, got; + String[] aliases, tzs; + TimeZone tz; + while ((line = in.readLine()) != null) { + st = new StringTokenizer(line); + timezoneID = st.nextToken(); + expected = st.nextToken(); + if (st.hasMoreTokens()) { + expected_DST = st.nextToken(); + } else { + expected_DST = null; + } + + if (aliasTable.containsKey(timezoneID)) { + aliases = aliasTable.get(timezoneID).split(" "); + tzs = new String[1 + aliases.length]; + System.arraycopy(aliases, 0, tzs, 1, aliases.length); + aliasTable.remove(timezoneID); + } else { + tzs = new String[1]; + } + tzs[0] = timezoneID; + + for (int j = 0; j < tzs.length; j++) { + tz = TimeZone.getTimeZone(tzs[j]); + + if (!tzs[j].equals(tz.getID())) { + System.err.println(tzs[j] + " may not be a valid Timezone ID and \"" + tz.getID() + "\" was returned. Please check it."); + err = true; + } + + timezoneTable.remove(tzs[j]); + + for (int i = 0; i < locales.length; i++) { + got = tz.getDisplayName(false, TimeZone.SHORT, locales[i]); + if (!expected.equals(got) && + !expected.startsWith(got + "/") && + !expected.endsWith("/" + got)) { + if (useLocalzedShortDisplayName(tz, locales[i], got, false)) { +/* + System.out.println(tzs[j] + + ((j > 0) ? "(Alias of \"" + tzs[0] + "\")" : "") + + " seems to use a localized short display name" + + ": original: " + expected + + ": got: " + got + " for non-DST in " + + locales[i] + " locale."); +*/ + } else { + System.err.println(tzs[j] + + ((j > 0) ? "(Alias of \"" + tzs[0] + "\")" : "") + + ": expected: " + expected + + ": got: " + got + " for non-DST in " + + locales[i] + " locale."); + err = true; + } + } + + got = tz.getDisplayName(true, TimeZone.SHORT, locales[i]); + if (expected_DST != null) { + if (!expected_DST.equals(got) && + !expected_DST.startsWith(got + "/") && + !expected_DST.endsWith("/" + got)) { + if (tzs[j].equals("Europe/London") && + locales[i].equals(new Locale("en", "IE"))) { + continue; + } else if (useLocalzedShortDisplayName(tz, locales[i], got, true)) { +/* + System.out.println(tzs[j] + + ((j > 0) ? "(Alias of \"" + tzs[0] + "\")" : "") + + " seems to use a localized short display name" + + ": original: " + expected_DST + + ": got: " + got + " for DST in " + + locales[i] + " locale."); +*/ + continue; + } + System.err.println(tzs[j] + + ((j > 0) ? "(Alias of \"" + tzs[0] + "\")" : "") + + ": expected: " + expected_DST + + ": got: " + got + " for DST in " + + locales[i] + " locale."); + err = true; + } + } else { + // Some timezones don't have DST display names in Olson's data, + // and we created them ourselves based on non-DST display names + // to prepare potential use in the future. + // Because there's no expected name, we don't judge if these + // DST display names are correct but just compare them with + // non-DST diplay names for checking with our eyes . + if (!expected.equals(got) && + !expected.startsWith(got + "/") && + !expected.endsWith("/" + got)) { +/* + System.out.println("## " + tzs[j] + + ((j > 0) ? "(Alias of \"" + tzs[0] + "\")" : "") + + ": expected: " + expected + + ": got: " + got + " for DST in " + + locales[i] + " locale."); +*/ + } + } + } + } + } + } + + if (!timezoneTable.isEmpty()) { + System.out.println("# Timezone(s) valid in JRE but untested in this test program:"); + Iterator it = timezoneTable.iterator(); + while (it.hasNext()) { + System.out.println(it.next()); + } + System.out.println(); + } + + if (!aliasTable.isEmpty()) { + System.out.println("# Timezone(s) exists in Olson's data as Link but unused in JRE:"); + for (Map.Entry entry : aliasTable.entrySet()) { + System.out.println(entry); + } + } + + return err; + } + + static boolean useLocalzedShortDisplayName(TimeZone tz, + Locale locale, + String got, + boolean inDST) { + if (locale.getLanguage().equals("de")) { + String name = tz.getDisplayName(inDST, TimeZone.LONG, locale); + if (inDST) { + if (("Mitteleurop\u00e4ische Sommerzeit".equals(name) && "MESZ".equals(got)) || + ("Osteurop\u00e4ische Sommerzeit".equals(name) && "OESZ".equals(got)) || + ("Westeurop\u00e4ische Sommerzeit".equals(name) && "WESZ".equals(got))) { + return true; + } + } else { + if (("Mitteleurop\u00e4ische Zeit".equals(name) && "MEZ".equals(got)) || + ("Osteurop\u00e4ische Zeit".equals(name) && "OEZ".equals(got)) || + ("Westeurop\u00e4ische Zeit".equals(name) && "WEZ".equals(got))) { + return true; + } + } + } else if (locale.getLanguage().equals("zh") && + (locale.getCountry().equals("TW") || locale.getCountry().equals("HK"))) { + String name = tz.getDisplayName(inDST, TimeZone.LONG, locale); + if (inDST) { + if (("\u53f0\u7063\u590f\u4ee4\u6642\u9593".equals(name) && "TDT".equals(got))) { + return true; + } + } else { + if (("\u53f0\u7063\u6a19\u6e96\u6642\u9593".equals(name) && "TST".equals(got))) { + return true; + } + } + } + // If we get a TimeZone with GMT+hh:mm format, we can ignore the offset value + if (tz.getDisplayName(Locale.ENGLISH).startsWith("GMT+") || tz.getDisplayName(Locale.ENGLISH).startsWith("GMT-")) { + return tz.getDisplayName().substring(0, 3).equals(got.substring(0, 3)); + } + + return false; + } + +} diff --git a/test/jdk/java/util/TimeZone/TextFileReader.java b/test/jdk/java/util/TimeZone/TextFileReader.java new file mode 100644 index 00000000000..54fde1c2d1d --- /dev/null +++ b/test/jdk/java/util/TimeZone/TextFileReader.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2008, 2022, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.io.*; + +// This class is public so that tools can invoke. +public class TextFileReader implements AutoCloseable { + private BufferedReader reader; + private int lineNo; + + public TextFileReader(String filename) throws IOException { + this(new File(new File(System.getProperty("test.src", "."), + "TimeZoneData"), + filename)); + } + + public TextFileReader(File file) throws IOException { + InputStream is = new FileInputStream(file); + reader = new BufferedReader(new InputStreamReader(is, "utf-8")); + } + + public String readLine() throws IOException { + return getLine(); + } + + public String getLine() throws IOException { + checkReader(); + + String line; + while ((line = reader.readLine()) != null) { + lineNo++; + line = line.trim(); + // Skip blank and comment lines. + if (line.length() == 0) { + continue; + } + int x = line.indexOf('#'); + if (x == 0) { + continue; + } + if (x > 0) { + line = line.substring(0, x).trim(); + } + break; + } + return line; + } + + public String getRawLine() throws IOException { + checkReader(); + + String line = reader.readLine(); + if (line != null) { + lineNo++; + } + return line; + } + + private void checkReader() throws IOException { + if (reader == null) { + throw new IOException("This TextFileReader has been closed."); + } + } + + @Override + public void close() throws IOException { + reader.close(); + reader = null; + } + + int getLineNo() { + return lineNo; + } +} diff --git a/test/jdk/java/util/TimeZone/TimeZoneData/VERSION b/test/jdk/java/util/TimeZone/TimeZoneData/VERSION new file mode 100644 index 00000000000..c7cf9054300 --- /dev/null +++ b/test/jdk/java/util/TimeZone/TimeZoneData/VERSION @@ -0,0 +1 @@ +tzdata2022a diff --git a/test/jdk/java/util/TimeZone/TimeZoneData/aliases.txt b/test/jdk/java/util/TimeZone/TimeZoneData/aliases.txt new file mode 100644 index 00000000000..618a0f0cf7f --- /dev/null +++ b/test/jdk/java/util/TimeZone/TimeZoneData/aliases.txt @@ -0,0 +1,213 @@ +Link Africa/Abidjan Africa/Accra # Ghana +Link Africa/Abidjan Africa/Bamako # Mali +Link Africa/Abidjan Africa/Banjul # The Gambia +Link Africa/Abidjan Africa/Conakry # Guinea +Link Africa/Abidjan Africa/Dakar # Senegal +Link Africa/Abidjan Africa/Freetown # Sierra Leone +Link Africa/Abidjan Africa/Lome # Togo +Link Africa/Abidjan Africa/Nouakchott # Mauritania +Link Africa/Abidjan Africa/Ouagadougou # Burkina Faso +Link Africa/Abidjan Atlantic/St_Helena # St Helena +Link Africa/Nairobi Africa/Addis_Ababa # Ethiopia +Link Africa/Nairobi Africa/Asmara # Eritrea +Link Africa/Nairobi Africa/Dar_es_Salaam # Tanzania +Link Africa/Nairobi Africa/Djibouti +Link Africa/Nairobi Africa/Kampala # Uganda +Link Africa/Nairobi Africa/Mogadishu # Somalia +Link Africa/Nairobi Indian/Antananarivo # Madagascar +Link Africa/Nairobi Indian/Comoro +Link Africa/Nairobi Indian/Mayotte +Link Africa/Maputo Africa/Blantyre # Malawi +Link Africa/Maputo Africa/Bujumbura # Burundi +Link Africa/Maputo Africa/Gaborone # Botswana +Link Africa/Maputo Africa/Harare # Zimbabwe +Link Africa/Maputo Africa/Kigali # Rwanda +Link Africa/Maputo Africa/Lubumbashi # E Dem. Rep. of Congo +Link Africa/Maputo Africa/Lusaka # Zambia +Link Africa/Lagos Africa/Bangui # Central African Republic +Link Africa/Lagos Africa/Brazzaville # Rep. of the Congo +Link Africa/Lagos Africa/Douala # Cameroon +Link Africa/Lagos Africa/Kinshasa # Dem. Rep. of the Congo (west) +Link Africa/Lagos Africa/Libreville # Gabon +Link Africa/Lagos Africa/Luanda # Angola +Link Africa/Lagos Africa/Malabo # Equatorial Guinea +Link Africa/Lagos Africa/Niamey # Niger +Link Africa/Lagos Africa/Porto-Novo # Benin +Link Africa/Johannesburg Africa/Maseru # Lesotho +Link Africa/Johannesburg Africa/Mbabane # Eswatini +Link Asia/Nicosia Europe/Nicosia +Link Asia/Qatar Asia/Bahrain +Link Asia/Riyadh Antarctica/Syowa +Link Asia/Riyadh Asia/Aden # Yemen +Link Asia/Riyadh Asia/Kuwait +Link Asia/Bangkok Asia/Phnom_Penh # Cambodia +Link Asia/Bangkok Asia/Vientiane # Laos +Link Asia/Dubai Asia/Muscat # Oman +Link Pacific/Guam Pacific/Saipan # N Mariana Is +Link Pacific/Auckland Antarctica/McMurdo +Link Pacific/Port_Moresby Antarctica/DumontDUrville +Link Pacific/Pago_Pago Pacific/Midway # in US minor outlying islands +Link Europe/London Europe/Jersey +Link Europe/London Europe/Guernsey +Link Europe/London Europe/Isle_of_Man +Link Europe/Helsinki Europe/Mariehamn +Link Europe/Zurich Europe/Busingen +Link Europe/Rome Europe/Vatican +Link Europe/Rome Europe/San_Marino +Link Europe/Zurich Europe/Vaduz +Link Europe/Oslo Arctic/Longyearbyen +Link Europe/Belgrade Europe/Ljubljana # Slovenia +Link Europe/Belgrade Europe/Podgorica # Montenegro +Link Europe/Belgrade Europe/Sarajevo # Bosnia and Herzegovina +Link Europe/Belgrade Europe/Skopje # North Macedonia +Link Europe/Belgrade Europe/Zagreb # Croatia +Link Europe/Prague Europe/Bratislava +Link Europe/Istanbul Asia/Istanbul # Istanbul is in both continents. +Link America/Phoenix America/Creston +Link America/Toronto America/Nassau +Link America/Panama America/Atikokan +Link America/Panama America/Cayman +Link America/Puerto_Rico America/Anguilla +Link America/Puerto_Rico America/Antigua +Link America/Puerto_Rico America/Aruba +Link America/Puerto_Rico America/Curacao +Link America/Puerto_Rico America/Blanc-Sablon # Quebec (Lower North Shore) +Link America/Puerto_Rico America/Dominica +Link America/Puerto_Rico America/Grenada +Link America/Puerto_Rico America/Guadeloupe +Link America/Puerto_Rico America/Kralendijk # Caribbean Netherlands +Link America/Puerto_Rico America/Lower_Princes # Sint Maarten +Link America/Puerto_Rico America/Marigot # St Martin (French part) +Link America/Puerto_Rico America/Montserrat +Link America/Puerto_Rico America/Port_of_Spain # Trinidad & Tobago +Link America/Puerto_Rico America/St_Barthelemy # St Barthélemy +Link America/Puerto_Rico America/St_Kitts # St Kitts & Nevis +Link America/Puerto_Rico America/St_Lucia +Link America/Puerto_Rico America/St_Thomas # Virgin Islands (US) +Link America/Puerto_Rico America/St_Vincent +Link America/Puerto_Rico America/Tortola # Virgin Islands (UK) +Link Asia/Riyadh87 Mideast/Riyadh87 +Link Asia/Riyadh88 Mideast/Riyadh88 +Link Asia/Riyadh89 Mideast/Riyadh89 +Link Africa/Nairobi Africa/Asmera +Link Africa/Abidjan Africa/Timbuktu +Link America/Argentina/Catamarca America/Argentina/ComodRivadavia +Link America/Adak America/Atka +Link America/Argentina/Buenos_Aires America/Buenos_Aires +Link America/Argentina/Catamarca America/Catamarca +Link America/Panama America/Coral_Harbour +Link America/Argentina/Cordoba America/Cordoba +Link America/Tijuana America/Ensenada +Link America/Indiana/Indianapolis America/Fort_Wayne +Link America/Nuuk America/Godthab +Link America/Indiana/Indianapolis America/Indianapolis +Link America/Argentina/Jujuy America/Jujuy +Link America/Indiana/Knox America/Knox_IN +Link America/Kentucky/Louisville America/Louisville +Link America/Argentina/Mendoza America/Mendoza +Link America/Toronto America/Montreal +Link America/Rio_Branco America/Porto_Acre +Link America/Argentina/Cordoba America/Rosario +Link America/Tijuana America/Santa_Isabel +Link America/Denver America/Shiprock +Link America/Puerto_Rico America/Virgin +Link Pacific/Auckland Antarctica/South_Pole +Link Asia/Ashgabat Asia/Ashkhabad +Link Asia/Kolkata Asia/Calcutta +Link Asia/Shanghai Asia/Chongqing +Link Asia/Shanghai Asia/Chungking +Link Asia/Dhaka Asia/Dacca +Link Asia/Shanghai Asia/Harbin +Link Asia/Urumqi Asia/Kashgar +Link Asia/Kathmandu Asia/Katmandu +Link Asia/Macau Asia/Macao +Link Asia/Yangon Asia/Rangoon +Link Asia/Ho_Chi_Minh Asia/Saigon +Link Asia/Jerusalem Asia/Tel_Aviv +Link Asia/Thimphu Asia/Thimbu +Link Asia/Makassar Asia/Ujung_Pandang +Link Asia/Ulaanbaatar Asia/Ulan_Bator +Link Atlantic/Faroe Atlantic/Faeroe +Link Europe/Oslo Atlantic/Jan_Mayen +Link Australia/Sydney Australia/ACT +Link Australia/Sydney Australia/Canberra +Link Australia/Hobart Australia/Currie +Link Australia/Lord_Howe Australia/LHI +Link Australia/Sydney Australia/NSW +Link Australia/Darwin Australia/North +Link Australia/Brisbane Australia/Queensland +Link Australia/Adelaide Australia/South +Link Australia/Hobart Australia/Tasmania +Link Australia/Melbourne Australia/Victoria +Link Australia/Perth Australia/West +Link Australia/Broken_Hill Australia/Yancowinna +Link America/Rio_Branco Brazil/Acre +Link America/Noronha Brazil/DeNoronha +Link America/Sao_Paulo Brazil/East +Link America/Manaus Brazil/West +Link America/Halifax Canada/Atlantic +Link America/Winnipeg Canada/Central +Link America/Toronto Canada/Eastern +Link America/Edmonton Canada/Mountain +Link America/St_Johns Canada/Newfoundland +Link America/Vancouver Canada/Pacific +Link America/Regina Canada/Saskatchewan +Link America/Whitehorse Canada/Yukon +Link America/Santiago Chile/Continental +Link Pacific/Easter Chile/EasterIsland +Link America/Havana Cuba +Link Africa/Cairo Egypt +Link Europe/Dublin Eire +Link Etc/UTC Etc/UCT +Link Europe/London Europe/Belfast +Link Europe/Chisinau Europe/Tiraspol +Link Europe/London GB +Link Europe/London GB-Eire +Link Etc/GMT GMT+0 +Link Etc/GMT GMT-0 +Link Etc/GMT GMT0 +Link Etc/GMT Greenwich +Link Asia/Hong_Kong Hongkong +Link Atlantic/Reykjavik Iceland +Link Asia/Tehran Iran +Link Asia/Jerusalem Israel +Link America/Jamaica Jamaica +Link Asia/Tokyo Japan +Link Pacific/Kwajalein Kwajalein +Link Africa/Tripoli Libya +Link America/Tijuana Mexico/BajaNorte +Link America/Mazatlan Mexico/BajaSur +Link America/Mexico_City Mexico/General +Link Pacific/Auckland NZ +Link Pacific/Chatham NZ-CHAT +Link America/Denver Navajo +Link Asia/Shanghai PRC +Link Pacific/Kanton Pacific/Enderbury +Link Pacific/Honolulu Pacific/Johnston +Link Pacific/Pohnpei Pacific/Ponape +Link Pacific/Pago_Pago Pacific/Samoa +Link Pacific/Chuuk Pacific/Truk +Link Pacific/Chuuk Pacific/Yap +Link Europe/Warsaw Poland +Link Europe/Lisbon Portugal +Link Asia/Taipei ROC +Link Asia/Seoul ROK +Link Asia/Singapore Singapore +Link Europe/Istanbul Turkey +Link Etc/UTC UCT +Link America/Anchorage US/Alaska +Link America/Adak US/Aleutian +Link America/Phoenix US/Arizona +Link America/Chicago US/Central +Link America/Indiana/Indianapolis US/East-Indiana +Link America/New_York US/Eastern +Link Pacific/Honolulu US/Hawaii +Link America/Indiana/Knox US/Indiana-Starke +Link America/Detroit US/Michigan +Link America/Denver US/Mountain +Link America/Los_Angeles US/Pacific +Link Pacific/Pago_Pago US/Samoa +Link Etc/UTC UTC +Link Etc/UTC Universal +Link Europe/Moscow W-SU +Link Etc/UTC Zulu diff --git a/test/jdk/java/util/TimeZone/TimeZoneData/displaynames.txt b/test/jdk/java/util/TimeZone/TimeZoneData/displaynames.txt new file mode 100644 index 00000000000..e4f5535b757 --- /dev/null +++ b/test/jdk/java/util/TimeZone/TimeZoneData/displaynames.txt @@ -0,0 +1,189 @@ +Africa/Abidjan GMT +Africa/Algiers CET +Africa/Bissau GMT +Africa/Cairo EET EEST +Africa/Ceuta CET CEST +Africa/Johannesburg SAST +Africa/Juba CAT +Africa/Khartoum CAT +Africa/Lagos WAT +Africa/Maputo CAT +Africa/Monrovia GMT +Africa/Nairobi EAT +Africa/Ndjamena WAT +Africa/Sao_Tome GMT +Africa/Tripoli EET +Africa/Tunis CET CEST +Africa/Windhoek CAT WAT +America/Adak HST HDT +America/Anchorage AKST AKDT +America/Bahia_Banderas CST CDT +America/Barbados AST ADT +America/Belize CST CDT +America/Boise MST MDT +America/Cambridge_Bay MST MDT +America/Cancun EST +America/Chicago CST CDT +America/Chihuahua MST MDT +America/Costa_Rica CST CDT +America/Danmarkshavn GMT +America/Dawson MST +America/Dawson_Creek MST +America/Denver MST MDT +America/Detroit EST EDT +America/Edmonton MST MDT +America/El_Salvador CST CDT +America/Fort_Nelson MST +America/Glace_Bay AST ADT +America/Goose_Bay AST ADT +America/Grand_Turk EST EDT +America/Guatemala CST CDT +America/Halifax AST ADT +America/Havana CST CDT +America/Hermosillo MST +America/Indiana/Indianapolis EST EDT +America/Indiana/Knox CST CDT +America/Indiana/Marengo EST EDT +America/Indiana/Petersburg EST EDT +America/Indiana/Tell_City CST CDT +America/Indiana/Vevay EST EDT +America/Indiana/Vincennes EST EDT +America/Indiana/Winamac EST EDT +America/Inuvik MST MDT +America/Iqaluit EST EDT +America/Jamaica EST +America/Juneau AKST AKDT +America/Kentucky/Louisville EST EDT +America/Kentucky/Monticello EST EDT +America/Los_Angeles PST PDT +America/Managua CST CDT +America/Martinique AST +America/Matamoros CST CDT +America/Mazatlan MST MDT +America/Menominee CST CDT +America/Merida CST CDT +America/Metlakatla AKST AKDT +America/Mexico_City CST CDT +America/Moncton AST ADT +America/Monterrey CST CDT +America/New_York EST EDT +America/Nipigon EST EDT +America/Nome AKST AKDT +America/North_Dakota/Beulah CST CDT +America/North_Dakota/Center CST CDT +America/North_Dakota/New_Salem CST CDT +America/Ojinaga MST MDT +America/Panama EST +America/Pangnirtung EST EDT +America/Phoenix MST +America/Port-au-Prince EST EDT +America/Puerto_Rico AST +America/Rainy_River CST CDT +America/Rankin_Inlet CST CDT +America/Regina CST +America/Resolute CST CDT +America/Santo_Domingo AST +America/Sitka AKST AKDT +America/St_Johns NST NDT +America/Swift_Current CST +America/Tegucigalpa CST CDT +America/Thule AST ADT +America/Thunder_Bay EST EDT +America/Tijuana PST PDT +America/Toronto EST EDT +America/Vancouver PST PDT +America/Whitehorse MST +America/Winnipeg CST CDT +America/Yakutat AKST AKDT +America/Yellowknife MST MDT +Antarctica/Macquarie AEST AEDT +Antarctica/Troll UTC +Asia/Amman EET EEST +Asia/Beirut EET EEST +Asia/Damascus EET EEST +Asia/Famagusta EET EEST +Asia/Gaza EET EEST +Asia/Hebron EET EEST +Asia/Hong_Kong HKT HKST +Asia/Jakarta WIB +Asia/Jayapura WIT +Asia/Jerusalem IST IDT +Asia/Karachi PKT PKST +Asia/Kolkata IST +Asia/Macau CST CDT +Asia/Makassar WITA +Asia/Manila PST PDT +Asia/Nicosia EET EEST +Asia/Pontianak WIB +Asia/Pyongyang KST +Asia/Seoul KST KDT +Asia/Shanghai CST CDT +Asia/Taipei CST CDT +Asia/Tokyo JST JDT +Atlantic/Bermuda AST ADT +Atlantic/Canary WET WEST +Atlantic/Faroe WET WEST +Atlantic/Madeira WET WEST +Atlantic/Reykjavik GMT +Australia/Adelaide ACST ACDT +Australia/Brisbane AEST AEDT +Australia/Broken_Hill ACST ACDT +Australia/Darwin ACST ACDT +Australia/Hobart AEST AEDT +Australia/Lindeman AEST AEDT +Australia/Melbourne AEST AEDT +Australia/Perth AWST AWDT +Australia/Sydney AEST AEDT +CET CET CEST +CST6CDT CST CDT +EET EET EEST +EST EST +EST5EDT EST EDT +Europe/Amsterdam CET CEST +Europe/Andorra CET CEST +Europe/Athens EET EEST +Europe/Belgrade CET CEST +Europe/Berlin CET CEST +Europe/Brussels CET CEST +Europe/Bucharest EET EEST +Europe/Budapest CET CEST +Europe/Chisinau EET EEST +Europe/Copenhagen CET CEST +Europe/Dublin IST/GMT IST/GMT +Europe/Gibraltar CET CEST +Europe/Helsinki EET EEST +Europe/Kaliningrad EET +Europe/Kiev EET EEST +Europe/Lisbon WET WEST +Europe/London GMT/BST GMT/BST +Europe/Luxembourg CET CEST +Europe/Madrid CET CEST +Europe/Malta CET CEST +Europe/Monaco CET CEST +Europe/Moscow MSK +Europe/Oslo CET CEST +Europe/Paris CET CEST +Europe/Prague CET CEST +Europe/Riga EET EEST +Europe/Rome CET CEST +Europe/Simferopol MSK +Europe/Sofia EET EEST +Europe/Stockholm CET CEST +Europe/Tallinn EET EEST +Europe/Tirane CET CEST +Europe/Uzhgorod EET EEST +Europe/Vienna CET CEST +Europe/Vilnius EET EEST +Europe/Warsaw CET CEST +Europe/Zaporozhye EET EEST +Europe/Zurich CET CEST +HST HST +MET MET MEST +MST MST +MST7MDT MST MDT +PST8PDT PST PDT +Pacific/Auckland NZST NZDT +Pacific/Guam ChST +Pacific/Honolulu HST +Pacific/Pago_Pago SST +WET WET WEST diff --git a/test/jdk/java/util/TimeZone/tools/share/CompareYearData.pl b/test/jdk/java/util/TimeZone/tools/share/CompareYearData.pl new file mode 100644 index 00000000000..4a98e625ec4 --- /dev/null +++ b/test/jdk/java/util/TimeZone/tools/share/CompareYearData.pl @@ -0,0 +1,84 @@ +# +# Copyright (c) 2008, 2022, 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 +# under the terms of the GNU General Public License version 2 only, as +# published by the Free Software Foundation. +# +# This code is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# version 2 for more details (a copy is included in the LICENSE file that +# accompanied this code). +# +# You should have received a copy of the GNU General Public License version +# 2 along with this work; if not, write to the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA +# or visit www.oracle.com if you need additional information or have any +# questions. +# + +# +# Compares two year* test data files +# Typical usage: +# perl CompareYearData.pl ../../TimeZoneData/year2008 year2008 +# + +%oldData = &readData($ARGV[0]); +%newData = &readData($ARGV[1]); + +foreach $key (sort(keys(%oldData))) { + if (defined($newData{$key})) { + if ($oldData{$key} ne $newData{$key}) { + print "Changed:\n"; + print "$oldData{$key}"; + print "---\n"; + print "$newData{$key}"; + } + delete $newData{$key}; + } else { + print "Deleted:\n"; + print "$oldData{$key}"; + } +} +foreach $key (sort(keys(%newData))) { + print "Added:\n"; + print "$newData{$key}"; +} + +sub readData { + local($file) = @_; + + open(F, $file) || die "Can't open $file\n"; + my %data = (); + my $line = 0; + my $id = ""; + + while () { + $line++; + s/^\s*\d+ //; + if (/tzdata\d+/) { + $data{" version"} = $_; + next; + } + if (/(\s*#.*$)/) { + $data{" comments"} .= $_; + next; + } + if (/^(Zone|Rule)/) { + die "No id at line: $line\n" if ($id eq ""); + $data{$id} .= $_; + } elsif (/^(\S+)\s+\S+/) { + $id = $1; + $data{$id} = $_; + $flag = 1; + } else { + die "Unknown format at line: $line: $file\n"; + } + } + close(F); + return %data; +} diff --git a/test/jdk/java/util/TimeZone/tools/share/Makefile b/test/jdk/java/util/TimeZone/tools/share/Makefile new file mode 100644 index 00000000000..69c4838efe0 --- /dev/null +++ b/test/jdk/java/util/TimeZone/tools/share/Makefile @@ -0,0 +1,58 @@ +# +# Copyright (c) 2008, 2022, 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 +# under the terms of the GNU General Public License version 2 only, as +# published by the Free Software Foundation. +# +# This code is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# version 2 for more details (a copy is included in the LICENSE file that +# accompanied this code). +# +# You should have received a copy of the GNU General Public License version +# 2 along with this work; if not, write to the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA +# or visit www.oracle.com if you need additional information or have any +# questions. +# + +# +# +# This makefile is used to update the time zone tests data: aliases.txt displaynames.txt +# and VERSION. After switching to new build system in JDK8 the following make +# command should be used for test data updates: +# make JDK_HOME= +# make install +# + +TZDATA = ../../../../../../../src/java.base/share/data/tzdata +TZDATA_VER = `grep '^tzdata' $(TZDATA)/VERSION` +TZNAME = africa antarctica asia australasia europe northamerica \ + solar87 solar88 solar89 southamerica \ + backward +TZFILES = $(addprefix $(TZDATA)/, $(TZNAME)) +ALIASLIST = aliases.txt +DISPLAYNAMES = displaynames.txt + +all: $(DISPLAYNAMES) VERSION $(ALIASLIST) + +$(DISPLAYNAMES): $(TZFILES) makeZoneData.pl + (cat $(TZFILES) | perl makeZoneData.pl -v -V "$(TZDATA_VER)") 2>errors + +VERSION: $(TZDATA)/VERSION + echo "$(TZDATA_VER)" > VERSION + +$(ALIASLIST): $(TZFILES) + rm -f $(ALIASLIST) + grep -h "^Link" $(TZFILES) >> $(ALIASLIST) + +clean: + rm -f $(DISPLAYNAMES) errors year???? VERSION $(ALIASLIST) + +install: + cp $(ALIASLIST) $(DISPLAYNAMES) VERSION ../../TimeZoneData/ diff --git a/test/jdk/java/util/TimeZone/tools/share/makeZoneData.pl b/test/jdk/java/util/TimeZone/tools/share/makeZoneData.pl new file mode 100644 index 00000000000..2df25a58582 --- /dev/null +++ b/test/jdk/java/util/TimeZone/tools/share/makeZoneData.pl @@ -0,0 +1,283 @@ +# +# Copyright (c) 2008, 2022, 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 +# under the terms of the GNU General Public License version 2 only, as +# published by the Free Software Foundation. +# +# This code is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# version 2 for more details (a copy is included in the LICENSE file that +# accompanied this code). +# +# You should have received a copy of the GNU General Public License version +# 2 along with this work; if not, write to the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA +# or visit www.oracle.com if you need additional information or have any +# questions. +# + +# +# +# +# Perl script to generate ZoneData from Olson public time zone data. +# +# For J2SE before JDK1.3, see ../../README how to update TimeZone.java +# static TimeZoneData. +# For J2SE since JDK1.4, this script is used to generate testdata(reference) +# for ZoneData.sh which is one of TimeZone Regression test. + +$continue = 0; + +# verbose flag +$verbose = 0; + +# version of Olson's public zone information (e.g. "tzdata2000g") +$versionName = "unknown"; + +# Number of testdata files. +$count = 5; + +# Display name datafile +$displayNameFile = "displaynames.txt"; + +# time zone IDs to be generated. If it's empty, then generate all time +# zone in the tzdata files. +@javatzids = (); + +# +# Parses command-line options +# +while ($#ARGV >= 0) { + if ($ARGV[0] =~ /^-v/) { + $verbose = 1; + } elsif ($ARGV[0] =~ /^-V/) { + $versionName = $ARGV[1]; + shift(@ARGV); + } else { + @javatzids = &readIDs($ARGV[0]); + last; + } + shift(@ARGV); +} + +# Beginning year of testdata +($sec, $min, $hour, $mday, $mon, $year, $wday, $ydat, $isdst) = gmtime(); +$baseYear = $year+1900; + +if ($verbose == 1) { + print STDERR "baseYear : $baseYear\n"; + print STDERR "versionName : $versionName\n"; +} + +# Open display name datafile +open (DNFD, ">$displayNameFile") || die ("$displayNameFile : open error.\n"); + +while() { + chop; + if (/^\#/) { # skip comment line + next; + } + @item = ("foo"); + + # Zone NAME GMTOFF RULES FORMAT [UNTIL] + if ($continue == 1) { + s/\#.*//; # chop trailing comments + s/\s+$//; + s/^\s+//; + @item = split(/\s+/, $_); + @item = ($zname, @item); # push zone name + } elsif (/^Zone/) { + s/\#.*//; # chop trailing comments + s/\s+$//; + @item = split(/\s+/, $_); + $zname = $item[1]; + if (defined ($zones{$name})) { + printf STDERR "WARNING: duplicate definition of zone $name\n"; + } + shift(@item); + } + if (@item[0] ne "foo") { + if($#item == 3) { # find out no UNTIL line + $item[3] =~ s/%/%%/; + $zones{$item[0]} = "Zone $item[0]\t$item[1]\t$item[2]\t$item[3]"; + } else { + $continue = 1; + next; + } + } + + # Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S + if (/^Rule/) { + ($rule, $name, $from, $to, $type, $in, $on, $at, $save, $letter) + = split(/\s+/, $_); + + # matches specified year? + for ($i = 0; $i < $count; $i++) { + if ($from <= $baseYear+$i && ($to >= $baseYear+$i || $to eq "max") + || ($from == $baseYear+$i && $to eq "only")) { + if ($save ne "0") { + $rules[$i]{$name . "0"} = $_; + } else { + $rules[$i]{$name . "1"} = $_; + } + } else { + if ($from <= $baseYear) { + if ($save ne "0") { + $oldRules[0]{$name} = $_; + } else { + $oldRules[1]{$name} = $_; + } + } + } + } + } + $continue = 0; +} + +# +# Prepare output files +# +for ($i = 0, $fd = 0; $i < $count; $i++, $fd++) { + $filename = "year".($baseYear+$i); + open ($fd, ">$filename") || die ("$filename : open error.\n"); + print $fd "# Based on $versionName\n"; +} + +# +# If no IDs are specified, produce test data for all zones. +# +if ($#javatzids < 0) { + @javatzids = keys(%zones); +} + +foreach $z (@javatzids) { + # + # skip any Riyadh zones; ZoneData.java can't handle Riyada zones + # + next if ($z =~ /Riyadh/); + + for ($i = 0, $fd = 0; $i < $count; $i++, $fd++) { + if (!defined($zones{$z})) { + printf $fd "$z ?\n"; + printf STDERR "WARNING: java zone $z not found\n"; + next; + } + @item = split(/\s+/, $zones{$z}); + if ($item[3] ne "-") { + printf $fd "$item[1] $item[2] "; + if (defined($rules[$i]{$item[3] . "0"}) + && defined($rules[$i]{$item[3] . "1"})) { + $rule0 = $rules[$i]{$item[3] . "0"}; + $rule1 = $rules[$i]{$item[3] . "1"}; + @r0 = split(/\s+/, $rule0); + @r1 = split(/\s+/, $rule1); + printf $fd "$r0[5] $r0[6] $r0[7] $r1[5] $r1[6] $r1[7] $r0[8]\n"; + printf $fd "$zones{$z}\n"; + printf $fd "$rule0\n"; + printf $fd "$rule1\n"; + if ($i == 0) { + $std = $dst = $item[4]; + $std =~ s/%%s/$r1[9]/; + if ($r1[9] eq "-") { + $std =~ s/-//; + } + $dst =~ s/%%s/$r0[9]/; + if ($r0[9] eq "-") { + $dst =~ s/-//; + } + if ("$std$dst" =~ /[A-Z]/) { + print DNFD "$item[1] $std $dst\n"; + } + } + } else { + printf $fd "-\n"; # In case we cannot find Rule, assume no DST. + printf $fd "$zones{$z}\n"; + printf STDERR "WARNING: $z no rules defined for $item[3]\n"; + if ($i == 0) { + # About 30 time zones (e.g. Asia/Tokyo needs the following + # recovery. + if ($item[4] =~ m/%/) { + @r0 = split(/\s+/, $oldRules[0]{$item[3]}); + @r1 = split(/\s+/, $oldRules[1]{$item[3]}); + if ($i == 0) { + $std = $dst = $item[4]; + $std =~ s/%%s/$r1[9]/; + if ($r1[9] eq "-") { + $std =~ s/-//; + } + $dst =~ s/%%s/$r0[9]/; + if ($r0[9] eq "-") { + $dst =~ s/-//; + } + if ("$std$dst" =~ /[A-Z]/) { + print DNFD "$item[1] $std $dst\n"; + } + } + } else { + if ("$item[4]" =~ /[A-Z]/) { + print DNFD "$item[1] $item[4]\n"; + } + } + } + } + } else { + printf $fd "$item[1] $item[2] $item[3]\n"; + printf $fd "$zones{$z}\n"; + if ($i == 0 && "$item[4]" =~ /[A-Z]/) { + print DNFD "$item[1] $item[4]\n"; + } + } + } +} + +# +# Close all the output files +# +close (DNFD); +for ($i = 0, $fd = 0; $i < $count; $i++, $fd++) { + close ($fd); +} + +# +# Sort the displaynames.txt file +# +open my $fh, '<', $displayNameFile || die ("Can't open $displayNameFile for sorting\n");; +chomp(my @names = <$fh>); +close $fh; +open my $fh, '>', $displayNameFile; +foreach $line (sort @names) { print $fh $line,"\n"; } +close $fh; + +exit(0); + +sub readIDs { + local ($file) = @_; + local (@ids, $i); + + open(F, $file) || die "Fatal: can't open $file.\n"; + + $i = 0; + while () { + chop; + if (/^\#/) { # skip comment line + next; + } + + # trim any leading and trailing space + s/^\s+//; + s/\s+$//; + + if (/^\s*$/) { # skip blank line + next; + } + + $ids[$i++] = $_; + } + close(F); + return @ids; +}