/* use serialVersionUID from JDK 1.1.4 for interoperability */
private static final long serialVersionUID = -5987973545549424702L;
+ private static final String[][] CALENDAR_CLASSES = {
+ {"GregorianCalendar", "gregorian"},
+ {"JapaneseCalendar", "japanese"},
+ {"BuddhistCalendar", "buddhist"},
+ {"TaiwanCalendar", "roc"},
+ {"PersianCalendar", "persian"},
+ {"IslamicCalendar", "islamic"},
+ {"HebrewCalendar", "hebrew"},
+ {"ChineseCalendar", "chinese"},
+ {"IndianCalendar", "indian"},
+ {"CopticCalendar", "coptic"},
+ {"EthiopicCalendar", "ethiopic"},
+ };
+
+
/**
* Returns era strings. For example: "AD" and "BC".
* @return the era strings.
/**
* Variant of DateFormatSymbols(Calendar, ULocale) that takes the Calendar class
- * instead of a Calandar instance.
+ * instead of a Calendar instance.
* @see #DateFormatSymbols(Calendar, Locale)
* @stable ICU 3.2
*/
String fullName = calendarClass.getName();
int lastDot = fullName.lastIndexOf('.');
String className = fullName.substring(lastDot+1);
- String calType = className.replaceAll("Calendar", "").toLowerCase();
+ String calType = null;
+ for (String[] calClassInfo : CALENDAR_CLASSES) {
+ if (calClassInfo[0].equals(className)) {
+ calType = calClassInfo[1];
+ break;
+ }
+ }
+ if (calType == null) {
+ calType = className.replaceAll("Calendar", "").toLowerCase(Locale.ENGLISH);
+ }
initializeData(locale, calType);
}
/*****************************************************************************************
*
- * Copyright (C) 1996-2010, International Business Machines
+ * Copyright (C) 1996-2011, International Business Machines
* Corporation and others. All Rights Reserved.
**/
import java.util.Locale;
import com.ibm.icu.text.DateFormatSymbols;
+import com.ibm.icu.util.Calendar;
+import com.ibm.icu.util.ULocale;
public class IntlTestDateFormatSymbols extends com.ibm.icu.dev.test.TestFmwk
{
errln("ERROR: Clone failed");
}
}
+
+ public void TestConstructorWithCalendar() {
+ ULocale[] TestLocales = {
+ new ULocale("en_US@caleandar=gregorian"),
+ new ULocale("ja_JP@calendar=japanese"),
+ new ULocale("th_TH@calendar=buddhist"),
+ new ULocale("zh_TW@calendar=roc"),
+ new ULocale("ar_IR@calendar=persian"),
+ new ULocale("ar_EG@calendar=islamic"),
+ new ULocale("he_IL@calendar=hebrew"),
+ new ULocale("zh_CN@calendar=chinese"),
+ new ULocale("hi_IN@calendar=indian"),
+ new ULocale("ar_EG@calendar=coptic"),
+ new ULocale("am_ET@calendar=ethiopic"),
+ };
+
+ int i;
+
+ // calendars
+ Calendar[] calendars = new Calendar[TestLocales.length];
+ for (i = 0; i < TestLocales.length; i++) {
+ calendars[i] = Calendar.getInstance(TestLocales[i]);
+ }
+
+ // Creates an instance from a base locale + calendar
+ DateFormatSymbols[] symbols = new DateFormatSymbols[TestLocales.length];
+ for (i = 0; i < TestLocales.length; i++) {
+ symbols[i] = new DateFormatSymbols(calendars[i], new ULocale(TestLocales[i].getBaseName()));
+ }
+
+ // Compare an instance created from a base locale + calendar
+ // with an instance created from its base locale + calendar class
+ for (i = 0; i < TestLocales.length; i++) {
+ DateFormatSymbols dfs = new DateFormatSymbols(calendars[i].getClass(), new ULocale(TestLocales[i].getBaseName()));
+ if (!dfs.equals(symbols[i])) {
+ errln("FAIL: DateFormatSymbols created from a base locale and calendar instance"
+ + " is different from one created from the same base locale and calendar class - "
+ + TestLocales[i]);
+ }
+ }
+
+ }
}