/*
*******************************************************************************
- * Copyright (C) 2001-2010, International Business Machines Corporation and *
+ * Copyright (C) 2001-2013, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
String str = fmt.format(dt);
logln(str);
- if (!str.equals("5/3/97 8:55 AM"))
- errln("Fail: Test broken; Want 5/3/97 8:55 AM Got " + str);
+ if (!str.equals("5/3/97, 8:55 AM"))
+ errln("Fail: Test broken; Want 5/3/97, 8:55 AM Got " + str);
String expected[] = {
"", //"ERA_FIELD",
String what;
{
- DateFormat df = DateFormat.getInstance(new GregorianCalendar(), new Locale("hi","IN"));
+ DateFormat df = DateFormat.getInstance(new GregorianCalendar(), new ULocale("hi_IN@numbers=deva"));
what = "Gregorian Calendar, hindi";
s = df.format(new Date(0)); /* 31/12/1969 */
logln(what + "=" + s);
}
}
}
-
-
- public void Test5006GetShortMonths() throws Exception {
+ // Note: The purpose of this test case is a little bit questionable. This test
+ // case expects Islamic month name is different from Gregorian month name.
+ // However, some locales (in this code, zh_CN) may intentionally use the same
+ // month name for both Gregorian and Islamic calendars. See #9645.
+ public void Test5006GetShortMonths() throws Exception {
// Currently supported NLV locales
Locale ENGLISH = new Locale("en", "US"); // We don't support 'en' alone
Locale ARABIC = new Locale("ar", "");
HUNGARIAN, ITALIAN, HEBREW, JAPANESE, KOREAN, POLISH, PORTUGUESE, RUSSIAN, TURKISH,
CHINESE_SIMPLIFIED, CHINESE_TRADITIONAL };
+ String[] islamicCivilTwelfthMonthLocalized = new String[locales.length];
String[] islamicTwelfthMonthLocalized = new String[locales.length];
String[] gregorianTwelfthMonthLocalized = new String[locales.length];
Locale locale = locales[i];
// Islamic
- com.ibm.icu.util.Calendar islamicCalendar = new com.ibm.icu.util.IslamicCalendar(locale);
+ com.ibm.icu.util.Calendar islamicCivilCalendar = new com.ibm.icu.util.IslamicCalendar(locale);
+ com.ibm.icu.text.SimpleDateFormat islamicCivilDateFormat = (com.ibm.icu.text.SimpleDateFormat) islamicCivilCalendar
+ .getDateTimeFormat(com.ibm.icu.text.DateFormat.FULL, -1, locale);
+ com.ibm.icu.text.DateFormatSymbols islamicCivilDateFormatSymbols = islamicCivilDateFormat
+ .getDateFormatSymbols();
+
+ String[] shortMonthsCivil = islamicCivilDateFormatSymbols.getShortMonths();
+ String twelfthMonthLocalizedCivil = shortMonthsCivil[11];
+
+ islamicCivilTwelfthMonthLocalized[i] = twelfthMonthLocalizedCivil;
+
+ com.ibm.icu.util.IslamicCalendar islamicCalendar = new com.ibm.icu.util.IslamicCalendar(locale);
+ islamicCalendar.setCivil(false);
com.ibm.icu.text.SimpleDateFormat islamicDateFormat = (com.ibm.icu.text.SimpleDateFormat) islamicCalendar
.getDateTimeFormat(com.ibm.icu.text.DateFormat.FULL, -1, locale);
com.ibm.icu.text.DateFormatSymbols islamicDateFormatSymbols = islamicDateFormat
for (int i = 0; i < locales.length; i++) {
String gregorianTwelfthMonth = gregorianTwelfthMonthLocalized[i];
+ String islamicCivilTwelfthMonth = islamicCivilTwelfthMonthLocalized[i];
String islamicTwelfthMonth = islamicTwelfthMonthLocalized[i];
- logln(locales[i] + ": " + gregorianTwelfthMonth + ", " + islamicTwelfthMonth);
+ logln(locales[i] + ": g:" + gregorianTwelfthMonth + ", ic:" + islamicCivilTwelfthMonth + ", i:"+islamicTwelfthMonth);
if (gregorianTwelfthMonth.equalsIgnoreCase(islamicTwelfthMonth)) {
- errln(locales[i] + ": gregorian and islamic are same: " + gregorianTwelfthMonth
+ // Simplified Chinese uses numeric month for both Gregorian/Islamic calendars
+ if (locales[i] != CHINESE_SIMPLIFIED) {
+ errln(locales[i] + ": gregorian and islamic are same: " + gregorianTwelfthMonth
+ + ", " + islamicTwelfthMonth);
+ }
+ }
+
+ if (gregorianTwelfthMonth.equalsIgnoreCase(islamicCivilTwelfthMonth)) {
+ // Simplified Chinese uses numeric month for both Gregorian/Islamic calendars
+ if (locales[i] != CHINESE_SIMPLIFIED) {
+ errln(locales[i] + ": gregorian and islamic-civil are same: " + gregorianTwelfthMonth
+ + ", " + islamicCivilTwelfthMonth);
+ }
+ }
+ if (!islamicTwelfthMonth.equalsIgnoreCase(islamicCivilTwelfthMonth)) {
+ errln(locales[i] + ": islamic-civil and islamic are NOT same: " + islamicCivilTwelfthMonth
+ ", " + islamicTwelfthMonth);
}
}
}
+
+ public void TestParsing() {
+ String pattern = "EEE-WW-MMMM-yyyy";
+ String text = "mon-02-march-2011";
+ int expectedDay = 7;
+
+ SimpleDateFormat format = new SimpleDateFormat(pattern);
+ Calendar cal = GregorianCalendar.getInstance(Locale.US);
+ ParsePosition pos = new ParsePosition(0);
+
+ try {
+ format.parse(text, cal, pos);
+ } catch (Exception e) {
+ errln("Fail parsing: " + e);
+ }
+
+ if (cal.get(Calendar.DAY_OF_MONTH) != expectedDay) {
+ errln("Parsing failed: day of month should be '7' with pattern: \"" + pattern + "\" for text: \"" + text + "\"");
+ }
+ }
+
+ // Date formatting with Dangi calendar in en locale (#9987)
+ public void TestDangiFormat() {
+ DateFormat fmt = DateFormat.getDateInstance(DateFormat.MEDIUM, new ULocale("en@calendar=dangi"));
+ String calType = fmt.getCalendar().getType();
+ assertEquals("Incorrect calendar type used by the date format instance", "dangi", calType);
+
+ GregorianCalendar gcal = new GregorianCalendar();
+ gcal.set(2013, Calendar.MARCH, 1, 0, 0, 0);
+ Date d = gcal.getTime();
+
+ String dangiDateStr = fmt.format(d);
+ assertEquals("Bad date format", "Mo1 20, gui-si", dangiDateStr);
+ }
+
+ public void TestT10110() {
+ try {
+ SimpleDateFormat formatter = new SimpleDateFormat("Gy年M月d日E", new Locale("zh_Hans"));
+ /* Object parsed = */ formatter.parseObject("610000");
+ }
+ catch(ParseException pe) {
+ return;
+ }
+ catch(Throwable t) {
+ errln("ParseException not thrown for bad pattern! exception was: " + t.getLocalizedMessage());
+ return;
+ }
+ errln("No exception thrown at all for bad pattern!");
+ }
+
}