/**
*******************************************************************************
- * Copyright (C) 2000-2011, International Business Machines Corporation and *
+ * Copyright (C) 2000-2013, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.text.ParsePosition;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.SHORT, loc),
"DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.SHORT, loc)",
- "Thursday, April 5, 2001 5:43 PM",
+ "Thursday, April 5, 2001 at 5:43 PM",
DateFormat.getDateInstance(cal, DateFormat.SHORT, loc),
"DateFormat.getDateInstance(cal, DateFormat.SHORT, loc)",
DateFormat.getDateTimeInstance(cal, DateFormat.FULL, DateFormat.SHORT, loc),
"DateFormat.getDateTimeInstance(cal, DateFormat.FULL, DateFormat.SHORT, loc)",
- "Thursday, April 5, 2001 5:43 PM",
+ "Thursday, April 5, 2001 at 5:43 PM",
cal.getDateTimeFormat(DateFormat.SHORT, DateFormat.FULL, loc),
"cal.getDateTimeFormat(DateFormat.SHORT, DateFormat.FULL, loc)",
- "4/5/01 5:43:53 PM Pacific Daylight Time",
+ "4/5/01, 5:43:53 PM Pacific Daylight Time",
cal.getDateTimeFormat(DateFormat.FULL, DateFormat.SHORT, loc),
"cal.getDateTimeFormat(DateFormat.FULL, DateFormat.SHORT, loc)",
- "Thursday, April 5, 2001 5:43 PM",
+ "Thursday, April 5, 2001 at 5:43 PM",
};
for (int i=0; i<DATA.length; i+=3) {
DateFormat df = (DateFormat) DATA[i];
{"th_TH", "buddhist", "gregorian"},
{"und_TH", "buddhist", "gregorian"},
{"en_TH", "buddhist", "gregorian"},
- {"he_IL", "gregorian", "hebrew", "islamic", "islamic-civil"},
- {"ar_EG", "gregorian", "coptic", "islamic", "islamic-civil"},
+ {"he_IL", "gregorian", "hebrew", "islamic", "islamic-civil", "islamic-tbla"},
+ {"ar_EG", "gregorian", "coptic", "islamic", "islamic-civil", "islamic-tbla"},
{"ja", "gregorian", "japanese"},
{"ps_Guru_IN", "gregorian", "indian"},
{"th@calendar=gregorian", "buddhist", "gregorian"},
{"en@calendar=islamic", "gregorian"},
{"zh_TW", "gregorian", "roc", "chinese"},
- {"ar_IR", "gregorian", "persian", "islamic", "islamic-civil"},
+ {"ar_IR", "persian", "gregorian", "islamic", "islamic-civil", "islamic-tbla"},
};
String[] ALL = Calendar.getKeywordValuesForLocale("calendar", ULocale.getDefault(), false);
errln("FAIL: Max week in 2009 in ISO calendar is 53, but got " + maxWeeks);
}
}
+
+ /**
+ * Test case for ticket:9019
+ */
+ public void Test9019() {
+ GregorianCalendar cal1 = new GregorianCalendar(TimeZone.GMT_ZONE,ULocale.US);
+ GregorianCalendar cal2 = new GregorianCalendar(TimeZone.GMT_ZONE,ULocale.US);
+ cal1.clear();
+ cal2.clear();
+ cal1.set(2011,Calendar.MAY,06);
+ cal2.set(2012,Calendar.JANUARY,06);
+ cal1.setLenient(false);
+ cal1.add(Calendar.MONTH, 8);
+ if(!cal1.getTime().equals(cal2.getTime())) {
+ errln("Error: Calendar is " + cal1.getTime() + " but expected " + cal2.getTime());
+ } else {
+ logln("Pass: rolled calendar is " + cal1.getTime());
+ }
+ }
+
+ /**
+ * Test case for ticket 9452
+ * Calendar addition fall onto the missing date - 2011-12-30 in Samoa
+ */
+ public void TestT9452() {
+ TimeZone samoaTZ = TimeZone.getTimeZone("Pacific/Apia");
+ GregorianCalendar cal = new GregorianCalendar(samoaTZ);
+
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZZZ");
+ sdf.setTimeZone(samoaTZ);
+
+ // Set date to 2011-12-29 00:00
+ cal.clear();
+ cal.set(2011, Calendar.DECEMBER, 29, 0, 0, 0);
+
+ Date d = cal.getTime();
+ String dstr = sdf.format(d);
+ logln("Initial date: " + dstr);
+
+ // Add 1 day
+ cal.add(Calendar.DATE, 1);
+ d = cal.getTime();
+ dstr = sdf.format(d);
+ logln("+1 day: " + dstr);
+ assertEquals("Add 1 day", "2011-12-31T00:00:00+14:00", dstr);
+
+ // Subtract 1 day
+ cal.add(Calendar.DATE, -1);
+ d = cal.getTime();
+ dstr = sdf.format(d);
+ logln("-1 day: " + dstr);
+ assertEquals("Subtract 1 day", "2011-12-29T00:00:00-10:00", dstr);
+ }
+
+ /**
+ * Test case for ticket 9403
+ * semantic API change when attempting to call setTimeInMillis(long) with a value outside the bounds.
+ * In strict mode an IllegalIcuArgumentException will be thrown
+ * In lenient mode the value will be pinned to the relative min/max
+ */
+ public void TestT9403() {
+ Calendar myCal = Calendar.getInstance();
+ long dateBit1, dateBit2, testMillis = 0L;
+ boolean missedException = true;
+
+ testMillis = -184303902611600000L;
+ logln("Testing invalid setMillis value in lienent mode - using value: " + testMillis);
+
+ try {
+ myCal.setTimeInMillis(testMillis);
+ } catch (IllegalArgumentException e) {
+ logln("Fail: detected as bad millis");
+ missedException = false;
+ }
+ assertTrue("Fail: out of bound millis did not trigger exception!", missedException);
+ dateBit1 = myCal.get(Calendar.MILLISECOND);
+ assertNotEquals("Fail: millis not changed to MIN_MILLIS", testMillis, dateBit1);
+
+
+ logln("Testing invalid setMillis value in strict mode - using value: " + testMillis);
+ myCal.setLenient(false);
+ try {
+ myCal.setTimeInMillis(testMillis);
+ } catch (IllegalArgumentException e) {
+ logln("Pass: correctly detected bad millis");
+ missedException = false;
+ }
+ dateBit1 = myCal.get(Calendar.DAY_OF_MONTH);
+ dateBit2 = myCal.getTimeInMillis();
+ assertFalse("Fail: error in setMillis, allowed invalid value : " + testMillis + "...returned dayOfMonth : " + dateBit1 + " millis : " + dateBit2, missedException);
+ }
+
+ /**
+ * Test case for ticket 9968
+ * subparse fails to return an error indication when start pos is 0
+ */
+ public void TestT9968() {
+ SimpleDateFormat sdf0 = new SimpleDateFormat("-MMMM");
+ ParsePosition pos0 = new ParsePosition(0);
+ /* Date d0 = */ sdf0.parse("-September", pos0);
+ logln("sdf0: " + pos0.getErrorIndex() + "/" + pos0.getIndex());
+ assertTrue("Fail: failed a good test", pos0.getErrorIndex() == -1);
+
+ SimpleDateFormat sdf1 = new SimpleDateFormat("-MMMM");
+ ParsePosition pos1 = new ParsePosition(0);
+ /* Date d1 = */ sdf1.parse("-????", pos1);
+ logln("sdf1: " + pos1.getErrorIndex() + "/" + pos1.getIndex());
+ assertTrue("Fail: failed to detect bad parse", pos1.getErrorIndex() == 1);
+
+ SimpleDateFormat sdf2 = new SimpleDateFormat("MMMM");
+ ParsePosition pos2 = new ParsePosition(0);
+ /* Date d2 = */ sdf2.parse("????", pos2);
+ logln("sdf2: " + pos2.getErrorIndex() + "/" + pos2.getIndex());
+ assertTrue("Fail: failed to detect bad parse", pos2.getErrorIndex() == 0);
+ }
}
//eof