1 /*
  2  * Copyright (c) 2000, 2016, 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  * @library /java/text/testlib
 29  * @run main/othervm -Djava.locale.providers=COMPAT,SPI TimeZoneNameTest
 30  */
 31 
 32 import java.util.*;
 33 import java.text.*;
 34 
 35 public class TimeZoneNameTest extends IntlTest
 36 {
 37     static final String[] data = {
 38         // Added to verify the fix for 4836940
 39         "N", "Antarctica/Rothera", "ROTT", "Rothera Time", "ROTT", "Rothera Time",
 40         "N", "Asia/Tehran", "IRST", "Iran Standard Time", "IRDT", "Iran Daylight Time",
 41         "N", "Iran", "IRST", "Iran Standard Time", "IRDT", "Iran Daylight Time",
 42 
 43         // Added to verify the fix for 4851113
 44         "N", "America/Rankin_Inlet", "CST", "Central Standard Time", "CDT", "Central Daylight Time",
 45         "N", "Asia/Samarkand", "UZT", "Uzbekistan Time", "UZT", "Uzbekistan Time",
 46         "N", "Asia/Tashkent", "UZT", "Uzbekistan Time", "UZT", "Uzbekistan Time",
 47         "N", "Atlantic/Jan_Mayen", "CET", "Central European Time", "CEST", "Central European Summer Time",
 48         "N", "Europe/Oslo", "CET", "Central European Time", "CEST", "Central European Summer Time",
 49 
 50         "N", "Pacific/Honolulu", "HST", "Hawaii Standard Time", "HST", "Hawaii Standard Time",
 51         "N", "America/Los_Angeles", "PST", "Pacific Standard Time", "PDT", "Pacific Daylight Time",
 52         "N", "US/Pacific", "PST", "Pacific Standard Time", "PDT", "Pacific Daylight Time",
 53         "N", "America/Phoenix", "MST", "Mountain Standard Time", "MST", "Mountain Standard Time",
 54         "N", "America/Denver", "MST", "Mountain Standard Time", "MDT", "Mountain Daylight Time",
 55         "N", "America/Chicago", "CST", "Central Standard Time", "CDT", "Central Daylight Time",
 56         "N", "America/Indianapolis", "EST", "Eastern Standard Time", "EST", "Eastern Standard Time",
 57         "N", "America/Montreal", "EST", "Eastern Standard Time", "EDT", "Eastern Daylight Time",
 58         "N", "America/Toronto", "EST", "Eastern Standard Time", "EDT", "Eastern Daylight Time",
 59         "N", "America/New_York", "EST", "Eastern Standard Time", "EDT", "Eastern Daylight Time",
 60         "S", "America/Manaus", "AMT", "Amazon Time", "AMT", "Amazon Time",
 61         "S", "America/Campo_Grande", "AMT", "Amazon Time", "AMST", "Amazon Summer Time",
 62         "S", "America/Bahia", "BRT", "Brasilia Time", "BRST", "Brasilia Summer Time",
 63         "N", "America/Halifax", "AST", "Atlantic Standard Time", "ADT", "Atlantic Daylight Time",
 64         "N", "GMT", "GMT", "Greenwich Mean Time", "GMT", "Greenwich Mean Time",
 65         "N", "Europe/London", "GMT", "Greenwich Mean Time", "BST", "British Summer Time",
 66         "N", "Europe/Paris", "CET", "Central European Time", "CEST", "Central European Summer Time",
 67         "N", "WET", "WET", "Western European Time", "WEST", "Western European Summer Time",
 68         "N", "Europe/Berlin", "CET", "Central European Time", "CEST", "Central European Summer Time",
 69         "N", "Asia/Jerusalem", "IST", "Israel Standard Time", "IDT", "Israel Daylight Time",
 70         "N", "Europe/Helsinki", "EET", "Eastern European Time", "EEST", "Eastern European Summer Time",
 71         "N", "Africa/Cairo", "EET", "Eastern European Time", "EEST", "Eastern European Summer Time",
 72         "N", "Europe/Moscow", "MSK", "Moscow Standard Time", "MSD", "Moscow Daylight Time",
 73         "N", "Asia/Omsk", "OMST", "Omsk Time", "OMSST", "Omsk Summer Time",
 74         "N", "Asia/Shanghai", "CST", "China Standard Time", "CST", "China Standard Time",
 75         "N", "Asia/Tokyo", "JST", "Japan Standard Time", "JST", "Japan Standard Time",
 76         "N", "Japan", "JST", "Japan Standard Time", "JST", "Japan Standard Time",
 77         "N", "Asia/Seoul", "KST", "Korea Standard Time", "KST", "Korea Standard Time",
 78         "N", "ROK", "KST", "Korea Standard Time", "KST", "Korea Standard Time",
 79         "S", "Australia/Darwin", "ACST", "Australian Central Standard Time (Northern Territory)",
 80                                  "ACST", "Australian Central Standard Time (Northern Territory)",
 81         "S", "Australia/Adelaide", "ACST", "Australian Central Standard Time (South Australia)",
 82                                    "ACDT", "Australian Central Daylight Time (South Australia)",
 83         "S", "Australia/Broken_Hill", "ACST", "Australian Central Standard Time (South Australia/New South Wales)",
 84                                       "ACDT", "Australian Central Daylight Time (South Australia/New South Wales)",
 85         "S", "Australia/Hobart", "AEST", "Australian Eastern Standard Time (Tasmania)",
 86                                  "AEDT", "Australian Eastern Daylight Time (Tasmania)",
 87         "S", "Australia/Brisbane", "AEST", "Australian Eastern Standard Time (Queensland)",
 88                                    "AEST", "Australian Eastern Standard Time (Queensland)",
 89         "S", "Australia/Sydney", "AEST", "Australian Eastern Standard Time (New South Wales)",
 90                                  "AEDT", "Australian Eastern Daylight Time (New South Wales)",
 91         "N", "Pacific/Guam", "ChST", "Chamorro Standard Time",
 92                              "ChST", "Chamorro Standard Time",
 93         "N", "Pacific/Saipan", "ChST", "Chamorro Standard Time",
 94                                "ChST", "Chamorro Standard Time",
 95     };
 96 
 97     public static void main(String[] args) throws Exception {
 98         Locale reservedLocale = Locale.getDefault();
 99         try {
100             Locale.setDefault(Locale.US);
101             new TimeZoneNameTest().run(args);
102         } finally {
103             // restore the reserved locale
104             Locale.setDefault(reservedLocale);
105         }
106     }
107 
108     public void Test4112924() {
109         SimpleDateFormat lfmt = new SimpleDateFormat("zzzz");
110         SimpleDateFormat sfmt = new SimpleDateFormat("z");
111 
112         GregorianCalendar june = new GregorianCalendar(2000, Calendar.JUNE, 21);
113         GregorianCalendar december = new GregorianCalendar(2000, Calendar.DECEMBER, 21);
114 
115         int count = data.length;
116         for (int i = 0; i < count; i++) {
117             GregorianCalendar sol1, sol2;
118 
119             // check hemisphere
120             if ("N".equals(data[i++])) {
121                 sol1 = december;
122                 sol2 = june;
123             } else {
124                 sol1 = june;
125                 sol2 = december;
126             }
127 
128             TimeZone tz = TimeZone.getTimeZone(data[i++]);
129             lfmt.setTimeZone(tz);
130             sfmt.setTimeZone(tz);
131 
132             logln(tz.getID() + ": " + sfmt.format(sol1.getTime()) + ", " + lfmt.format(sol1.getTime()));
133             logln(tz.getID() + ": " + sfmt.format(sol2.getTime()) + ", " + lfmt.format(sol2.getTime()));
134             String s = sfmt.format(sol1.getTime());
135             if (!data[i].equals(s)) {
136                 errln(tz.getID() + ": wrong short name: \"" + s + "\" (expected \"" + data[i] + "\")");
137             }
138             s = lfmt.format(sol1.getTime());
139             if (!data[++i].equals(s)) {
140                 errln(tz.getID() + ": wrong long name: \"" + s + "\" (expected \"" + data[i] + "\")");
141             }
142             s = sfmt.format(sol2.getTime());
143             if (!data[++i].equals(s)) {
144                 errln(tz.getID() + ": wrong short name: \"" + s + "\" (expected \"" + data[i] + "\")");
145             }
146             s = lfmt.format(sol2.getTime());
147             if (!data[++i].equals(s)) {
148                 errln(tz.getID() + ": wrong long name: \"" + s + "\" (expected \"" + data[i] + "\")");
149             }
150         }
151     }
152 }