File: TimeZoneNameTest.java

package info (click to toggle)
openjdk-11 11.0.4%2B11-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 757,028 kB
  • sloc: java: 5,016,041; xml: 1,191,974; cpp: 934,731; ansic: 555,697; sh: 24,299; objc: 12,703; python: 3,602; asm: 3,415; makefile: 2,772; awk: 351; sed: 172; perl: 114; jsp: 24; csh: 3
file content (152 lines) | stat: -rw-r--r-- 8,547 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
 * Copyright (c) 2000, 2016, 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 4348864 4112924 4425386 4495052 4836940 4851113 8008577
 * @summary test time zone display names in en_US locale
 * @library /java/text/testlib
 * @run main/othervm -Djava.locale.providers=COMPAT,SPI TimeZoneNameTest
 */

import java.util.*;
import java.text.*;

public class TimeZoneNameTest extends IntlTest
{
    static final String[] data = {
        // Added to verify the fix for 4836940
        "N", "Antarctica/Rothera", "ROTT", "Rothera Time", "ROTT", "Rothera Time",
        "N", "Asia/Tehran", "IRST", "Iran Standard Time", "IRDT", "Iran Daylight Time",
        "N", "Iran", "IRST", "Iran Standard Time", "IRDT", "Iran Daylight Time",

        // Added to verify the fix for 4851113
        "N", "America/Rankin_Inlet", "CST", "Central Standard Time", "CDT", "Central Daylight Time",
        "N", "Asia/Samarkand", "UZT", "Uzbekistan Time", "UZT", "Uzbekistan Time",
        "N", "Asia/Tashkent", "UZT", "Uzbekistan Time", "UZT", "Uzbekistan Time",
        "N", "Atlantic/Jan_Mayen", "CET", "Central European Time", "CEST", "Central European Summer Time",
        "N", "Europe/Oslo", "CET", "Central European Time", "CEST", "Central European Summer Time",

        "N", "Pacific/Honolulu", "HST", "Hawaii Standard Time", "HST", "Hawaii Standard Time",
        "N", "America/Los_Angeles", "PST", "Pacific Standard Time", "PDT", "Pacific Daylight Time",
        "N", "US/Pacific", "PST", "Pacific Standard Time", "PDT", "Pacific Daylight Time",
        "N", "America/Phoenix", "MST", "Mountain Standard Time", "MST", "Mountain Standard Time",
        "N", "America/Denver", "MST", "Mountain Standard Time", "MDT", "Mountain Daylight Time",
        "N", "America/Chicago", "CST", "Central Standard Time", "CDT", "Central Daylight Time",
        "N", "America/Indianapolis", "EST", "Eastern Standard Time", "EST", "Eastern Standard Time",
        "N", "America/Montreal", "EST", "Eastern Standard Time", "EDT", "Eastern Daylight Time",
        "N", "America/Toronto", "EST", "Eastern Standard Time", "EDT", "Eastern Daylight Time",
        "N", "America/New_York", "EST", "Eastern Standard Time", "EDT", "Eastern Daylight Time",
        "S", "America/Manaus", "AMT", "Amazon Time", "AMT", "Amazon Time",
        "S", "America/Campo_Grande", "AMT", "Amazon Time", "AMST", "Amazon Summer Time",
        "S", "America/Bahia", "BRT", "Brasilia Time", "BRST", "Brasilia Summer Time",
        "N", "America/Halifax", "AST", "Atlantic Standard Time", "ADT", "Atlantic Daylight Time",
        "N", "GMT", "GMT", "Greenwich Mean Time", "GMT", "Greenwich Mean Time",
        "N", "Europe/London", "GMT", "Greenwich Mean Time", "BST", "British Summer Time",
        "N", "Europe/Paris", "CET", "Central European Time", "CEST", "Central European Summer Time",
        "N", "WET", "WET", "Western European Time", "WEST", "Western European Summer Time",
        "N", "Europe/Berlin", "CET", "Central European Time", "CEST", "Central European Summer Time",
        "N", "Asia/Jerusalem", "IST", "Israel Standard Time", "IDT", "Israel Daylight Time",
        "N", "Europe/Helsinki", "EET", "Eastern European Time", "EEST", "Eastern European Summer Time",
        "N", "Africa/Cairo", "EET", "Eastern European Time", "EEST", "Eastern European Summer Time",
        "N", "Europe/Moscow", "MSK", "Moscow Standard Time", "MSD", "Moscow Daylight Time",
        "N", "Asia/Omsk", "OMST", "Omsk Time", "OMSST", "Omsk Summer Time",
        "N", "Asia/Shanghai", "CST", "China Standard Time", "CST", "China Standard Time",
        "N", "Asia/Tokyo", "JST", "Japan Standard Time", "JST", "Japan Standard Time",
        "N", "Japan", "JST", "Japan Standard Time", "JST", "Japan Standard Time",
        "N", "Asia/Seoul", "KST", "Korea Standard Time", "KST", "Korea Standard Time",
        "N", "ROK", "KST", "Korea Standard Time", "KST", "Korea Standard Time",
        "S", "Australia/Darwin", "ACST", "Australian Central Standard Time (Northern Territory)",
                                 "ACST", "Australian Central Standard Time (Northern Territory)",
        "S", "Australia/Adelaide", "ACST", "Australian Central Standard Time (South Australia)",
                                   "ACDT", "Australian Central Daylight Time (South Australia)",
        "S", "Australia/Broken_Hill", "ACST", "Australian Central Standard Time (South Australia/New South Wales)",
                                      "ACDT", "Australian Central Daylight Time (South Australia/New South Wales)",
        "S", "Australia/Hobart", "AEST", "Australian Eastern Standard Time (Tasmania)",
                                 "AEDT", "Australian Eastern Daylight Time (Tasmania)",
        "S", "Australia/Brisbane", "AEST", "Australian Eastern Standard Time (Queensland)",
                                   "AEST", "Australian Eastern Standard Time (Queensland)",
        "S", "Australia/Sydney", "AEST", "Australian Eastern Standard Time (New South Wales)",
                                 "AEDT", "Australian Eastern Daylight Time (New South Wales)",
        "N", "Pacific/Guam", "ChST", "Chamorro Standard Time",
                             "ChST", "Chamorro Standard Time",
        "N", "Pacific/Saipan", "ChST", "Chamorro Standard Time",
                               "ChST", "Chamorro Standard Time",
    };

    public static void main(String[] args) throws Exception {
        Locale reservedLocale = Locale.getDefault();
        try {
            Locale.setDefault(Locale.US);
            new TimeZoneNameTest().run(args);
        } finally {
            // restore the reserved locale
            Locale.setDefault(reservedLocale);
        }
    }

    public void Test4112924() {
        SimpleDateFormat lfmt = new SimpleDateFormat("zzzz");
        SimpleDateFormat sfmt = new SimpleDateFormat("z");

        GregorianCalendar june = new GregorianCalendar(2000, Calendar.JUNE, 21);
        GregorianCalendar december = new GregorianCalendar(2000, Calendar.DECEMBER, 21);

        int count = data.length;
        for (int i = 0; i < count; i++) {
            GregorianCalendar sol1, sol2;

            // check hemisphere
            if ("N".equals(data[i++])) {
                sol1 = december;
                sol2 = june;
            } else {
                sol1 = june;
                sol2 = december;
            }

            TimeZone tz = TimeZone.getTimeZone(data[i++]);
            lfmt.setTimeZone(tz);
            sfmt.setTimeZone(tz);

            logln(tz.getID() + ": " + sfmt.format(sol1.getTime()) + ", " + lfmt.format(sol1.getTime()));
            logln(tz.getID() + ": " + sfmt.format(sol2.getTime()) + ", " + lfmt.format(sol2.getTime()));
            String s = sfmt.format(sol1.getTime());
            if (!data[i].equals(s)) {
                errln(tz.getID() + ": wrong short name: \"" + s + "\" (expected \"" + data[i] + "\")");
            }
            s = lfmt.format(sol1.getTime());
            if (!data[++i].equals(s)) {
                errln(tz.getID() + ": wrong long name: \"" + s + "\" (expected \"" + data[i] + "\")");
            }
            s = sfmt.format(sol2.getTime());
            if (!data[++i].equals(s)) {
                errln(tz.getID() + ": wrong short name: \"" + s + "\" (expected \"" + data[i] + "\")");
            }
            s = lfmt.format(sol2.getTime());
            if (!data[++i].equals(s)) {
                errln(tz.getID() + ": wrong long name: \"" + s + "\" (expected \"" + data[i] + "\")");
            }
        }
    }
}