/********************************************************************
* COPYRIGHT:
- * Copyright (c) 1997-2012, International Business Machines Corporation
+ * Copyright (c) 1997-2016, International Business Machines Corporation
* and others. All Rights Reserved.
********************************************************************/
CASE(47,TestT8057);
CASE(48,TestT8596);
CASE(49,Test9019);
+ CASE(50,TestT9452);
default: name = ""; break;
}
}
CalendarRegressionTest::Test9019()
{
UErrorCode status = U_ZERO_ERROR;
- LocalPointer<GregorianCalendar> cal1(new GregorianCalendar(status));
- LocalPointer<GregorianCalendar> cal2(new GregorianCalendar(status));
- cal1->set(UCAL_HOUR, 1);
- cal2->set(UCAL_HOUR,2);
- cal1->clear();
- cal2->clear();
+ LocalPointer<GregorianCalendar> cal1(new GregorianCalendar(status), status);
+ LocalPointer<GregorianCalendar> cal2(new GregorianCalendar(status), status);
if(U_FAILURE(status)) {
dataerrln("Error creating Calendar: %s", u_errorName(status));
return;
}
+ cal1->set(UCAL_HOUR, 1);
+ cal2->set(UCAL_HOUR,2);
+ cal1->clear();
+ cal2->clear();
failure(status, "new GregorianCalendar");
cal1->set(2011,UCAL_MAY,06);
cal2->set(2012,UCAL_JANUARY,06);
}
UErrorCode status = U_ZERO_ERROR;
count = ids->count(status);
+ (void)count; // Suppress set but not used warning.
SimpleTimeZone *pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, *ids->snext(status));
pdt->setStartRule(UCAL_APRIL, 1, UCAL_SUNDAY, 2 * 60 * 60 * 1000, status);
pdt->setEndRule(UCAL_OCTOBER, -1, UCAL_SUNDAY, 2 * 60 * 60 * 1000, status);
if (dow < min || dow > max)
errln("FAIL: Day of week %d out of range [%d,%d]\n", dow, min, max);
if (dow != UCAL_SUNDAY)
- errln("FAIL: Day of week should be SUNDAY Got " + dow);
+ errln(UnicodeString("FAIL: Day of week should be SUNDAY Got ") + dow);
if(U_FAILURE(status)) {
errln("Error checking Calendar: %s", u_errorName(status));
}
int32_t dow = a->get(UCAL_DAY_OF_WEEK, status);
if (dow != UCAL_THURSDAY)
- errln("Fail: Want THURSDAY Got " + dow);
+ errln(UnicodeString("Fail: Want THURSDAY Got ") + dow);
delete a;
}
UnicodeString temp;
errln("test failed with zone " + zones[i]->getID(temp));
errln(" cutover date is Date(Long.MAX_VALUE)");
- errln(" isLeapYear(100) returns: " + is100Leap);
+ errln(UnicodeString(" isLeapYear(100) returns: ") + is100Leap);
}
delete calendar;
}
2000, UCAL_JANUARY, 1, 52,
2001, UCAL_DECEMBER, 31, 1,
};
- int32_t DATA_length = (int32_t)(sizeof(DATA) / sizeof(DATA[0]));
+ int32_t DATA_length = UPRV_LENGTHOF(DATA);
UnicodeString str;
DateFormat& dfmt = *(DateFormat*)&fmt;
30, 42, 293, UCAL_SATURDAY,
31, 43, 294, UCAL_SUNDAY
};
- int32_t DOY_DATA_length = (int32_t)(sizeof(DOY_DATA) / sizeof(DOY_DATA[0]));
+ int32_t DOY_DATA_length = UPRV_LENGTHOF(DOY_DATA);
for (i=0; i<DOY_DATA_length; i+=4) {
// Test time->fields
// { Calendar::YEAR_WOY, ADD|ROLL, 1, -ONE_DAY, +6*ONE_DAY },
// { Calendar::DOW_LOCAL, ADD|ROLL, 2, -ONE_DAY, +1*ONE_DAY }
};
- int32_t DATA_length = (int32_t)(sizeof(DATA) / sizeof(DATA[0]));
+ int32_t DATA_length = UPRV_LENGTHOF(DATA);
// Now run the tests
for (i=0; i<DATA_length; ++i) {
1964, UCAL_SEPTEMBER, 7, 1999, UCAL_JUNE, 4,
1999, UCAL_JUNE, 4, 1964, UCAL_SEPTEMBER, 7,
};
- int32_t DATA_length = (int32_t)(sizeof(DATA)/sizeof(DATA[0]));
+ int32_t DATA_length = UPRV_LENGTHOF(DATA);
Calendar* pcal = Calendar::createInstance(Locale::getUS(), ec);
if(U_FAILURE(ec)) {
dataerrln("Error creating calendar %s", u_errorName(ec));
delete gc;
}
+// Test case for ticket 9452
+// Calendar addition fall onto the missing date - 2011-12-30 in Samoa
+void CalendarRegressionTest::TestT9452(void) {
+ UErrorCode status = U_ZERO_ERROR;
+ GregorianCalendar cal(TimeZone::createTimeZone("Pacific/Apia"), status);
+ failure(status, "initializing GregorianCalendar");
+
+ SimpleDateFormat sdf(UnicodeString("y-MM-dd'T'HH:mm:ssZZZZZ"), status);
+ failure(status, "initializing SimpleDateFormat");
+ sdf.setCalendar(cal);
+
+ UnicodeString dstr;
+
+ // Set date to 2011-12-29 00:00
+ cal.clear();
+ cal.set(2011, UCAL_DECEMBER, 29, 0, 0, 0);
+
+ UDate d = cal.getTime(status);
+ if (!failure(status, "getTime for initial date")) {
+ sdf.format(d, dstr);
+ logln(UnicodeString("Initial date: ") + dstr);
+
+ // Add 1 day
+ cal.add(UCAL_DATE, 1, status);
+ failure(status, "add 1 day");
+ d = cal.getTime(status);
+ failure(status, "getTime after +1 day");
+ dstr.remove();
+ sdf.format(d, dstr);
+ logln(UnicodeString("+1 day: ") + dstr);
+ assertEquals("Add 1 day", UnicodeString("2011-12-31T00:00:00+14:00"), dstr);
+
+ // Subtract 1 day
+ cal.add(UCAL_DATE, -1, status);
+ failure(status, "subtract 1 day");
+ d = cal.getTime(status);
+ failure(status, "getTime after -1 day");
+ dstr.remove();
+ sdf.format(d, dstr);
+ logln(UnicodeString("-1 day: ") + dstr);
+ assertEquals("Subtract 1 day", UnicodeString("2011-12-29T00:00:00-10:00"), dstr);
+ }
+}
+
#endif /* #if !UCONFIG_NO_FORMATTING */