< prev index next >

test/jdk/java/text/Format/DateFormat/TimeZoneNameTest.java

Print this page

  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",

 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 }

  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",

 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 }
< prev index next >