1 /*
2 * Copyright (c) 1997, 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 4052223 4089987 4469904 4326988 4486735 8008577 8045998 8140571
27 * @summary test DateFormat and SimpleDateFormat.
28 * @library /java/text/testlib
29 * @modules jdk.localedata
30 * @run main/othervm -Djava.locale.providers=COMPAT,SPI DateFormatTest
31 */
32
33 import java.util.*;
34 import java.text.*;
35 import static java.util.GregorianCalendar.*;
36
37 public class DateFormatTest extends IntlTest
38 {
39 public static void main(String[] args) throws Exception {
40 Locale reservedLocale = Locale.getDefault();
41 try {
42 Locale.setDefault(Locale.US);
43 new DateFormatTest().run(args);
44 } finally {
45 // restore the reserved locale
46 Locale.setDefault(reservedLocale);
1188 "00000000000000000000000000000000000000000000000000" +
1189 "00000000000000000000000000000000000000000000002001\u5e74";
1190 SimpleDateFormat sdf = new SimpleDateFormat(pat);
1191 String s = sdf.format(new Date(2001-1900, Calendar.JANUARY, 1));
1192 if (!expected.equals(s)) {
1193 errln("wrong format result: expected="+expected+", got="+s);
1194 }
1195 Date longday = sdf.parse(s);
1196 GregorianCalendar cal = new GregorianCalendar();
1197 cal.setTime(longday);
1198 if (cal.get(YEAR) != 2001) {
1199 errln("wrong parse result: expected=2001, got=" + cal.get(YEAR));
1200 }
1201 } catch (Exception e) {
1202 throw e;
1203 } finally {
1204 // Restore the initial time zone
1205 TimeZone.setDefault(initialTimeZone);
1206 }
1207 }
1208 }
|
1 /*
2 * Copyright (c) 1997, 2019, 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 4052223 4089987 4469904 4326988 4486735 8008577 8045998 8140571
27 * 8216969
28 * @summary test DateFormat and SimpleDateFormat.
29 * @library /java/text/testlib
30 * @modules jdk.localedata
31 * @run main/othervm -Djava.locale.providers=COMPAT,SPI DateFormatTest
32 */
33
34 import java.util.*;
35 import java.text.*;
36 import static java.util.GregorianCalendar.*;
37
38 public class DateFormatTest extends IntlTest
39 {
40 public static void main(String[] args) throws Exception {
41 Locale reservedLocale = Locale.getDefault();
42 try {
43 Locale.setDefault(Locale.US);
44 new DateFormatTest().run(args);
45 } finally {
46 // restore the reserved locale
47 Locale.setDefault(reservedLocale);
1189 "00000000000000000000000000000000000000000000000000" +
1190 "00000000000000000000000000000000000000000000002001\u5e74";
1191 SimpleDateFormat sdf = new SimpleDateFormat(pat);
1192 String s = sdf.format(new Date(2001-1900, Calendar.JANUARY, 1));
1193 if (!expected.equals(s)) {
1194 errln("wrong format result: expected="+expected+", got="+s);
1195 }
1196 Date longday = sdf.parse(s);
1197 GregorianCalendar cal = new GregorianCalendar();
1198 cal.setTime(longday);
1199 if (cal.get(YEAR) != 2001) {
1200 errln("wrong parse result: expected=2001, got=" + cal.get(YEAR));
1201 }
1202 } catch (Exception e) {
1203 throw e;
1204 } finally {
1205 // Restore the initial time zone
1206 TimeZone.setDefault(initialTimeZone);
1207 }
1208 }
1209
1210 public void Test8216969() throws Exception {
1211 Locale locale = new Locale("ru");
1212 String format = "\u0434\u0435\u043a";
1213 String standalone = "\u0434\u0435\u043a.";
1214
1215 // Check that format form is used so that the dot is parsed correctly.
1216 SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMM.yyyy", locale);
1217 System.out.println(simpleDateFormat.parse("28 " + format + ".2018"));
1218
1219 // Check that standalone form is used.
1220 simpleDateFormat = new SimpleDateFormat("MMM", locale);
1221 System.out.println(simpleDateFormat.parse(standalone));
1222 }
1223 }
|