< prev index next >

test/java/util/Calendar/NarrowNamesTest.java

Print this page


   1 /*
   2  * Copyright (c) 2012, 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 import java.util.*;
  25 import static java.util.GregorianCalendar.*;
  26 
  27 public class NarrowNamesTest {
  28     private static final Locale US = Locale.US;
  29     private static final Locale JAJPJP = new Locale("ja", "JP", "JP");
  30     private static final Locale THTH = new Locale("th", "TH");
  31 
  32     private static final String RESET_INDEX = "RESET_INDEX";
  33 
  34     private static int errors = 0;
  35 
  36     // This test is locale data-dependent.
  37     public static void main(String[] args) {
  38         test(US, ERA, "B",
  39              ERA, BC, YEAR, 1);
  40         test(US, ERA, "A",
  41              ERA, AD, YEAR, 2012);
  42         test(US, DAY_OF_WEEK, "S",
  43              YEAR, 2012, MONTH, DECEMBER, DAY_OF_MONTH, 23);
  44         test(US, AM_PM, "a",
  45              HOUR_OF_DAY, 10);
  46         test(US, AM_PM, "p",
  47              HOUR_OF_DAY, 23);
  48         test(JAJPJP, DAY_OF_WEEK, "\u65e5",


  49              YEAR, 24, MONTH, DECEMBER, DAY_OF_MONTH, 23);
  50         test(THTH, MONTH, NARROW_STANDALONE, "\u0e18.\u0e04.",
  51              YEAR, 2555, MONTH, DECEMBER, DAY_OF_MONTH, 5);
  52         test(THTH, DAY_OF_WEEK, "\u0e1e",
  53              YEAR, 2555, MONTH, DECEMBER, DAY_OF_MONTH, 5);
  54 
  55         testMap(US, DAY_OF_WEEK, ALL_STYLES, // shouldn't include any narrow names
  56                 "", // 1-based indexing for DAY_OF_WEEK
  57                 "Sunday",    // Sunday
  58                 "Monday",    // Monday
  59                 "Tuesday",   // Tuesday
  60                 "Wednesday", // Wednesday
  61                 "Thursday",  // Thursday
  62                 "Friday",    // Friday
  63                 "Saturday",  // Saturday
  64                 RESET_INDEX,
  65                 "", // 1-based indexing for DAY_OF_WEEK
  66                 "Sun",       // abb Sunday
  67                 "Mon",       // abb Monday
  68                 "Tue",       // abb Tuesday


   1 /*
   2  * Copyright (c) 2012, 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 import java.time.LocalDateTime;
  25 import java.util.*;
  26 import static java.util.GregorianCalendar.*;
  27 
  28 public class NarrowNamesTest {
  29     private static final Locale US = Locale.US;
  30     private static final Locale JAJPJP = new Locale("ja", "JP", "JP");
  31     private static final Locale THTH = new Locale("th", "TH");
  32 
  33     private static final String RESET_INDEX = "RESET_INDEX";
  34 
  35     private static int errors = 0;
  36 
  37     // This test is locale data-dependent.
  38     public static void main(String[] args) {
  39         test(US, ERA, "B",
  40              ERA, BC, YEAR, 1);
  41         test(US, ERA, "A",
  42              ERA, AD, YEAR, 2012);
  43         test(US, DAY_OF_WEEK, "S",
  44              YEAR, 2012, MONTH, DECEMBER, DAY_OF_MONTH, 23);
  45         test(US, AM_PM, "a",
  46              HOUR_OF_DAY, 10);
  47         test(US, AM_PM, "p",
  48              HOUR_OF_DAY, 23);
  49         test(JAJPJP, DAY_OF_WEEK,
  50              LocalDateTime.now().isBefore(LocalDateTime.of(2019, 5, 1, 0, 0)) ?
  51                 "\u65e5" : "\u706b", // "Sun" for HEISEI, "Tue" for NEWERA
  52              YEAR, 24, MONTH, DECEMBER, DAY_OF_MONTH, 23);
  53         test(THTH, MONTH, NARROW_STANDALONE, "\u0e18.\u0e04.",
  54              YEAR, 2555, MONTH, DECEMBER, DAY_OF_MONTH, 5);
  55         test(THTH, DAY_OF_WEEK, "\u0e1e",
  56              YEAR, 2555, MONTH, DECEMBER, DAY_OF_MONTH, 5);
  57 
  58         testMap(US, DAY_OF_WEEK, ALL_STYLES, // shouldn't include any narrow names
  59                 "", // 1-based indexing for DAY_OF_WEEK
  60                 "Sunday",    // Sunday
  61                 "Monday",    // Monday
  62                 "Tuesday",   // Tuesday
  63                 "Wednesday", // Wednesday
  64                 "Thursday",  // Thursday
  65                 "Friday",    // Friday
  66                 "Saturday",  // Saturday
  67                 RESET_INDEX,
  68                 "", // 1-based indexing for DAY_OF_WEEK
  69                 "Sun",       // abb Sunday
  70                 "Mon",       // abb Monday
  71                 "Tue",       // abb Tuesday


< prev index next >