1 /*
  2  * Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 
 24 /**
 25  * @test
 26  * @bug 4348864 4112924 4425386 4495052 4836940 4851113 8008577
 27  * @summary test time zone display names in en_US locale
 28  * @run junit/othervm -Djava.locale.providers=COMPAT,SPI TimeZoneNameTest
 29  */
 30 
 31 import java.util.*;
 32 import java.text.*;
 33 
 34 import org.junit.jupiter.api.Test;
 35 import org.junit.jupiter.api.BeforeAll;
 36 
 37 import static org.junit.jupiter.api.Assertions.fail;
 38 
 39 public class TimeZoneNameTest
 40 {
 41 
 42     // Change JVM default Locale
 43     @BeforeAll
 44     static void initAll() {
 45         Locale.setDefault(Locale.US);
 46     }
 47 
 48     static final String[] data = {
 49         // Added to verify the fix for 4836940
 50         "N", "Antarctica/Rothera", "ROTT", "Rothera Time", "ROTT", "Rothera Time",
 51         "N", "Asia/Tehran", "IRST", "Iran Standard Time", "IRDT", "Iran Daylight Time",
 52         "N", "Iran", "IRST", "Iran Standard Time", "IRDT", "Iran Daylight Time",
 53 
 54         // Added to verify the fix for 4851113
 55         "N", "America/Rankin_Inlet", "CST", "Central Standard Time", "CDT", "Central Daylight Time",
 56         "N", "Asia/Samarkand", "UZT", "Uzbekistan Time", "UZT", "Uzbekistan Time",
 57         "N", "Asia/Tashkent", "UZT", "Uzbekistan Time", "UZT", "Uzbekistan Time",
 58         "N", "Atlantic/Jan_Mayen", "CET", "Central European Time", "CEST", "Central European Summer Time",
 59         "N", "Europe/Oslo", "CET", "Central European Time", "CEST", "Central European Summer Time",
 60 
 61         "N", "Pacific/Honolulu", "HST", "Hawaii Standard Time", "HST", "Hawaii Standard Time",
 62         "N", "America/Los_Angeles", "PST", "Pacific Standard Time", "PDT", "Pacific Daylight Time",
 63         "N", "US/Pacific", "PST", "Pacific Standard Time", "PDT", "Pacific Daylight Time",
 64         "N", "America/Phoenix", "MST", "Mountain Standard Time", "MST", "Mountain Standard Time",
 65         "N", "America/Denver", "MST", "Mountain Standard Time", "MDT", "Mountain Daylight Time",
 66         "N", "America/Chicago", "CST", "Central Standard Time", "CDT", "Central Daylight Time",
 67         "N", "America/Indianapolis", "EST", "Eastern Standard Time", "EST", "Eastern Standard Time",
 68         "N", "America/Montreal", "EST", "Eastern Standard Time", "EDT", "Eastern Daylight Time",
 69         "N", "America/Toronto", "EST", "Eastern Standard Time", "EDT", "Eastern Daylight Time",
 70         "N", "America/New_York", "EST", "Eastern Standard Time", "EDT", "Eastern Daylight Time",
 71         "S", "America/Manaus", "AMT", "Amazon Time", "AMT", "Amazon Time",
 72         "S", "America/Campo_Grande", "AMT", "Amazon Time", "AMST", "Amazon Summer Time",
 73         "S", "America/Bahia", "BRT", "Brasilia Time", "BRST", "Brasilia Summer Time",
 74         "N", "America/Halifax", "AST", "Atlantic Standard Time", "ADT", "Atlantic Daylight Time",
 75         "N", "GMT", "GMT", "Greenwich Mean Time", "GMT", "Greenwich Mean Time",
 76         "N", "Europe/London", "GMT", "Greenwich Mean Time", "BST", "British Summer Time",
 77         "N", "Europe/Paris", "CET", "Central European Time", "CEST", "Central European Summer Time",
 78         "N", "WET", "WET", "Western European Time", "WEST", "Western European Summer Time",
 79         "N", "Europe/Berlin", "CET", "Central European Time", "CEST", "Central European Summer Time",
 80         "N", "Asia/Jerusalem", "IST", "Israel Standard Time", "IDT", "Israel Daylight Time",
 81         "N", "Europe/Helsinki", "EET", "Eastern European Time", "EEST", "Eastern European Summer Time",
 82         "N", "Africa/Cairo", "EET", "Eastern European Time", "EEST", "Eastern European Summer Time",
 83         "N", "Europe/Moscow", "MSK", "Moscow Standard Time", "MSD", "Moscow Daylight Time",
 84         "N", "Asia/Omsk", "OMST", "Omsk Time", "OMSST", "Omsk Summer Time",
 85         "N", "Asia/Shanghai", "CST", "China Standard Time", "CST", "China Standard Time",
 86         "N", "Asia/Tokyo", "JST", "Japan Standard Time", "JST", "Japan Standard Time",
 87         "N", "Japan", "JST", "Japan Standard Time", "JST", "Japan Standard Time",
 88         "N", "Asia/Seoul", "KST", "Korea Standard Time", "KST", "Korea Standard Time",
 89         "N", "ROK", "KST", "Korea Standard Time", "KST", "Korea Standard Time",
 90         "S", "Australia/Darwin", "ACST", "Australian Central Standard Time (Northern Territory)",
 91                                  "ACST", "Australian Central Standard Time (Northern Territory)",
 92         "S", "Australia/Adelaide", "ACST", "Australian Central Standard Time (South Australia)",
 93                                    "ACDT", "Australian Central Daylight Time (South Australia)",
 94         "S", "Australia/Broken_Hill", "ACST", "Australian Central Standard Time (South Australia/New South Wales)",
 95                                       "ACDT", "Australian Central Daylight Time (South Australia/New South Wales)",
 96         "S", "Australia/Hobart", "AEST", "Australian Eastern Standard Time (Tasmania)",
 97                                  "AEDT", "Australian Eastern Daylight Time (Tasmania)",
 98         "S", "Australia/Brisbane", "AEST", "Australian Eastern Standard Time (Queensland)",
 99                                    "AEST", "Australian Eastern Standard Time (Queensland)",
100         "S", "Australia/Sydney", "AEST", "Australian Eastern Standard Time (New South Wales)",
101                                  "AEDT", "Australian Eastern Daylight Time (New South Wales)",
102         "N", "Pacific/Guam", "ChST", "Chamorro Standard Time",
103                              "ChST", "Chamorro Standard Time",
104         "N", "Pacific/Saipan", "ChST", "Chamorro Standard Time",
105                                "ChST", "Chamorro Standard Time",
106     };
107 
108     @Test
109     public void Test4112924() {
110         SimpleDateFormat lfmt = new SimpleDateFormat("zzzz");
111         SimpleDateFormat sfmt = new SimpleDateFormat("z");
112 
113         GregorianCalendar june = new GregorianCalendar(2000, Calendar.JUNE, 21);
114         GregorianCalendar december = new GregorianCalendar(2000, Calendar.DECEMBER, 21);
115 
116         int count = data.length;
117         for (int i = 0; i < count; i++) {
118             GregorianCalendar sol1, sol2;
119 
120             // check hemisphere
121             if ("N".equals(data[i++])) {
122                 sol1 = december;
123                 sol2 = june;
124             } else {
125                 sol1 = june;
126                 sol2 = december;
127             }
128 
129             TimeZone tz = TimeZone.getTimeZone(data[i++]);
130             lfmt.setTimeZone(tz);
131             sfmt.setTimeZone(tz);
132 
133             System.out.println(tz.getID() + ": " + sfmt.format(sol1.getTime()) + ", " + lfmt.format(sol1.getTime()));
134             System.out.println(tz.getID() + ": " + sfmt.format(sol2.getTime()) + ", " + lfmt.format(sol2.getTime()));
135             String s = sfmt.format(sol1.getTime());
136             if (!data[i].equals(s)) {
137                 fail(tz.getID() + ": wrong short name: \"" + s + "\" (expected \"" + data[i] + "\")");
138             }
139             s = lfmt.format(sol1.getTime());
140             if (!data[++i].equals(s)) {
141                 fail(tz.getID() + ": wrong long name: \"" + s + "\" (expected \"" + data[i] + "\")");
142             }
143             s = sfmt.format(sol2.getTime());
144             if (!data[++i].equals(s)) {
145                 fail(tz.getID() + ": wrong short name: \"" + s + "\" (expected \"" + data[i] + "\")");
146             }
147             s = lfmt.format(sol2.getTime());
148             if (!data[++i].equals(s)) {
149                 fail(tz.getID() + ": wrong long name: \"" + s + "\" (expected \"" + data[i] + "\")");
150             }
151         }
152     }
153 }