1 /*
   2  * Copyright (c) 2015, 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 8134384
  27  * @summary Tests CLDR TimeZoneNames has English names for all tzids
  28  * @run main/othervm -Djava.locale.providers=CLDR Bug8134384
  29  */
  30 
  31 import java.text.*;
  32 import java.time.*;
  33 import java.util.*;
  34 
  35 public class Bug8134384 {
  36     public static void main(String [] args) {
  37         TimeZone original = TimeZone.getDefault();
  38 
  39         try {
  40             for (String tz : TimeZone.getAvailableIDs() ) {
  41                 TimeZone.setDefault(TimeZone.getTimeZone(tz));
  42                 // Summer solstice
  43                 String date1 = Date.from(Instant.parse("2015-06-21T00:00:00.00Z")).toString();
  44                 testParse(Locale.ENGLISH, date1, tz);
  45                 testParse(Locale.US, date1, tz);
  46                 testParse(Locale.ROOT, date1, tz);
  47                 // Winter solstice
  48                 String date2 = Date.from(Instant.parse("2015-12-22T00:00:00.00Z")).toString();
  49                 testParse(Locale.ENGLISH, date2, tz);
  50                 testParse(Locale.US, date2, tz);
  51                 testParse(Locale.ROOT, date2, tz);
  52             }
  53         } finally {
  54             TimeZone.setDefault(original);
  55         }
  56     }
  57 
  58     private static void testParse(Locale locale, String date, String tz) {
  59         try {
  60             new SimpleDateFormat("EEE MMM d hh:mm:ss z yyyy", locale).parse(date);
  61             System.out.println(String.format(Locale.ENGLISH, "OK parsing '%s' in locale '%s', tz: %s", date, locale, tz));
  62         } catch (ParseException pe) {
  63             throw new RuntimeException(String.format(Locale.ENGLISH, "ERROR parsing '%s' in locale '%s', tz: %s: %s", date, locale, tz, pe.toString()));
  64         }
  65     }
  66 }