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 8134250 8134520 27 * @summary Tests CLDR/LDML features are correctly reflected in JDK. 28 * @run main/othervm -Djava.locale.providers=CLDR Bug8134250 29 */ 30 31 // Note this test highly depends on a particular version of CLDR. Results 32 // may vary in the future. 33 34 import java.time.*; 35 import java.time.chrono.*; 36 import java.time.format.*; 37 import java.util.*; 38 39 public class Bug8134250 { 40 public static void main(String [] args) { 41 LocalDate d = LocalDate.of(1980, Month.JANUARY, 1); 42 43 // en-GB inherits from en-001 where its short tz name for 44 // America/Los_Angeles is "non-inheritance marker". Thus the 45 // resulting formatted text should be a custom ID. 46 DateTimeFormatterBuilder dtfb = new DateTimeFormatterBuilder(); 47 dtfb.appendZoneText(TextStyle.SHORT); 48 DateTimeFormatter dtf = dtfb.toFormatter(Locale.UK) 49 .withZone(ZoneId.of("America/Los_Angeles")); 50 String result = dtf.format(d); 51 System.out.println(result); 52 if (!"GMT-08:00".equals(result)) { 53 throw new RuntimeException("short time zone name for America/Los_Angeles in en_GB is incorrect. Got: " + result + ", expected: GMT-08:00"); 54 } 55 56 // Islamic Um-Alqura calendar is an alias to Islamic calendar. 57 // In Islamic calendar data, only month names are localized, also 58 // date/time format for FULL style should be inherited from "generic" 59 // calendar, where it includes ERA field. 60 Locale locale = Locale.forLanguageTag("en-US-u-ca-islamic-umalqura"); 61 Chronology chrono = Chronology.ofLocale(locale); 62 dtf = DateTimeFormatter 63 .ofLocalizedDate(FormatStyle.FULL) 64 .withLocale(locale) 65 .withChronology(chrono); 66 result = dtf.format(d); 67 System.out.println(dtf.format(d)); 68 if (!"Tuesday, Safar 12, 1400 AH".equals(result)) { 69 throw new RuntimeException("FULL date format of Islamic Um-Alqura calendar in en_US is incorrect. Got: " + result + ", expected: Tuesday, Safar 12, 1400 AH"); 70 } 71 } 72 }