1 /*
2 * Copyright (c) 2012, 2017, 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 */
32 import java.time.format.DateTimeFormatter;
33 import java.time.format.DateTimeFormatterBuilder;
34 import java.time.format.TextStyle;
35 import java.time.temporal.ChronoField;
36 import java.time.temporal.TemporalQueries;
37 import java.time.zone.ZoneRulesProvider;
38 import java.util.Arrays;
39 import java.util.Date;
40 import java.util.HashSet;
41 import java.util.Locale;
42 import java.util.Random;
43 import java.util.Set;
44 import java.util.TimeZone;
45 import jdk.test.lib.RandomFactory;
46
47 import org.testng.annotations.DataProvider;
48 import org.testng.annotations.Test;
49
50 /*
51 * @test
52 * @bug 8081022 8151876 8166875
53 * @key randomness
54 */
55
56 /**
57 * Test ZoneTextPrinterParser
58 */
59 @Test
60 public class TestZoneTextPrinterParser extends AbstractTestPrinterParser {
61
62 protected static DateTimeFormatter getFormatter(Locale locale, TextStyle style) {
63 return new DateTimeFormatterBuilder().appendZoneText(style)
64 .toFormatter(locale)
65 .withDecimalStyle(DecimalStyle.of(locale));
66 }
67
68 public void test_printText() {
69 Random r = RandomFactory.getRandom();
70 int N = 8;
71 Locale[] locales = Locale.getAvailableLocales();
72 Set<String> zids = ZoneRulesProvider.getAvailableZoneIds();
141 ZoneId.of("Asia/Shanghai"),
142 }));
143
144 private static Set<ZoneId> none = new HashSet<>();
145
146 @DataProvider(name="preferredZones")
147 Object[][] data_preferredZones() {
148 return new Object[][] {
149 {"America/New_York", "Eastern Standard Time", none, Locale.ENGLISH, TextStyle.FULL},
150 // {"EST", "Eastern Standard Time", preferred, Locale.ENGLISH, TextStyle.FULL},
151 {"Europe/Paris", "Central European Time", none, Locale.ENGLISH, TextStyle.FULL},
152 // {"CET", "Central European Time", preferred, Locale.ENGLISH, TextStyle.FULL}, no three-letter ID in CLDR
153 {"Asia/Shanghai", "China Standard Time", none, Locale.ENGLISH, TextStyle.FULL},
154 {"Asia/Macau", "China Standard Time", preferred, Locale.ENGLISH, TextStyle.FULL},
155 {"Asia/Taipei", "Taipei Standard Time", preferred, Locale.ENGLISH, TextStyle.FULL},
156 {"America/Chicago", "CST", none, Locale.ENGLISH, TextStyle.SHORT},
157 {"Asia/Taipei", "CST", preferred, Locale.ENGLISH, TextStyle.SHORT},
158 {"Australia/South", "ACST", preferred_s, Locale.ENGLISH, TextStyle.SHORT},
159 {"America/Chicago", "CDT", none, Locale.ENGLISH, TextStyle.SHORT},
160 {"Asia/Shanghai", "CDT", preferred_s, Locale.ENGLISH, TextStyle.SHORT},
161 };
162 }
163
164 @Test(dataProvider="preferredZones")
165 public void test_ParseText(String expected, String text, Set<ZoneId> preferred, Locale locale, TextStyle style) {
166 DateTimeFormatter fmt = new DateTimeFormatterBuilder().appendZoneText(style, preferred)
167 .toFormatter(locale)
168 .withDecimalStyle(DecimalStyle.of(locale));
169
170 String ret = fmt.parse(text, TemporalQueries.zone()).getId();
171
172 System.out.printf("[%-5s %s] %24s -> %s(%s)%n",
173 locale.toString(),
174 style == TextStyle.FULL ? " full" :"short",
175 text, ret, expected);
176
177 assertEquals(ret, expected);
178
179 }
180
|
1 /*
2 * Copyright (c) 2012, 2018, 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 */
32 import java.time.format.DateTimeFormatter;
33 import java.time.format.DateTimeFormatterBuilder;
34 import java.time.format.TextStyle;
35 import java.time.temporal.ChronoField;
36 import java.time.temporal.TemporalQueries;
37 import java.time.zone.ZoneRulesProvider;
38 import java.util.Arrays;
39 import java.util.Date;
40 import java.util.HashSet;
41 import java.util.Locale;
42 import java.util.Random;
43 import java.util.Set;
44 import java.util.TimeZone;
45 import jdk.test.lib.RandomFactory;
46
47 import org.testng.annotations.DataProvider;
48 import org.testng.annotations.Test;
49
50 /*
51 * @test
52 * @bug 8081022 8151876 8166875 8189784
53 * @key randomness
54 */
55
56 /**
57 * Test ZoneTextPrinterParser
58 */
59 @Test
60 public class TestZoneTextPrinterParser extends AbstractTestPrinterParser {
61
62 protected static DateTimeFormatter getFormatter(Locale locale, TextStyle style) {
63 return new DateTimeFormatterBuilder().appendZoneText(style)
64 .toFormatter(locale)
65 .withDecimalStyle(DecimalStyle.of(locale));
66 }
67
68 public void test_printText() {
69 Random r = RandomFactory.getRandom();
70 int N = 8;
71 Locale[] locales = Locale.getAvailableLocales();
72 Set<String> zids = ZoneRulesProvider.getAvailableZoneIds();
141 ZoneId.of("Asia/Shanghai"),
142 }));
143
144 private static Set<ZoneId> none = new HashSet<>();
145
146 @DataProvider(name="preferredZones")
147 Object[][] data_preferredZones() {
148 return new Object[][] {
149 {"America/New_York", "Eastern Standard Time", none, Locale.ENGLISH, TextStyle.FULL},
150 // {"EST", "Eastern Standard Time", preferred, Locale.ENGLISH, TextStyle.FULL},
151 {"Europe/Paris", "Central European Time", none, Locale.ENGLISH, TextStyle.FULL},
152 // {"CET", "Central European Time", preferred, Locale.ENGLISH, TextStyle.FULL}, no three-letter ID in CLDR
153 {"Asia/Shanghai", "China Standard Time", none, Locale.ENGLISH, TextStyle.FULL},
154 {"Asia/Macau", "China Standard Time", preferred, Locale.ENGLISH, TextStyle.FULL},
155 {"Asia/Taipei", "Taipei Standard Time", preferred, Locale.ENGLISH, TextStyle.FULL},
156 {"America/Chicago", "CST", none, Locale.ENGLISH, TextStyle.SHORT},
157 {"Asia/Taipei", "CST", preferred, Locale.ENGLISH, TextStyle.SHORT},
158 {"Australia/South", "ACST", preferred_s, Locale.ENGLISH, TextStyle.SHORT},
159 {"America/Chicago", "CDT", none, Locale.ENGLISH, TextStyle.SHORT},
160 {"Asia/Shanghai", "CDT", preferred_s, Locale.ENGLISH, TextStyle.SHORT},
161 {"America/Juneau", "AKST", none, Locale.ENGLISH, TextStyle.SHORT},
162 {"America/Juneau", "AKDT", none, Locale.ENGLISH, TextStyle.SHORT},
163 {"Pacific/Honolulu", "HST", none, Locale.ENGLISH, TextStyle.SHORT},
164 {"America/Halifax", "AST", none, Locale.ENGLISH, TextStyle.SHORT},
165 };
166 }
167
168 @Test(dataProvider="preferredZones")
169 public void test_ParseText(String expected, String text, Set<ZoneId> preferred, Locale locale, TextStyle style) {
170 DateTimeFormatter fmt = new DateTimeFormatterBuilder().appendZoneText(style, preferred)
171 .toFormatter(locale)
172 .withDecimalStyle(DecimalStyle.of(locale));
173
174 String ret = fmt.parse(text, TemporalQueries.zone()).getId();
175
176 System.out.printf("[%-5s %s] %24s -> %s(%s)%n",
177 locale.toString(),
178 style == TextStyle.FULL ? " full" :"short",
179 text, ret, expected);
180
181 assertEquals(ret, expected);
182
183 }
184
|