Path: blob/master/test/jdk/java/text/Format/DateFormat/TimeZoneNameTest.java
41152 views
/*1* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 4348864 4112924 4425386 4495052 4836940 4851113 800857726* @summary test time zone display names in en_US locale27* @library /java/text/testlib28* @run main/othervm -Djava.locale.providers=COMPAT,SPI TimeZoneNameTest29*/3031import java.util.*;32import java.text.*;3334public class TimeZoneNameTest extends IntlTest35{36static final String[] data = {37// Added to verify the fix for 483694038"N", "Antarctica/Rothera", "ROTT", "Rothera Time", "ROTT", "Rothera Time",39"N", "Asia/Tehran", "IRST", "Iran Standard Time", "IRDT", "Iran Daylight Time",40"N", "Iran", "IRST", "Iran Standard Time", "IRDT", "Iran Daylight Time",4142// Added to verify the fix for 485111343"N", "America/Rankin_Inlet", "CST", "Central Standard Time", "CDT", "Central Daylight Time",44"N", "Asia/Samarkand", "UZT", "Uzbekistan Time", "UZT", "Uzbekistan Time",45"N", "Asia/Tashkent", "UZT", "Uzbekistan Time", "UZT", "Uzbekistan Time",46"N", "Atlantic/Jan_Mayen", "CET", "Central European Time", "CEST", "Central European Summer Time",47"N", "Europe/Oslo", "CET", "Central European Time", "CEST", "Central European Summer Time",4849"N", "Pacific/Honolulu", "HST", "Hawaii Standard Time", "HST", "Hawaii Standard Time",50"N", "America/Los_Angeles", "PST", "Pacific Standard Time", "PDT", "Pacific Daylight Time",51"N", "US/Pacific", "PST", "Pacific Standard Time", "PDT", "Pacific Daylight Time",52"N", "America/Phoenix", "MST", "Mountain Standard Time", "MST", "Mountain Standard Time",53"N", "America/Denver", "MST", "Mountain Standard Time", "MDT", "Mountain Daylight Time",54"N", "America/Chicago", "CST", "Central Standard Time", "CDT", "Central Daylight Time",55"N", "America/Indianapolis", "EST", "Eastern Standard Time", "EST", "Eastern Standard Time",56"N", "America/Montreal", "EST", "Eastern Standard Time", "EDT", "Eastern Daylight Time",57"N", "America/Toronto", "EST", "Eastern Standard Time", "EDT", "Eastern Daylight Time",58"N", "America/New_York", "EST", "Eastern Standard Time", "EDT", "Eastern Daylight Time",59"S", "America/Manaus", "AMT", "Amazon Time", "AMT", "Amazon Time",60"S", "America/Campo_Grande", "AMT", "Amazon Time", "AMST", "Amazon Summer Time",61"S", "America/Bahia", "BRT", "Brasilia Time", "BRST", "Brasilia Summer Time",62"N", "America/Halifax", "AST", "Atlantic Standard Time", "ADT", "Atlantic Daylight Time",63"N", "GMT", "GMT", "Greenwich Mean Time", "GMT", "Greenwich Mean Time",64"N", "Europe/London", "GMT", "Greenwich Mean Time", "BST", "British Summer Time",65"N", "Europe/Paris", "CET", "Central European Time", "CEST", "Central European Summer Time",66"N", "WET", "WET", "Western European Time", "WEST", "Western European Summer Time",67"N", "Europe/Berlin", "CET", "Central European Time", "CEST", "Central European Summer Time",68"N", "Asia/Jerusalem", "IST", "Israel Standard Time", "IDT", "Israel Daylight Time",69"N", "Europe/Helsinki", "EET", "Eastern European Time", "EEST", "Eastern European Summer Time",70"N", "Africa/Cairo", "EET", "Eastern European Time", "EEST", "Eastern European Summer Time",71"N", "Europe/Moscow", "MSK", "Moscow Standard Time", "MSD", "Moscow Daylight Time",72"N", "Asia/Omsk", "OMST", "Omsk Time", "OMSST", "Omsk Summer Time",73"N", "Asia/Shanghai", "CST", "China Standard Time", "CST", "China Standard Time",74"N", "Asia/Tokyo", "JST", "Japan Standard Time", "JST", "Japan Standard Time",75"N", "Japan", "JST", "Japan Standard Time", "JST", "Japan Standard Time",76"N", "Asia/Seoul", "KST", "Korea Standard Time", "KST", "Korea Standard Time",77"N", "ROK", "KST", "Korea Standard Time", "KST", "Korea Standard Time",78"S", "Australia/Darwin", "ACST", "Australian Central Standard Time (Northern Territory)",79"ACST", "Australian Central Standard Time (Northern Territory)",80"S", "Australia/Adelaide", "ACST", "Australian Central Standard Time (South Australia)",81"ACDT", "Australian Central Daylight Time (South Australia)",82"S", "Australia/Broken_Hill", "ACST", "Australian Central Standard Time (South Australia/New South Wales)",83"ACDT", "Australian Central Daylight Time (South Australia/New South Wales)",84"S", "Australia/Hobart", "AEST", "Australian Eastern Standard Time (Tasmania)",85"AEDT", "Australian Eastern Daylight Time (Tasmania)",86"S", "Australia/Brisbane", "AEST", "Australian Eastern Standard Time (Queensland)",87"AEST", "Australian Eastern Standard Time (Queensland)",88"S", "Australia/Sydney", "AEST", "Australian Eastern Standard Time (New South Wales)",89"AEDT", "Australian Eastern Daylight Time (New South Wales)",90"N", "Pacific/Guam", "ChST", "Chamorro Standard Time",91"ChST", "Chamorro Standard Time",92"N", "Pacific/Saipan", "ChST", "Chamorro Standard Time",93"ChST", "Chamorro Standard Time",94};9596public static void main(String[] args) throws Exception {97Locale reservedLocale = Locale.getDefault();98try {99Locale.setDefault(Locale.US);100new TimeZoneNameTest().run(args);101} finally {102// restore the reserved locale103Locale.setDefault(reservedLocale);104}105}106107public void Test4112924() {108SimpleDateFormat lfmt = new SimpleDateFormat("zzzz");109SimpleDateFormat sfmt = new SimpleDateFormat("z");110111GregorianCalendar june = new GregorianCalendar(2000, Calendar.JUNE, 21);112GregorianCalendar december = new GregorianCalendar(2000, Calendar.DECEMBER, 21);113114int count = data.length;115for (int i = 0; i < count; i++) {116GregorianCalendar sol1, sol2;117118// check hemisphere119if ("N".equals(data[i++])) {120sol1 = december;121sol2 = june;122} else {123sol1 = june;124sol2 = december;125}126127TimeZone tz = TimeZone.getTimeZone(data[i++]);128lfmt.setTimeZone(tz);129sfmt.setTimeZone(tz);130131logln(tz.getID() + ": " + sfmt.format(sol1.getTime()) + ", " + lfmt.format(sol1.getTime()));132logln(tz.getID() + ": " + sfmt.format(sol2.getTime()) + ", " + lfmt.format(sol2.getTime()));133String s = sfmt.format(sol1.getTime());134if (!data[i].equals(s)) {135errln(tz.getID() + ": wrong short name: \"" + s + "\" (expected \"" + data[i] + "\")");136}137s = lfmt.format(sol1.getTime());138if (!data[++i].equals(s)) {139errln(tz.getID() + ": wrong long name: \"" + s + "\" (expected \"" + data[i] + "\")");140}141s = sfmt.format(sol2.getTime());142if (!data[++i].equals(s)) {143errln(tz.getID() + ": wrong short name: \"" + s + "\" (expected \"" + data[i] + "\")");144}145s = lfmt.format(sol2.getTime());146if (!data[++i].equals(s)) {147errln(tz.getID() + ": wrong long name: \"" + s + "\" (expected \"" + data[i] + "\")");148}149}150}151}152153154