/* ******************************************************************************* * Copyright (C) 2000-2010, International Business Machines Corporation and * others. All Rights Reserved. ******************************************************************************* */ package com.ibm.icu.dev.test.calendar; import java.text.ParseException; import java.util.Date; import java.util.Locale; import com.ibm.icu.impl.CalendarAstronomer; import com.ibm.icu.impl.LocaleUtility; import com.ibm.icu.impl.ZoneMeta; import com.ibm.icu.text.DateFormat; import com.ibm.icu.text.SimpleDateFormat; import com.ibm.icu.util.BuddhistCalendar; import com.ibm.icu.util.Calendar; import com.ibm.icu.util.ChineseCalendar; import com.ibm.icu.util.GregorianCalendar; import com.ibm.icu.util.JapaneseCalendar; import com.ibm.icu.util.TaiwanCalendar; import com.ibm.icu.util.TimeZone; import com.ibm.icu.util.ULocale; /** * @summary Tests of new functionality in IBMCalendar */ public class IBMCalendarTest extends CalendarTest { public static void main(String[] args) throws Exception { new IBMCalendarTest().run(args); } /** * Test weekend support in IBMCalendar. * * NOTE: This test will have to be updated when the isWeekend() etc. * API is finalized later. * * In particular, the test will have to be rewritten to instantiate * a Calendar in the given locale (using getInstance()) and call * that Calendar's isWeekend() etc. methods. */ public void TestWeekend() { SimpleDateFormat fmt = new SimpleDateFormat("EEE MMM dd yyyy G HH:mm:ss.SSS"); // NOTE // This test tests for specific locale data. This is probably okay // as far as US data is concerned, but if the Arabic/Yemen data // changes, this test will have to be updated. // Test specific days Object[] DATA1 = { Locale.US, new int[] { // Saturday:Sunday 2000, Calendar.MARCH, 17, 23, 0, 0, // Fri 23:00 2000, Calendar.MARCH, 18, 0, -1, 0, // Fri 23:59:59.999 2000, Calendar.MARCH, 18, 0, 0, 1, // Sat 00:00 2000, Calendar.MARCH, 18, 15, 0, 1, // Sat 15:00 2000, Calendar.MARCH, 19, 23, 0, 1, // Sun 23:00 2000, Calendar.MARCH, 20, 0, -1, 1, // Sun 23:59:59.999 2000, Calendar.MARCH, 20, 0, 0, 0, // Mon 00:00 2000, Calendar.MARCH, 20, 8, 0, 0, // Mon 08:00 }, new Locale("ar", "YE"), new int[] { // Thursday:Friday 2000, Calendar.MARCH, 15, 23, 0, 0, // Wed 23:00 2000, Calendar.MARCH, 16, 0, -1, 0, // Wed 23:59:59.999 2000, Calendar.MARCH, 16, 0, 0, 1, // Thu 00:00 2000, Calendar.MARCH, 16, 15, 0, 1, // Thu 15:00 2000, Calendar.MARCH, 17, 23, 0, 1, // Fri 23:00 2000, Calendar.MARCH, 18, 0, -1, 1, // Fri 23:59:59.999 2000, Calendar.MARCH, 18, 0, 0, 0, // Sat 00:00 2000, Calendar.MARCH, 18, 8, 0, 0, // Sat 08:00 }, }; // Test days of the week Object[] DATA2 = { Locale.US, new int[] { Calendar.MONDAY, Calendar.WEEKDAY, Calendar.FRIDAY, Calendar.WEEKDAY, Calendar.SATURDAY, Calendar.WEEKEND, Calendar.SUNDAY, Calendar.WEEKEND_CEASE, }, new Locale("ar", "YE"), new int[] { // Thursday:Friday Calendar.WEDNESDAY,Calendar.WEEKDAY, Calendar.SATURDAY, Calendar.WEEKDAY, Calendar.THURSDAY, Calendar.WEEKEND, Calendar.FRIDAY, Calendar.WEEKEND_CEASE, }, }; // We only test the getDayOfWeekType() and isWeekend() APIs. // The getWeekendTransition() API is tested indirectly via the // isWeekend() API, which calls it. for (int i1=0; i1 " + d); } else { errln("Fail: " + era + ":" + year + "/" + (month+1) + "/" + dayOfMonth + " => " + d + ", expected " + D); } cal.clear(); cal.setTime(D); int e = cal.get(Calendar.ERA); int y = cal.get(Calendar.YEAR); if (y == year && e == era) { logln("OK: " + D + " => " + cal.get(Calendar.ERA) + ":" + cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH)+1) + "/" + cal.get(Calendar.DATE)); } else { logln("Fail: " + D + " => " + cal.get(Calendar.ERA) + ":" + cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH)+1) + "/" + cal.get(Calendar.DATE) + ", expected " + era + ":" + year + "/" + (month+1) + "/" + dayOfMonth); } } } /** * Verify that BuddhistCalendar shifts years to Buddhist Era but otherwise * behaves like GregorianCalendar. */ public void TestBuddhist() { quasiGregorianTest(new BuddhistCalendar(), new int[] { // BE 2542 == 1999 CE 0, 2542, 1999, Calendar.JUNE, 4 }); } public void TestBuddhistCoverage() { { // new BuddhistCalendar(ULocale) BuddhistCalendar cal = new BuddhistCalendar(ULocale.getDefault()); if(cal == null){ errln("could not create BuddhistCalendar with ULocale"); } } { // new BuddhistCalendar(TimeZone,ULocale) BuddhistCalendar cal = new BuddhistCalendar(TimeZone.getDefault(),ULocale.getDefault()); if(cal == null){ errln("could not create BuddhistCalendar with TimeZone ULocale"); } } { // new BuddhistCalendar(TimeZone) BuddhistCalendar cal = new BuddhistCalendar(TimeZone.getDefault()); if(cal == null){ errln("could not create BuddhistCalendar with TimeZone"); } } { // new BuddhistCalendar(Locale) BuddhistCalendar cal = new BuddhistCalendar(Locale.getDefault()); if(cal == null){ errln("could not create BuddhistCalendar with Locale"); } } { // new BuddhistCalendar(TimeZone, Locale) BuddhistCalendar cal = new BuddhistCalendar(TimeZone.getDefault(), Locale.getDefault()); if(cal == null){ errln("could not create BuddhistCalendar with TimeZone and Locale"); } } { // new BuddhistCalendar(Date) BuddhistCalendar cal = new BuddhistCalendar(new Date()); if(cal == null){ errln("could not create BuddhistCalendar with Date"); } } { // new BuddhistCalendar(int year, int month, int date) BuddhistCalendar cal = new BuddhistCalendar(2543, Calendar.MAY, 22); if(cal == null){ errln("could not create BuddhistCalendar with year,month,data"); } } { // new BuddhistCalendar(int year, int month, int date, int hour, int minute, int second) BuddhistCalendar cal = new BuddhistCalendar(2543, Calendar.MAY, 22, 1, 1, 1); if(cal == null){ errln("could not create BuddhistCalendar with year,month,date,hour,minute,second"); } } { // data BuddhistCalendar cal = new BuddhistCalendar(2543, Calendar.MAY, 22); Date time = cal.getTime(); String[] calendarLocales = { "th_TH" }; String[] formatLocales = { "en", "ar", "hu", "th" }; for (int i = 0; i < calendarLocales.length; ++i) { String calLocName = calendarLocales[i]; Locale calLocale = LocaleUtility.getLocaleFromName(calLocName); cal = new BuddhistCalendar(calLocale); for (int j = 0; j < formatLocales.length; ++j) { String locName = formatLocales[j]; Locale formatLocale = LocaleUtility.getLocaleFromName(locName); DateFormat format = DateFormat.getDateTimeInstance(cal, DateFormat.FULL, DateFormat.FULL, formatLocale); logln(calLocName + "/" + locName + " --> " + format.format(time)); } } } } /** * Test limits of the Buddhist calendar. */ public void TestBuddhistLimits() { // Final parameter is either number of days, if > 0, or test // duration in seconds, if < 0. Calendar cal = Calendar.getInstance(); cal.set(2007, Calendar.JANUARY, 1); BuddhistCalendar buddhist = new BuddhistCalendar(); doLimitsTest(buddhist, null, cal.getTime()); doTheoreticalLimitsTest(buddhist, false); } /** * Default calendar for Thai (Ticket#6302) */ public void TestThaiDefault() { // Buddhist calendar is used as the default calendar for // Thai locale Calendar cal = Calendar.getInstance(new ULocale("th_TH")); String type = cal.getType(); if (!type.equals("buddhist")) { errln("FAIL: Buddhist calendar is not returned for locale " + cal.toString()); } } /** * Verify that TaiwanCalendar shifts years to Minguo Era but otherwise * behaves like GregorianCalendar. */ public void TestTaiwan() { quasiGregorianTest(new TaiwanCalendar(), new int[] { TaiwanCalendar.BEFORE_MINGUO, 8, 1904, Calendar.FEBRUARY, 29, TaiwanCalendar.MINGUO, 1, 1912, Calendar.JUNE, 4, TaiwanCalendar.MINGUO, 3, 1914, Calendar.FEBRUARY, 12, TaiwanCalendar.MINGUO, 96,2007, Calendar.FEBRUARY, 12, }); } /** * Test limits of the Taiwan calendar. */ public void TestTaiwanLimits() { // Final parameter is either number of days, if > 0, or test // duration in seconds, if < 0. Calendar cal = Calendar.getInstance(); cal.set(2007, Calendar.JANUARY, 1); TaiwanCalendar taiwan = new TaiwanCalendar(); doLimitsTest(taiwan, null, cal.getTime()); doTheoreticalLimitsTest(taiwan, false); } public void TestTaiwanCoverage() { { // new TaiwanCalendar(ULocale) TaiwanCalendar cal = new TaiwanCalendar(ULocale.getDefault()); if(cal == null){ errln("could not create TaiwanCalendar with ULocale"); } } { // new TaiwanCalendar(TimeZone,ULocale) TaiwanCalendar cal = new TaiwanCalendar(TimeZone.getDefault(),ULocale.getDefault()); if(cal == null){ errln("could not create TaiwanCalendar with TimeZone ULocale"); } } { // new TaiwanCalendar(TimeZone) TaiwanCalendar cal = new TaiwanCalendar(TimeZone.getDefault()); if(cal == null){ errln("could not create TaiwanCalendar with TimeZone"); } } { // new TaiwanCalendar(Locale) TaiwanCalendar cal = new TaiwanCalendar(Locale.getDefault()); if(cal == null){ errln("could not create TaiwanCalendar with Locale"); } } { // new TaiwanCalendar(TimeZone, Locale) TaiwanCalendar cal = new TaiwanCalendar(TimeZone.getDefault(), Locale.getDefault()); if(cal == null){ errln("could not create TaiwanCalendar with TimeZone and Locale"); } } { // new TaiwanCalendar(Date) TaiwanCalendar cal = new TaiwanCalendar(new Date()); if(cal == null){ errln("could not create TaiwanCalendar with Date"); } } { // new TaiwanCalendar(int year, int month, int date) TaiwanCalendar cal = new TaiwanCalendar(34, Calendar.MAY, 22); if(cal == null){ errln("could not create TaiwanCalendar with year,month,data"); } } { // new TaiwanCalendar(int year, int month, int date, int hour, int minute, int second) TaiwanCalendar cal = new TaiwanCalendar(34, Calendar.MAY, 22, 1, 1, 1); if(cal == null){ errln("could not create TaiwanCalendar with year,month,date,hour,minute,second"); } } { // data TaiwanCalendar cal = new TaiwanCalendar(34, Calendar.MAY, 22); Date time = cal.getTime(); String[] calendarLocales = { "en","zh" }; String[] formatLocales = { "en", "ar", "hu", "th" }; for (int i = 0; i < calendarLocales.length; ++i) { String calLocName = calendarLocales[i]; Locale calLocale = LocaleUtility.getLocaleFromName(calLocName); cal = new TaiwanCalendar(calLocale); for (int j = 0; j < formatLocales.length; ++j) { String locName = formatLocales[j]; Locale formatLocale = LocaleUtility.getLocaleFromName(locName); DateFormat format = DateFormat.getDateTimeInstance(cal, DateFormat.FULL, DateFormat.FULL, formatLocale); logln(calLocName + "/" + locName + " --> " + format.format(time)); } } } } /** * Verify that JapaneseCalendar shifts years to Japanese Eras but otherwise * behaves like GregorianCalendar. */ public void TestJapanese() { // First make sure this test works for GregorianCalendar int[] control = { GregorianCalendar.AD, 1868, 1868, Calendar.SEPTEMBER, 8, GregorianCalendar.AD, 1868, 1868, Calendar.SEPTEMBER, 9, GregorianCalendar.AD, 1869, 1869, Calendar.JUNE, 4, GregorianCalendar.AD, 1912, 1912, Calendar.JULY, 29, GregorianCalendar.AD, 1912, 1912, Calendar.JULY, 30, GregorianCalendar.AD, 1912, 1912, Calendar.AUGUST, 1, }; quasiGregorianTest(new GregorianCalendar(), control); int[] data = { JapaneseCalendar.MEIJI, 1, 1868, Calendar.SEPTEMBER, 8, JapaneseCalendar.MEIJI, 1, 1868, Calendar.SEPTEMBER, 9, JapaneseCalendar.MEIJI, 2, 1869, Calendar.JUNE, 4, JapaneseCalendar.MEIJI, 45, 1912, Calendar.JULY, 29, JapaneseCalendar.TAISHO, 1, 1912, Calendar.JULY, 30, JapaneseCalendar.TAISHO, 1, 1912, Calendar.AUGUST, 1, }; quasiGregorianTest(new JapaneseCalendar(), data); } /** * Test limits of the Gregorian calendar. */ public void TestGregorianLimits() { // Final parameter is either number of days, if > 0, or test // duration in seconds, if < 0. Calendar cal = Calendar.getInstance(); cal.set(2004, Calendar.JANUARY, 1); GregorianCalendar gregorian = new GregorianCalendar(); doLimitsTest(gregorian, null, cal.getTime()); doTheoreticalLimitsTest(gregorian, false); } /** * Test behavior of fieldDifference around leap years. Also test a large * field difference to check binary search. */ public void TestLeapFieldDifference() { Calendar cal = Calendar.getInstance(); cal.set(2004, Calendar.FEBRUARY, 29); Date date2004 = cal.getTime(); cal.set(2000, Calendar.FEBRUARY, 29); Date date2000 = cal.getTime(); int y = cal.fieldDifference(date2004, Calendar.YEAR); int d = cal.fieldDifference(date2004, Calendar.DAY_OF_YEAR); if (d == 0) { logln("Ok: 2004/Feb/29 - 2000/Feb/29 = " + y + " years, " + d + " days"); } else { errln("FAIL: 2004/Feb/29 - 2000/Feb/29 = " + y + " years, " + d + " days"); } cal.setTime(date2004); y = cal.fieldDifference(date2000, Calendar.YEAR); d = cal.fieldDifference(date2000, Calendar.DAY_OF_YEAR); if (d == 0) { logln("Ok: 2000/Feb/29 - 2004/Feb/29 = " + y + " years, " + d + " days"); } else { errln("FAIL: 2000/Feb/29 - 2004/Feb/29 = " + y + " years, " + d + " days"); } // Test large difference cal.set(2001, Calendar.APRIL, 5); // 2452005 Date ayl = cal.getTime(); cal.set(1964, Calendar.SEPTEMBER, 7); // 2438646 Date asl = cal.getTime(); d = cal.fieldDifference(ayl, Calendar.DAY_OF_MONTH); cal.setTime(ayl); int d2 = cal.fieldDifference(asl, Calendar.DAY_OF_MONTH); if (d == -d2 && d == 13359) { logln("Ok: large field difference symmetrical " + d); } else { logln("FAIL: large field difference incorrect " + d + ", " + d2 + ", expect +/- 13359"); } } /** * Test ms_MY "Malay (Malaysia)" locale. Bug 1543. */ public void TestMalaysianInstance() { Locale loc = new Locale("ms", "MY"); // Malay (Malaysia) Calendar cal = Calendar.getInstance(loc); if(cal == null){ errln("could not create Malaysian instance"); } } /** * setFirstDayOfWeek and setMinimalDaysInFirstWeek may change the * field <=> time mapping, since they affect the interpretation of * the WEEK_OF_MONTH or WEEK_OF_YEAR fields. */ public void TestWeekShift() { Calendar cal = new GregorianCalendar( TimeZone.getTimeZone("America/Los_Angeles"), new Locale("en", "US")); cal.setTime(new Date(997257600000L)); // Wed Aug 08 01:00:00 PDT 2001 // In pass one, change the first day of week so that the weeks // shift in August 2001. In pass two, change the minimal days // in the first week so that the weeks shift in August 2001. // August 2001 // Su Mo Tu We Th Fr Sa // 1 2 3 4 // 5 6 7 8 9 10 11 // 12 13 14 15 16 17 18 // 19 20 21 22 23 24 25 // 26 27 28 29 30 31 for (int pass=0; pass<2; ++pass) { if (pass==0) { cal.setFirstDayOfWeek(Calendar.WEDNESDAY); cal.setMinimalDaysInFirstWeek(4); } else { cal.setFirstDayOfWeek(Calendar.SUNDAY); cal.setMinimalDaysInFirstWeek(4); } cal.add(Calendar.DATE, 1); // Force recalc cal.add(Calendar.DATE, -1); Date time1 = cal.getTime(); // Get time -- should not change // Now change a week parameter and then force a recalc. // The bug is that the recalc should not be necessary -- // calendar should do so automatically. if (pass==0) { cal.setFirstDayOfWeek(Calendar.THURSDAY); } else { cal.setMinimalDaysInFirstWeek(5); } int woy1 = cal.get(Calendar.WEEK_OF_YEAR); int wom1 = cal.get(Calendar.WEEK_OF_MONTH); cal.add(Calendar.DATE, 1); // Force recalc cal.add(Calendar.DATE, -1); int woy2 = cal.get(Calendar.WEEK_OF_YEAR); int wom2 = cal.get(Calendar.WEEK_OF_MONTH); Date time2 = cal.getTime(); if (!time1.equals(time2)) { errln("FAIL: shifting week should not alter time"); } else { logln(time1.toString()); } if (woy1 == woy2 && wom1 == wom2) { logln("Ok: WEEK_OF_YEAR: " + woy1 + ", WEEK_OF_MONTH: " + wom1); } else { errln("FAIL: WEEK_OF_YEAR: " + woy1 + " => " + woy2 + ", WEEK_OF_MONTH: " + wom1 + " => " + wom2 + " after week shift"); } } } /** * Make sure that when adding a day, we actually wind up in a * different day. The DST adjustments we use to keep the hour * constant across DST changes can backfire and change the day. */ public void TestTimeZoneTransitionAdd() { Locale locale = Locale.US; // could also be CHINA SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm z", locale); String tz[] = TimeZone.getAvailableIDs(); for (int z=0; z 0) { errln(info); } else { logln(info); } } /** * Test the ZoneMeta API. */ public void TestZoneMeta() { // Test index by country API // Format: {country, zone1, zone2, ..., zoneN} String COUNTRY[][] = { {""}, {"US", "America/Los_Angeles", "PST"} }; StringBuffer buf = new StringBuffer(); for (int i=0; i>= 1; // Check bitmask to see if we saw all expected zones if (mask == (1 << (COUNTRY[i].length-1))-1) { logln(buf.toString()); } else { errln(buf.toString()); } } // Test equivalent IDs API int n = ZoneMeta.countEquivalentIDs("PST"); boolean ok = false; buf.setLength(0); buf.append("Equivalent to PST: "); for (int i=0; i= 0) { errln("calendar " + c0 + " not < " + c1); } c0.add(Calendar.MONTH, 1); if (c0.compareTo(c1) <= 0) { errln("calendar " + c0 + " not > " + c1); } c0.setTimeInMillis(c1.getTimeInMillis()); if (c0.compareTo(c1) != 0) { errln("calendar " + c0 + " not == " + c1); } } /** * Miscellaneous tests to increase coverage. */ public void TestCoverage() { // BuddhistCalendar BuddhistCalendar bcal = new BuddhistCalendar(); /*int i =*/ bcal.getMinimum(Calendar.ERA); bcal.add(Calendar.YEAR, 1); bcal.add(Calendar.MONTH, 1); /*Date d = */bcal.getTime(); // CalendarAstronomer // (This class should probably be made package-private.) CalendarAstronomer astro = new CalendarAstronomer(); /*String s = */astro.local(0); // ChineseCalendar ChineseCalendar ccal = new ChineseCalendar(TimeZone.getDefault(), Locale.getDefault()); ccal.add(Calendar.MONTH, 1); ccal.add(Calendar.YEAR, 1); ccal.roll(Calendar.MONTH, 1); ccal.roll(Calendar.YEAR, 1); ccal.getTime(); // ICU 2.6 Calendar cal = Calendar.getInstance(Locale.US); logln(cal.toString()); logln(cal.getDisplayName(Locale.US)); int weekendOnset=-1; int weekendCease=-1; for (int i=Calendar.SUNDAY; i<=Calendar.SATURDAY; ++i) { if (cal.getDayOfWeekType(i) == Calendar.WEEKEND_ONSET) { weekendOnset = i; } if (cal.getDayOfWeekType(i) == Calendar.WEEKEND_CEASE) { weekendCease = i; } } // can't call this unless we get a transition day (unusual), // but make the call anyway for coverage reasons try { /*int x=*/ cal.getWeekendTransition(weekendOnset); /*int x=*/ cal.getWeekendTransition(weekendCease); } catch (IllegalArgumentException e) {} /*int x=*/ cal.isWeekend(new Date()); // new GregorianCalendar(ULocale) GregorianCalendar gcal = new GregorianCalendar(ULocale.getDefault()); if(gcal==null){ errln("could not create GregorianCalendar with ULocale"); } else { logln("Calendar display name: " + gcal.getDisplayName(ULocale.getDefault())); } //cover getAvailableULocales final ULocale[] locales = Calendar.getAvailableULocales(); long count = locales.length; if (count == 0) errln("getAvailableULocales return empty list"); logln("" + count + " available ulocales in Calendar."); // Jitterbug 4451, for coverage class StubCalendar extends Calendar{ /** * For serialization */ private static final long serialVersionUID = -4558903444622684759L; protected int handleGetLimit(int field, int limitType) {return 0;} protected int handleComputeMonthStart(int eyear, int month, boolean useMonth) {return 0;} protected int handleGetExtendedYear() {return 0;} public void run(){ if (Calendar.gregorianPreviousMonthLength(2000,2) != 29){ errln("Year 2000 Feb should have 29 days."); } long millis = Calendar.julianDayToMillis(Calendar.MAX_JULIAN); if(millis != Calendar.MAX_MILLIS){ errln("Did not get the expected value from julianDayToMillis. Got:" + millis); } DateFormat df = handleGetDateFormat("",Locale.getDefault()); if (!df.equals(handleGetDateFormat("",ULocale.getDefault()))){ errln ("Calendar.handleGetDateFormat(String, Locale) should delegate to ( ,ULocale)"); } if (!getType().equals("gregorian")){ errln ("Calendar.getType() should be 'gregorian'"); } } } StubCalendar stub = new StubCalendar(); stub.run(); } // Tests for jb 4541 public void TestJB4541() { ULocale loc = new ULocale("en_US"); // !!! Shouldn't we have an api like this? // !!! Question: should this reflect those actually available in this copy of ICU, or // the list of types we assume is available? // String[] calTypes = Calendar.getAvailableTypes(); final String[] calTypes = { "buddhist", "chinese", "coptic", "ethiopic", "gregorian", "hebrew", "islamic", "islamic-civil", "japanese", "roc" }; // constructing a DateFormat with a locale indicating a calendar type should construct a // date format appropriate to that calendar final Date time = new Date(); for (int i = 0; i < calTypes.length; ++i) { ULocale aLoc = loc.setKeywordValue("calendar", calTypes[i]); logln("locale: " + aLoc); DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, aLoc); logln("df type: " + df.getClass().getName() + " loc: " + df.getLocale(ULocale.VALID_LOCALE)); Calendar cal = df.getCalendar(); // todo, what about variants of calendars, we have a type for islamic-civil, should we also have a type // for variants of other calendars? assertEquals("calendar types", cal.getType(), calTypes[i].equals("islamic-civil") ? "islamic" : calTypes[i]); DateFormat df2 = cal.getDateTimeFormat(DateFormat.FULL, DateFormat.FULL, ULocale.US); logln("df2 type: " + df2.getClass().getName() + " loc: " + df2.getLocale(ULocale.VALID_LOCALE)); assertEquals("format results", df.format(time), df2.format(time)); } // dateFormat.setCalendar should throw exception if wrong format for calendar if (false) { DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, new ULocale("en_US@calendar=chinese")); logln("dateformat type: " + df.getClass().getName()); Calendar cal = Calendar.getInstance(new ULocale("en_US@calendar=chinese")); logln("calendar type: " + cal.getClass().getName()); } } public void TestTypes() { String[] locs = { "en_US_VALLEYGIRL", "en_US_VALLEYGIRL@collation=phonebook;calendar=japanese", "en_US_VALLEYGIRL@collation=phonebook;calendar=gregorian", "ja_JP@calendar=japanese", "th_TH@calendar=buddhist", "ja_JP_TRADITIONAL", "th_TH_TRADITIONAL", "th_TH_TRADITIONAL@calendar=gregorian", "en_US", "th_TH", // Default calendar for th_TH is buddhist "th", // th's default region is TH and buddhist is used as default for TH // FIXME: ICU Service canonicalize en_TH to en, so TH is ignored in Calendar instantiation. See #6816. // "en_TH", // Default calendar for any locales with region TH is buddhist }; String[] types = { "gregorian", "japanese", "gregorian", "japanese", "buddhist", "japanese", "buddhist", "gregorian", "gregorian", "buddhist", "buddhist", // FIXME: ICU Service canonicalize en_TH to en, so TH is ignored in Calendar instantiation. See #6816. // "buddhist", }; for (int i = 0; i < locs.length; i++) { Calendar cal = Calendar.getInstance(new ULocale(locs[i])); if (!cal.getType().equals(types[i])) { errln(locs[i] + " Calendar type " + cal.getType() + " instead of " + types[i]); } } } }