1 /* 2 * Copyright (c) 2008, 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 6683975 27 * @summary Make sure that date is formatted correctlyin th locale. 28 */ 29 import java.text.*; 30 import java.util.*; 31 32 public class Bug6683975 { 33 34 private static boolean err = false; 35 36 private static Locale th = new Locale("th", ""); 37 private static Locale th_TH = new Locale("th", "TH"); 38 private static String expected_th[] = { 39 "\u0e27\u0e31\u0e19\u0e2d\u0e31\u0e07\u0e04\u0e32\u0e23\u0e17\u0e35\u0e48 30 \u0e01\u0e31\u0e19\u0e22\u0e32\u0e22\u0e19 \u0e04.\u0e28. 2008, 8 \u0e19\u0e32\u0e2c\u0e34\u0e01\u0e32 0 \u0e19\u0e32\u0e17\u0e35 00 \u0e27\u0e34\u0e19\u0e32\u0e17\u0e35", // 0: FULL 40 "30 \u0e01\u0e31\u0e19\u0e22\u0e32\u0e22\u0e19 2008, 8 \u0e19\u0e32\u0e2c\u0e34\u0e01\u0e32 0 \u0e19\u0e32\u0e17\u0e35", // 1: LONG 41 "30 \u0e01.\u0e22. 2008, 8:00:00", // 2: MEDIUM 42 "30/9/2008, 8:00 \u0e19.", // 3: SHORT 43 }; 44 private static String expected_th_TH[] = { 45 "\u0e27\u0e31\u0e19\u0e2d\u0e31\u0e07\u0e04\u0e32\u0e23\u0e17\u0e35\u0e48 30 \u0e01\u0e31\u0e19\u0e22\u0e32\u0e22\u0e19 \u0e1e.\u0e28. 2551, 8 \u0e19\u0e32\u0e2c\u0e34\u0e01\u0e32 0 \u0e19\u0e32\u0e17\u0e35 00 \u0e27\u0e34\u0e19\u0e32\u0e17\u0e35", // 0: FULL 46 "30 \u0e01\u0e31\u0e19\u0e22\u0e32\u0e22\u0e19 2551, 8 \u0e19\u0e32\u0e2c\u0e34\u0e01\u0e32 0 \u0e19\u0e32\u0e17\u0e35", // 1: LONG 47 "30 \u0e01.\u0e22. 2551, 8:00:00", // 2: MEDIUM 48 "30/9/2551, 8:00 \u0e19." // 3: SHORT 49 }; 50 private static String stylePattern[] = { 51 "FULL", "LONG", "MEDIUM", "SHORT" 52 }; 53 54 private static void test(int style) { 55 DateFormat df_th = DateFormat.getDateTimeInstance(style, style, th); 56 DateFormat df_th_TH = DateFormat.getDateTimeInstance(style, style, th_TH); 57 58 String str_th = ((SimpleDateFormat)df_th).toPattern(); 59 String str_th_TH = ((SimpleDateFormat)df_th_TH).toPattern(); 60 if (!str_th.equals(str_th_TH)) { 61 err = true; 62 System.err.println("Error: Pattern for th locale should be the same as pattern for th_TH locale. (" + stylePattern[style] + ")"); 63 System.err.println("\tth: " + str_th); 64 System.err.println("\tth_TH: " + str_th_TH); 65 } 66 67 Date date = new Date(2008-1900, Calendar.SEPTEMBER, 30, 8, 0, 0); 68 str_th = df_th.format(date); 69 if (!expected_th[style].equals(str_th)) { 70 err = true; 71 System.err.println("Error: Formatted date in th locale is incorrect in " + stylePattern[style] + " pattern."); 72 System.err.println("\tExpected: " + expected_th[style]); 73 System.err.println("\tGot: " + str_th); 74 } 75 76 str_th_TH = df_th_TH.format(date); 77 if (!expected_th_TH[style].equals(str_th_TH)) { 78 err = true; 79 System.err.println("Error: Formatted date in th_TH locale is incorrect in " + stylePattern[style] + " pattern."); 80 System.err.println("\tExpected: " + expected_th_TH[style]); 81 System.err.println("\tGot: " + str_th_TH); 82 } 83 } 84 85 public static void main(String[] args) { 86 TimeZone timezone = TimeZone.getDefault(); 87 Locale locale = Locale.getDefault(); 88 89 TimeZone.setDefault(TimeZone.getTimeZone("US/Pacific")); 90 Locale.setDefault(Locale.US); 91 92 try { 93 test(DateFormat.FULL); 94 test(DateFormat.LONG); 95 test(DateFormat.MEDIUM); 96 test(DateFormat.SHORT); 97 } 98 catch (Exception e) { 99 err = true; 100 System.err.println("Unexpected exception was thrown: " + e); 101 } 102 finally { 103 TimeZone.setDefault(timezone); 104 Locale.setDefault(locale); 105 106 if (err) { 107 throw new RuntimeException("Failed."); 108 } else { 109 System.out.println("Passed."); 110 } 111 } 112 } 113 114 }