/********************************************************************
* COPYRIGHT:
- * Copyright (c) 1997-2004, International Business Machines Corporation and
- * others. All Rights Reserved.
+ * Copyright (c) 1997-2013, International Business Machines Corporation
+ * and others. All Rights Reserved.
********************************************************************/
#include "unicode/utypes.h"
#include "unicode/strenum.h"
#include "cmemory.h"
#include "caltest.h"
+#include "unicode/localpointer.h"
#include <float.h>
CASE(42,TestWeekShift);
CASE(43,TestTimeZoneTransitionAdd);
CASE(44,TestDeprecates);
+ CASE(45,TestT5555);
+ CASE(46,TestT6745);
+ CASE(47,TestT8057);
+ CASE(48,TestT8596);
+ CASE(49,Test9019);
+ CASE(50,TestT9452);
default: name = ""; break;
}
}
CalendarRegressionTest::failure(UErrorCode status, const char* msg)
{
if(U_FAILURE(status)) {
- errln(UnicodeString("FAIL: ") + msg + " failed, error " + u_errorName(status));
+ errcheckln(status, UnicodeString("FAIL: ") + msg + " failed, error " + u_errorName(status));
return TRUE;
}
UErrorCode status = U_ZERO_ERROR;
GregorianCalendar *cal = (GregorianCalendar*)Calendar::createInstance(status);
if(U_FAILURE(status)) {
- errln("Error creating Calendar: %s", u_errorName(status));
+ dataerrln("Error creating Calendar: %s", u_errorName(status));
delete cal;
return;
}
UErrorCode status = U_ZERO_ERROR;
GregorianCalendar *cal = new GregorianCalendar(status);
if(U_FAILURE(status)) {
- errln("Error creating Calendar: %s", u_errorName(status));
+ dataerrln("Error creating Calendar: %s", u_errorName(status));
delete cal;
return;
}
UErrorCode status = U_ZERO_ERROR;
GregorianCalendar *cal1 = new GregorianCalendar(status) ;
if(U_FAILURE(status)) {
- errln("Error creating Calendar: %s", u_errorName(status));
+ dataerrln("Error creating Calendar: %s", u_errorName(status));
delete cal1;
return;
}
delete cal2;
}
+
+void
+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();
+ if(U_FAILURE(status)) {
+ dataerrln("Error creating Calendar: %s", u_errorName(status));
+ return;
+ }
+ failure(status, "new GregorianCalendar");
+ cal1->set(2011,UCAL_MAY,06);
+ cal2->set(2012,UCAL_JANUARY,06);
+ printdate(cal1.getAlias(), "cal1: ") ;
+ cal1->setLenient(FALSE);
+ cal1->add(UCAL_MONTH,8,status);
+ failure(status, "->add(UCAL_MONTH,8)");
+ printdate(cal1.getAlias(), "cal1 (lenient) after adding 8 months:") ;
+ printdate(cal2.getAlias(), "cal2 (expected date):") ;
+
+ if(!cal1->equals(*cal2,status)) {
+ errln("Error: cal1 != cal2.\n");
+ }
+ failure(status, "equals");
+}
+
void
CalendarRegressionTest::printdate(GregorianCalendar *cal, const char *string)
{
// require the host zone to be set; it can be set in Java.
UErrorCode status = U_ZERO_ERROR;
StringEnumeration* ids = TimeZone::createEnumeration();
+ if (ids == NULL) {
+ dataerrln("Unable to create TimeZone Enumeration.");
+ return;
+ }
UBool bad = FALSE;
+ TimeZone* tz =TimeZone::createTimeZone("Asia/Riyadh87");
+ failure(status, "new TimeZone");
+ GregorianCalendar *cl = new GregorianCalendar(tz, status);
+ if (U_FAILURE(status)) {
+ dataerrln("Fail new GregorianCalendar: %s", u_errorName(status));
+ delete tz;
+ return;
+ }
+ cl->clear();
+ cl->set(1900, 15, 5, 5, 8, 13);
+ cl->get(UCAL_HOUR, status);
+ failure(status, "cl->get(UCAL_HOUR, status)");
+ status = U_ZERO_ERROR;
+ delete cl;
for (int32_t i=0; i<ids->count(status); ++i) {
TimeZone *zone = TimeZone::createTimeZone(*ids->snext(status));
GregorianCalendar *cal = new GregorianCalendar(zone, status);
c->before(*c,status) ||
*c != *c ||
*c != *d)
- errln("Fail");
+ dataerrln("Fail");
delete c;
delete d;
}
{
int32_t count = 0;
StringEnumeration* ids = TimeZone::createEnumeration(-8 * 60 * 60 * 1000);
+ if (ids == NULL) {
+ dataerrln("Unable to create TimeZone enumeration.");
+ return;
+ }
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);
Calendar *calendar = new GregorianCalendar(pdt, status);
-
+ if (U_FAILURE(status)) {
+ dataerrln("Fail new GregorianCalendar: %s", u_errorName(status));
+ return;
+ }
calendar->set(UCAL_MONTH,3);
calendar->set(UCAL_DATE,18);
calendar->set(UCAL_SECOND, 30);
UErrorCode status = U_ZERO_ERROR;
Calendar *cal = Calendar::createInstance(status);
if(U_FAILURE(status)) {
- errln("Error creating Calendar: %s", u_errorName(status));
+ dataerrln("Error creating Calendar: %s", u_errorName(status));
delete cal;
return;
}
UErrorCode status = U_ZERO_ERROR;
GregorianCalendar *gc = new GregorianCalendar(status);
if(U_FAILURE(status)) {
- errln("Error creating Calendar: %s", u_errorName(status));
+ dataerrln("Error creating Calendar: %s", u_errorName(status));
delete gc;
return;
}
Calendar *cal = Calendar::createInstance(TimeZone::createTimeZone("GMT"),
Locale::getUK(),status);
if(U_FAILURE(status)) {
- errln("Error creating Calendar: %s", u_errorName(status));
+ dataerrln("Error creating Calendar: %s", u_errorName(status));
delete cal;
delete fmt;
return;
{
UErrorCode status = U_ZERO_ERROR;
Calendar *cal = new GregorianCalendar(status);
- if(status == U_USING_FALLBACK_WARNING) {
- errln("Error creating Calendar: %s", u_errorName(status));
+ if(status == U_USING_FALLBACK_WARNING || U_FAILURE(status)) {
+ dataerrln("Error creating Calendar: %s", u_errorName(status));
delete cal;
return;
}
UErrorCode status = U_ZERO_ERROR;
GregorianCalendar *cal = new GregorianCalendar(status);
if(U_FAILURE(status)) {
- errln("Error creating Calendar: %s", u_errorName(status));
+ dataerrln("Error creating Calendar: %s", u_errorName(status));
delete cal;
return;
}
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));
errln("FAIL: actual minimum differs from minimum");
}
if(cal->getActualMinimum(Calendar::DAY_OF_WEEK, status) != min) {
+ errln("FAIL: actual minimum (Calendar::DAY_OF_WEEK, status) differs from minimum");
+ }
+ if(cal->getActualMinimum(Calendar::DAY_OF_WEEK) != min) {
errln("FAIL: actual minimum (Calendar::DAY_OF_WEEK) differs from minimum");
}
if(((Calendar*)cal)->getActualMinimum(UCAL_DAY_OF_WEEK, status) != min) {
UErrorCode status = U_ZERO_ERROR;
Calendar *cal = Calendar::createInstance(status);
if(U_FAILURE(status)) {
- errln("Error creating Calendar: %s", u_errorName(status));
+ dataerrln("Error creating Calendar: %s", u_errorName(status));
delete cal;
return;
}
UErrorCode status = U_ZERO_ERROR;
GregorianCalendar *foo1 = new GregorianCalendar(1997, 8, 27,status);
if(U_FAILURE(status)) {
- errln("Error creating Calendar: %s", u_errorName(status));
+ dataerrln("Error creating Calendar: %s", u_errorName(status));
delete foo1;
return;
}
UDate firstDate = Calendar::getNow();
Calendar *cal = new GregorianCalendar(status);
if(U_FAILURE(status)) {
- errln("Error creating Calendar: %s", u_errorName(status));
+ dataerrln("Error creating Calendar: %s", u_errorName(status));
delete cal;
return;
}
date = new SimpleDateFormat(UnicodeString("dd MMM yyy (zzzz) 'is in week' ww"),status);
Calendar *cal = Calendar::createInstance(status);
if(U_FAILURE(status)) {
- errln("Error creating Calendar: %s", u_errorName(status));
+ dataerrln("Error creating Calendar: %s", u_errorName(status));
delete cal;
delete newZone;
delete date;
void CalendarRegressionTest::test4092362() {
UErrorCode status = U_ZERO_ERROR;
GregorianCalendar *cal1 = new GregorianCalendar(1997, 10, 11, 10, 20, 40,status);
+ if (U_FAILURE(status)) {
+ dataerrln("Fail new GregorianCalendar: %s", u_errorName(status));
+ delete cal1;
+ return;
+ }
/*cal1.set( Calendar::YEAR, 1997 );
cal1.set( Calendar::MONTH, 10 );
cal1.set( Calendar::DATE, 11 );
logln( UnicodeString(" Cal1 = ") + cal1->getTime(status) );
logln( UnicodeString(" Cal1 time in ms = ") + cal1->get(UCAL_MILLISECOND,status) );
- for( int32_t k = 0; k < 100 ; k++ );
+ for (int32_t k = 0; k < 100 ; k++)
+ ;
GregorianCalendar *cal2 = new GregorianCalendar(1997, 10, 11, 10, 20, 40,status);
/*cal2.set( Calendar::YEAR, 1997 );
{
UErrorCode status = U_ZERO_ERROR;
GregorianCalendar *a = new GregorianCalendar(1997,UCAL_NOVEMBER, 13,status);
+ if (U_FAILURE(status)) {
+ dataerrln("Fail new GregorianCalendar: %s", u_errorName(status));
+ delete a;
+ return;
+ }
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;
}
int32_t sec = 0, min = 0, hr = 0, day = 1, month = 10, year = 1997;
Calendar *cal1 = new GregorianCalendar(*PST,status);
+ if (U_FAILURE(status)) {
+ dataerrln("Failure new GregorianCalendar: %s", u_errorName(status));
+ delete GMT;
+ delete PST;
+ delete cal1;
+ return;
+ }
cal1->setTime(880698639000.0,status);
// Issue 1: Changing the timezone doesn't change the
// represented time. The old API, pre 1.2.2a requires
Calendar *cal2 = new GregorianCalendar(*GMT,status);
Calendar *cal3 = new GregorianCalendar(*PST,status);
+ cal2->set(UCAL_MILLISECOND, 0);
+ cal3->set(UCAL_MILLISECOND, 0);
cal2->set(cal1->get(UCAL_YEAR,status),
cal1->get(UCAL_MONTH,status),
for (int32_t x=0;x<12;x++) {
GregorianCalendar *gc = new
GregorianCalendar(1997,x,y[x], status);
+ if (U_FAILURE(status)) {
+ dataerrln("Fail new GregorianCalendar: %s", u_errorName(status));
+ delete gc;
+ return;
+ }
int32_t m1,m2;
log(UnicodeString("") + (m1=gc->get(UCAL_MONTH,status)+1)+UnicodeString("/")+
gc->get(UCAL_DATE,status)+"/"+gc->get(UCAL_YEAR,status)+
UErrorCode status = U_ZERO_ERROR;
GregorianCalendar *cal = (GregorianCalendar*)Calendar::createInstance(status);
if(U_FAILURE(status)) {
- errln("Error creating calendar: %s", u_errorName(status));
+ dataerrln("Error creating calendar: %s", u_errorName(status));
delete cal;
return;
}
UnicodeString output, testDesc, str, str2;
GregorianCalendar *testCal = (GregorianCalendar*)Calendar::createInstance(status);
if(U_FAILURE(status)) {
- errln("Error creating calendar: %s", u_errorName(status));
+ dataerrln("Error creating calendar: %s", u_errorName(status));
delete testCal;
return;
}
for (int32_t j=0; j<3; ++j) {
UnicodeString temp;
if (n[j] == 0)
- errln(UnicodeString("Fail: No locales for ") + locales[i].getName());
+ dataerrln(UnicodeString("Fail: No locales for ") + locales[i].getName());
}
}
//}
UErrorCode status = U_ZERO_ERROR;
Calendar *cal = Calendar::createInstance(status);
if(U_FAILURE(status)) {
- errln("Error creating calendar %s", u_errorName(status));
+ dataerrln("Error creating calendar %s", u_errorName(status));
delete cal;
return;
}
void CalendarRegressionTest::test4114578()
{
UErrorCode status = U_ZERO_ERROR;
- int32_t ONE_HOUR = 60*60*1000;
+ double ONE_HOUR = 60*60*1000;
Calendar *cal = Calendar::createInstance(status);
if(U_FAILURE(status)) {
- errln("Error creating calendar %s", u_errorName(status));
+ dataerrln("Error creating calendar %s", u_errorName(status));
delete cal;
return;
}
UErrorCode status = U_ZERO_ERROR;
Calendar *cal = Calendar::createInstance(status);
if(U_FAILURE(status)) {
- errln("Error creating calendar %s", u_errorName(status));
+ dataerrln("Error creating calendar %s", u_errorName(status));
delete cal;
return;
}
UErrorCode status = U_ZERO_ERROR;
GregorianCalendar *cal = (GregorianCalendar*) Calendar::createInstance(status);
if(U_FAILURE(status)) {
- errln("Error creating calendar %s", u_errorName(status));
+ dataerrln("Error creating calendar %s", u_errorName(status));
delete cal;
return;
}
DateFormat *fmt = new SimpleDateFormat(UnicodeString("MMMM d, yyyy G"),status);
+ if(U_FAILURE(status)) {
+ dataerrln("Error creating SimpleDateFormat - %s", u_errorName(status));
+ delete cal;
+ return;
+ }
cal->clear();
for (int32_t y=-20; y<=10; ++y) {
cal->set(UCAL_ERA, y < 1 ? GregorianCalendar::BC : GregorianCalendar::AD);
UErrorCode status = U_ZERO_ERROR;
GregorianCalendar *cal = (GregorianCalendar*) Calendar::createInstance(status);
if(U_FAILURE(status)) {
- errln("Error creating calendar %s", u_errorName(status));
+ dataerrln("Error creating calendar %s", u_errorName(status));
delete cal;
return;
}
DateFormat *fmt = new SimpleDateFormat(UnicodeString("MMMM d, yyyy G"),status);
+ if(U_FAILURE(status)) {
+ dataerrln("Error creating SimpleDateFormat - %s", u_errorName(status));
+ delete cal;
+ return;
+ }
cal->clear();
cal->set(UCAL_ERA, GregorianCalendar::BC);
cal->set(UCAL_YEAR, 81); // 81 BC is a leap year (proleptically)
UErrorCode status = U_ZERO_ERROR;
GregorianCalendar *cal = new GregorianCalendar(status);
if(U_FAILURE(status)) {
- errln("Error creating calendar %s", u_errorName(status));
+ dataerrln("Error creating calendar %s", u_errorName(status));
delete cal;
return;
}
UErrorCode status = U_ZERO_ERROR;
GregorianCalendar *calendar = new GregorianCalendar(status);
if(U_FAILURE(status)) {
- errln("Error creating calendar %s", u_errorName(status));
+ dataerrln("Error creating calendar %s", u_errorName(status));
delete calendar;
return;
}
UErrorCode status = U_ZERO_ERROR;
GregorianCalendar *calendar = new GregorianCalendar(status);
if(status == U_USING_FALLBACK_WARNING || U_FAILURE(status)) {
- errln("Error creating calendar %s", u_errorName(status));
+ dataerrln("Error creating calendar %s", u_errorName(status));
delete calendar;
return;
}
UErrorCode status = U_ZERO_ERROR;
GregorianCalendar *calendar = new GregorianCalendar(status);
if(U_FAILURE(status)) {
- errln("Error creating calendar %s", u_errorName(status));
+ dataerrln("Error creating calendar %s", u_errorName(status));
delete calendar;
return;
}
UErrorCode status = U_ZERO_ERROR;
GregorianCalendar *calendar = new GregorianCalendar(status);
if(status == U_USING_FALLBACK_WARNING || U_FAILURE(status)) {
- errln("Error creating calendar %s", u_errorName(status));
+ dataerrln("Error creating calendar %s", u_errorName(status));
delete calendar;
return;
}
for (int32_t i=0; i < 3; ++i) {
GregorianCalendar *calendar = new GregorianCalendar(zones[i], status);
if(U_FAILURE(status)) {
- errln("Couldnt' create calendar.");
+ dataerrln("Couldnt' create calendar.: %s", u_errorName(status));
return;
}
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;
}
GregorianCalendar *cal = new GregorianCalendar(tz, status);
if(U_FAILURE(status)) {
- errln("Couldn't create calendar");
+ dataerrln("Couldn't create calendar.: %s", u_errorName(status));
return;
}
UDate d0, dPlus, dMinus;
UErrorCode status = U_ZERO_ERROR;
GregorianCalendar *calendar = new GregorianCalendar(1996, UCAL_FEBRUARY, 29, status);
if(U_FAILURE(status)) {
- errln("Couldn't create calendar");
+ dataerrln("Couldn't create calendar.: %s", u_errorName(status));
return;
}
UDate start = calendar->getTime(status);
GregorianCalendar *calendar = new GregorianCalendar(Locale::getUS(), status);
if(U_FAILURE(status)) {
- errln("Couldn't create calendar");
+ dataerrln("Couldn't create calendar.: %s", u_errorName(status));
return;
}
calendar->set(1998, UCAL_MARCH, 1);
DateFormat *format = new SimpleDateFormat(UnicodeString("EEE MMM dd HH:mm:ss zzz yyyy G"),
Locale::getUS(), status);
if(U_FAILURE(status)) {
- errln("Couldn't create SimpleDateFormat");
+ dataerrln("Couldn't create SimpleDateFormat - %s", u_errorName(status));
return;
}
Locale::getUS(), status);
fmt.setCalendar(cal);
if (U_FAILURE(status)) {
- errln("Couldn't initialize test");
+ dataerrln("Couldn't initialize test - %s", u_errorName(status));
return;
}
UErrorCode status = U_ZERO_ERROR;
UnicodeString temp, temp2, temp3;
int32_t i;
- GregorianCalendar cal(TimeZone::createTimeZone("GMT"), status);
+ GregorianCalendar cal(TimeZone::createTimeZone("GMT"), Locale::getUS(), status);
SimpleDateFormat fmt("HH:mm 'w'w 'd'D E d MMM yyyy", Locale::getUS(), status);
if (U_FAILURE(status)) {
- errln("Error: Cannot create calendar or format");
+ dataerrln("Error: Cannot create calendar or format - %s", u_errorName(status));
return;
}
fmt.setCalendar(cal);
int32_t DATA_length = (int32_t)(sizeof(DATA)/sizeof(DATA[0]));
Calendar* pcal = Calendar::createInstance(Locale::getUS(), ec);
if(U_FAILURE(ec)) {
- errln("Error creating calendar %s", u_errorName(ec));
+ dataerrln("Error creating calendar %s", u_errorName(ec));
delete pcal;
return;
}
SimpleDateFormat fmt(UnicodeString("MMM dd yyyy",""), ec);
fmt.setCalendar(cal);
UnicodeString s, t, u;
- if (!failure(ec, "setup")) {
+ if (U_SUCCESS(ec)) {
for (i=0; i<DATA_length; i+=6) {
int32_t y1 = DATA[i];
int32_t m1 = DATA[i+1];
fmt.format(date22, t.remove()));
}
}
+ } else {
+ dataerrln("Error creating SimpleDateFormat - %s", u_errorName(ec));
}
delete pcal;
}
+void CalendarRegressionTest::TestT5555()
+{
+ UErrorCode ec = U_ZERO_ERROR;
+ Calendar *cal = Calendar::createInstance(ec);
+
+ if (cal == NULL || U_FAILURE(ec)) {
+ dataerrln("FAIL: Calendar::createInstance(): %s", u_errorName(ec));
+ delete cal;
+ return;
+ }
+
+ // Set to Wednesday, February 21, 2007
+ cal->set(2007, UCAL_FEBRUARY, 21);
+
+ // Advance three years
+ cal->add(UCAL_MONTH, 36, ec);
+
+ // Set to last Wednesday of the month
+ cal->set(UCAL_DAY_OF_WEEK_IN_MONTH, -1);
+
+ cal->getTime(ec);
+
+ int32_t yy, mm, dd, ee;
+
+ yy = cal->get(UCAL_YEAR, ec);
+ mm = cal->get(UCAL_MONTH, ec);
+ dd = cal->get(UCAL_DATE, ec);
+ ee = cal->get(UCAL_DAY_OF_WEEK, ec);
+
+ // Should be set to Wednesday, February 24, 2010
+ if (U_FAILURE(ec) || yy != 2010 || mm != UCAL_FEBRUARY || dd != 24 || ee != UCAL_WEDNESDAY) {
+ errln("FAIL: got date %4d/%02d/%02d, expected 210/02/24: ", yy, mm + 1, dd);
+ }
+ delete cal;
+}
+
+typedef struct {
+ int32_t startYear;
+ int32_t startMonth; // 0-based
+ int32_t startDay; // 1-based
+ UCalendarDateFields fieldToChange;
+ int32_t fieldDelta;
+ int32_t endYear;
+ int32_t endMonth; // 0-based
+ int32_t endDay; // 1-based
+} CoptEthCalTestItem;
+
+// year 1724 in coptic calendar =
+// year 2000 in ethiopic calendar (276 more than coptic) =
+// year 7500 in ethiopic-amete-alem calendar (5776 more than coptic)
+// (2007-2008 in gregorian calendar depending on month)
+static const CoptEthCalTestItem coptEthCalTestItems[] = {
+ { 1724, 12, 1, UCAL_MONTH, +1, 1725, 0, 1 },
+ { 1724, 12, 1, UCAL_MONTH, +9, 1725, 8, 1 },
+ { 1723, 12, 2, UCAL_MONTH, +1, 1724, 0, 2 }, // 1723 is a leap year
+ { 1723, 12, 2, UCAL_MONTH, +9, 1724, 8, 2 },
+ { 1725, 0, 1, UCAL_MONTH, -1, 1724, 12, 1 },
+ { 1725, 0, 1, UCAL_MONTH, -6, 1724, 7, 1 },
+ { 1724, 12, 1, UCAL_DATE, +8, 1725, 0, 4 },
+ { 1723, 12, 1, UCAL_DATE, +8, 1724, 0, 3 }, // 1723 is a leap year
+ { 1724, 0, 1, UCAL_DATE, -1, 1723, 12, 6 }, // 1723 is a leap year
+ { 0, 0, 0, (UCalendarDateFields)0, 0, 0, 0, 0 } // terminator
+};
+
+typedef struct {
+ const char * locale;
+ int32_t yearOffset;
+} CoptEthCalLocale;
+
+static const CoptEthCalLocale copEthCalLocales[] = {
+ { "en@calendar=coptic", 0 },
+ { "en@calendar=ethiopic", 276 },
+ { NULL, 0 } // terminator
+};
+
+void CalendarRegressionTest::TestT6745()
+{
+ const CoptEthCalLocale * testLocalePtr;
+ for ( testLocalePtr = copEthCalLocales; testLocalePtr->locale != NULL; ++testLocalePtr) {
+ UErrorCode status = U_ZERO_ERROR;
+ Calendar *cal = Calendar::createInstance(Locale(testLocalePtr->locale), status);
+ if ( U_FAILURE(status) ) {
+ dataerrln((UnicodeString)"FAIL: Calendar::createInstance, locale " + testLocalePtr->locale + ", status " + u_errorName(status));
+ continue;
+ }
+ const CoptEthCalTestItem * testItemPtr;
+ for (testItemPtr = coptEthCalTestItems; testItemPtr->fieldDelta != 0; ++testItemPtr) {
+ status = U_ZERO_ERROR;
+ cal->set( testItemPtr->startYear + testLocalePtr->yearOffset, testItemPtr->startMonth, testItemPtr->startDay, 9, 0 );
+ cal->add( testItemPtr->fieldToChange, testItemPtr->fieldDelta, status );
+ if ( U_FAILURE(status) ) {
+ errln((UnicodeString)"FAIL: Calendar::add, locale " + testLocalePtr->locale + ", field/delta " +
+ testItemPtr->fieldToChange + "/" + testItemPtr->fieldDelta + ", status " + u_errorName(status));
+ continue;
+ }
+ int32_t endYear = testItemPtr->endYear + testLocalePtr->yearOffset;
+ int32_t year = cal->get(UCAL_YEAR, status);
+ int32_t month = cal->get(UCAL_MONTH, status);
+ int32_t day = cal->get(UCAL_DATE, status);
+ if ( U_FAILURE(status) || year != endYear || month != testItemPtr->endMonth || day != testItemPtr->endDay ) {
+ errln((UnicodeString)"ERROR: Calendar::add, locale " + testLocalePtr->locale + ", field/delta " +
+ testItemPtr->fieldToChange + "/" + testItemPtr->fieldDelta + ", status " + u_errorName(status) +
+ ", expected " + endYear + "/" + testItemPtr->endMonth + "/" + testItemPtr->endDay +
+ ", got " + year + "/" + month + "/" + day );
+ }
+ }
+ delete cal;
+ }
+}
+
/**
* Test behavior of fieldDifference around leap years. Also test a large
* field difference to check binary search.
UErrorCode ec = U_ZERO_ERROR;
Calendar* cal = Calendar::createInstance(ec);
if (cal == NULL || U_FAILURE(ec)) {
- errln("FAIL: Calendar::createInstance()");
+ dataerrln("FAIL: Calendar::createInstance(): %s", u_errorName(ec));
delete cal;
return;
}
UErrorCode ec = U_ZERO_ERROR;
Calendar* cal = Calendar::createInstance(loc, ec);
if (U_FAILURE(ec)) {
- errln("FAIL: Can't construct calendar for ms_MY");
+ dataerrln("FAIL: Can't construct calendar for ms_MY: %s", u_errorName(ec));
}
delete cal;
}
UErrorCode ec = U_ZERO_ERROR;
GregorianCalendar cal(TimeZone::createTimeZone("America/Los_Angeles"),
Locale("en", "US"), ec);
+ if (U_FAILURE(ec)) {
+ dataerrln("Fail GregorianCalendar: %s", u_errorName(ec));
+ return;
+ }
cal.setTime(UDate(997257600000.0), ec); // 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
StringEnumeration *tz = TimeZone::createEnumeration();
if (tz == NULL) {
- errln("FAIL: TimeZone::createEnumeration");
+ dataerrln("FAIL: TimeZone::createEnumeration");
return;
}
}
if (U_FAILURE(ec)) {
- errln("FAIL: %s", u_errorName(ec));
+ dataerrln("FAIL: %s", u_errorName(ec));
}
delete tz;
Calendar *c2 = Calendar::createInstance("ja_JP_TRADITIONAL",status);
if(!c1 || !c2 || U_FAILURE(status)) {
- errln("Couldn't create calendars for roll of HOUR");
+ dataerrln("Couldn't create calendars for roll of HOUR: %s", u_errorName(status));
return;
}
delete c1;
delete c2;
+
+}
+
+void CalendarRegressionTest::TestT8057(void) {
+ // Set the calendar to the last day in a leap year
+ UErrorCode status = U_ZERO_ERROR;
+ GregorianCalendar *cal = (GregorianCalendar*)Calendar::createInstance(status);
+ if(U_FAILURE(status)) {
+ errln("Error creating Calendar: %s", u_errorName(status));
+ delete cal;
+ return;
+ }
+ cal->setLenient(FALSE);
+ cal->clear();
+ cal->set(2008, UCAL_DECEMBER, 31);
+
+ // Force calculating then fields once.
+ UDate t = cal->getTime(status);
+ if(U_FAILURE(status)) {
+ errln("Error while calculating the date");
+ delete cal;
+ return;
+ }
+
+ UDate expected = 1262246400000.0; // 2009-12-31 00:00 PST
+
+ cal->add(UCAL_YEAR, 1, status);
+ t = cal->getTime(status);
+ if (U_SUCCESS(status)) {
+ if (t != expected) {
+ dataerrln((UnicodeString)"FAIL: wrong date after add: expected=" + expected + " returned=" + t);
+ }
+ } else {
+ errln("FAIL: error while adding one year");
+ }
+
+ delete cal;
}
+// Test case for ticket#8596.
+// Setting an year followed by getActualMaximum(Calendar.WEEK_OF_YEAR)
+// may result wrong maximum week.
+void CalendarRegressionTest::TestT8596(void) {
+ UErrorCode status = U_ZERO_ERROR;
+ GregorianCalendar *gc = new GregorianCalendar(*TimeZone::getGMT(), status);
+
+ if (U_FAILURE(status)) {
+ dataerrln("Error creating Calendar: %s", u_errorName(status));
+ delete gc;
+ return;
+ }
+
+ gc->setFirstDayOfWeek(UCAL_MONDAY);
+ gc->setMinimalDaysInFirstWeek(4);
+
+ // Force the calender to resolve the fields once.
+ // The maximum week number in 2011 is 52.
+ gc->set(UCAL_YEAR, 2011);
+ gc->get(UCAL_YEAR, status);
+
+ // Set a date in year 2009, but not calling get to resolve
+ // the calendar's internal field yet.
+ gc->set(2009, UCAL_JULY, 1);
+
+ // Then call getActuamMaximum for week of year.
+ // #8596 was caused by conflict between year set
+ // above and internal work calendar field resolution.
+ int32_t maxWeeks = gc->getActualMaximum(UCAL_WEEK_OF_YEAR, status);
+
+ if (U_FAILURE(status)) {
+ errln("Error calendar calculation: %s", u_errorName(status));
+ delete gc;
+ return;
+ }
+
+ if (maxWeeks != 53) {
+ errln((UnicodeString)"FAIL: Max week in 2009 in ISO calendar is 53, but got " + maxWeeks);
+ }
+
+ 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 */