< prev index next >

test/jdk/java/util/TimeZone/CLDRDisplayNamesTest.java

Print this page


   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  */


  56         {
  57             "zh-CN",
  58             "\u5317\u7f8e\u592a\u5e73\u6d0b\u6807\u51c6\u65f6\u95f4",
  59             "GMT-08:00",
  60             "\u5317\u7f8e\u592a\u5e73\u6d0b\u590f\u4ee4\u65f6\u95f4",
  61             "GMT-07:00",
  62             //"\u5317\u7f8e\u592a\u5e73\u6d0b\u65f6\u95f4",
  63         //"PT",
  64         },
  65         {
  66             "de-DE",
  67             "Nordamerikanische Westk\u00fcsten-Normalzeit",
  68             "GMT-08:00",
  69             "Nordamerikanische Westk\u00fcsten-Sommerzeit",
  70             "GMT-07:00",
  71             //"Nordamerikanische Westk\u00fcstenzeit",
  72         //"PT",
  73         },
  74     };
  75 


  76     public static void main(String[] args) {
  77         // Make sure that localized time zone names of CLDR are used
  78         // if specified.
  79         TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
  80         int errors = 0;
  81         for (String[] data : CLDR_DATA) {
  82             Locale locale = Locale.forLanguageTag(data[0]);
  83             for (int i = 1; i < data.length; i++) {
  84                 int style = ((i % 2) == 1) ? LONG : SHORT;
  85                 boolean daylight = (i == 3 || i == 4);
  86                 String name = tz.getDisplayName(daylight, style, locale);
  87                 if (!data[i].equals(name)) {
  88                     System.err.printf("error: got '%s' expected '%s' (style=%d, daylight=%s, locale=%s)%n",
  89                             name, data[i], style, daylight, locale);
  90                     errors++;
  91                 }
  92             }
  93         }
  94 
  95         // for 8129881


 114             System.err.println(pe);
 115             errors++;
 116         } finally {
 117             Locale.setDefault(originalLocale);
 118         }
 119 
 120         // for 8210490
 121         // Check that TimeZone.getDisplayName should honor passed locale parameter,
 122         // even if default locale is set to some other locale.
 123         Locale.setDefault(Locale.forLanguageTag("ar-PK"));
 124         TimeZone zi = TimeZone.getTimeZone("Etc/GMT-5");
 125         String displayName = zi.getDisplayName(false, TimeZone.SHORT, Locale.US);
 126         Locale.setDefault(originalLocale);
 127         if (!displayName.equals("GMT+05:00")) {
 128             System.err.printf("Wrong display name for timezone Etc/GMT-5 : expected GMT+05:00,  Actual " + displayName);
 129             errors++;
 130         }
 131         if (errors > 0) {
 132             throw new RuntimeException("test failed");
 133         }






















 134     }
 135 }
   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  */


  56         {
  57             "zh-CN",
  58             "\u5317\u7f8e\u592a\u5e73\u6d0b\u6807\u51c6\u65f6\u95f4",
  59             "GMT-08:00",
  60             "\u5317\u7f8e\u592a\u5e73\u6d0b\u590f\u4ee4\u65f6\u95f4",
  61             "GMT-07:00",
  62             //"\u5317\u7f8e\u592a\u5e73\u6d0b\u65f6\u95f4",
  63         //"PT",
  64         },
  65         {
  66             "de-DE",
  67             "Nordamerikanische Westk\u00fcsten-Normalzeit",
  68             "GMT-08:00",
  69             "Nordamerikanische Westk\u00fcsten-Sommerzeit",
  70             "GMT-07:00",
  71             //"Nordamerikanische Westk\u00fcstenzeit",
  72         //"PT",
  73         },
  74     };
  75 
  76     private static final String NO_INHERITANCE_MARKER = "\u2205\u2205\u2205";
  77 
  78     public static void main(String[] args) {
  79         // Make sure that localized time zone names of CLDR are used
  80         // if specified.
  81         TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
  82         int errors = 0;
  83         for (String[] data : CLDR_DATA) {
  84             Locale locale = Locale.forLanguageTag(data[0]);
  85             for (int i = 1; i < data.length; i++) {
  86                 int style = ((i % 2) == 1) ? LONG : SHORT;
  87                 boolean daylight = (i == 3 || i == 4);
  88                 String name = tz.getDisplayName(daylight, style, locale);
  89                 if (!data[i].equals(name)) {
  90                     System.err.printf("error: got '%s' expected '%s' (style=%d, daylight=%s, locale=%s)%n",
  91                             name, data[i], style, daylight, locale);
  92                     errors++;
  93                 }
  94             }
  95         }
  96 
  97         // for 8129881


 116             System.err.println(pe);
 117             errors++;
 118         } finally {
 119             Locale.setDefault(originalLocale);
 120         }
 121 
 122         // for 8210490
 123         // Check that TimeZone.getDisplayName should honor passed locale parameter,
 124         // even if default locale is set to some other locale.
 125         Locale.setDefault(Locale.forLanguageTag("ar-PK"));
 126         TimeZone zi = TimeZone.getTimeZone("Etc/GMT-5");
 127         String displayName = zi.getDisplayName(false, TimeZone.SHORT, Locale.US);
 128         Locale.setDefault(originalLocale);
 129         if (!displayName.equals("GMT+05:00")) {
 130             System.err.printf("Wrong display name for timezone Etc/GMT-5 : expected GMT+05:00,  Actual " + displayName);
 131             errors++;
 132         }
 133         if (errors > 0) {
 134             throw new RuntimeException("test failed");
 135         }
 136 
 137         // 8217366: No "no inheritance marker" should be left in the returned array
 138         // from DateFormatSymbols.getZoneStrings()
 139         List.of(Locale.ROOT,
 140                 Locale.CHINA,
 141                 Locale.GERMANY,
 142                 Locale.JAPAN,
 143                 Locale.UK,
 144                 Locale.US,
 145                 Locale.forLanguageTag("hi-IN"),
 146                 Locale.forLanguageTag("es-419")).stream()
 147             .peek(System.out::println)
 148             .map(l -> DateFormatSymbols.getInstance(l).getZoneStrings())
 149             .flatMap(zoneStrings -> Arrays.stream(zoneStrings))
 150             .filter(namesArray -> Arrays.stream(namesArray)
 151                 .anyMatch(aName -> aName.equals(NO_INHERITANCE_MARKER)))
 152             .findAny()
 153             .ifPresentOrElse(marker -> {
 154                     throw new RuntimeException("No inheritance marker detected with tzid: "
 155                                                 + marker[0]);
 156                 },
 157                 () -> System.out.println("Success: No \"no inheritance marker\" detected."));
 158     }
 159 }
< prev index next >