+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/********************************************************************
- * COPYRIGHT:
- * Copyright (c) 1997-2003, International Business Machines Corporation and
- * others. All Rights Reserved.
+ * COPYRIGHT:
+ * Copyright (c) 1997-2016, International Business Machines Corporation
+ * and others. All Rights Reserved.
********************************************************************/
-
+
#include "unicode/utypes.h"
#if !UCONFIG_NO_FORMATTING
#include "calregts.h"
+#include "unicode/calendar.h"
#include "unicode/gregocal.h"
#include "unicode/simpletz.h"
#include "unicode/smpdtfmt.h"
#include "unicode/strenum.h"
#include "cmemory.h"
+#include "caltest.h"
+#include "unicode/localpointer.h"
#include <float.h>
#define CASE(id,test) case id: name = #test; if (exec) { logln(#test "---"); logln((UnicodeString)""); test(); } break
-void
+void
CalendarRegressionTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
{
// if (exec) logln((UnicodeString)"TestSuite NumberFormatRegressionTest");
CASE(27,test4145158);
CASE(28,test4145983);
CASE(29,test4147269);
-
+
CASE(30,Test4149677);
CASE(31,Test4162587);
CASE(32,Test4165343);
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);
+ CASE(51,TestPersianCalOverflow);
+ CASE(52,TestIslamicCalOverflow);
default: name = ""; break;
}
}
const char* CalendarRegressionTest::FIELD_NAME [] = {
- "ERA",
- "YEAR",
- "MONTH",
- "WEEK_OF_YEAR",
- "WEEK_OF_MONTH",
- "DAY_OF_MONTH",
- "DAY_OF_YEAR",
- "DAY_OF_WEEK",
- "DAY_OF_WEEK_IN_MONTH",
- "AM_PM",
- "HOUR",
- "HOUR_OF_DAY",
- "MINUTE",
- "SECOND",
- "MILLISECOND",
- "ZONE_OFFSET",
+ "ERA",
+ "YEAR",
+ "MONTH",
+ "WEEK_OF_YEAR",
+ "WEEK_OF_MONTH",
+ "DAY_OF_MONTH",
+ "DAY_OF_YEAR",
+ "DAY_OF_WEEK",
+ "DAY_OF_WEEK_IN_MONTH",
+ "AM_PM",
+ "HOUR",
+ "HOUR_OF_DAY",
+ "MINUTE",
+ "SECOND",
+ "MILLISECOND",
+ "ZONE_OFFSET",
"DST_OFFSET",
"YEAR_WOY",
"DOW_LOCAL"
};
-UBool
+UBool
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;
}
/*
* bug 4100311
*/
-void
+void
CalendarRegressionTest::test4100311()
{
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
+
+void
+CalendarRegressionTest::Test9019()
+{
+ UErrorCode status = U_ZERO_ERROR;
+ 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);
+ 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)
{
UErrorCode status = U_ZERO_ERROR;
/**
* @bug 4031502
*/
-void
-CalendarRegressionTest::test4031502()
+void
+CalendarRegressionTest::test4031502()
{
// This bug actually occurs on Windows NT as well, and doesn't
// require the host zone to be set; it can be set in Java.
UErrorCode status = U_ZERO_ERROR;
- int32_t count = 0;
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);
}
delete cal;
}
- if (bad)
+ if (bad)
errln("TimeZone problems with GC");
// delete [] ids; // TODO: bad APIs
delete ids;
/**
* @bug 4035301
*/
-void CalendarRegressionTest::test4035301()
+void CalendarRegressionTest::test4035301()
{
UErrorCode status = U_ZERO_ERROR;
GregorianCalendar *c = new GregorianCalendar(98, 8, 7,status);
c->before(*c,status) ||
*c != *c ||
*c != *d)
- errln("Fail");
+ dataerrln("Fail");
delete c;
delete d;
}
/**
* @bug 4040996
*/
-void CalendarRegressionTest::test4040996()
+void CalendarRegressionTest::test4040996()
{
int32_t count = 0;
StringEnumeration* ids = TimeZone::createEnumeration(-8 * 60 * 60 * 1000);
- UErrorCode status = U_ZERO_ERROR;
+ 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);
logln(UnicodeString("MONTH: ") + calendar->get(UCAL_MONTH, status));
- logln(UnicodeString("DAY_OF_MONTH: ") +
+ logln(UnicodeString("DAY_OF_MONTH: ") +
calendar->get(UCAL_DATE, status));
logln(UnicodeString("MINUTE: ") + calendar->get(UCAL_MINUTE, status));
logln(UnicodeString("SECOND: ") + calendar->get(UCAL_SECOND, status));
//instead of the date it was set to.
//This happens when adding MILLISECOND or MINUTE also
logln(UnicodeString("MONTH: ") + calendar->get(UCAL_MONTH, status));
- logln(UnicodeString("DAY_OF_MONTH: ") +
+ logln(UnicodeString("DAY_OF_MONTH: ") +
calendar->get(UCAL_DATE, status));
logln(UnicodeString("MINUTE: ") + calendar->get(UCAL_MINUTE, status));
logln(UnicodeString("SECOND: ") + calendar->get(UCAL_SECOND, status));
/**
* @bug 4051765
*/
-void CalendarRegressionTest::test4051765()
+void CalendarRegressionTest::test4051765()
{
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;
}
logln("ERA: " + Calendar::get(Calendar::ERA));
logln("YEAR: " + Calendar::get(Calendar::YEAR));
logln("MONTH: " + Calendar::get(Calendar::MONTH));
- logln("WEEK_OF_YEAR: " +
+ logln("WEEK_OF_YEAR: " +
Calendar::get(Calendar::WEEK_OF_YEAR));
- logln("WEEK_OF_MONTH: " +
+ logln("WEEK_OF_MONTH: " +
Calendar::get(Calendar::WEEK_OF_MONTH));
logln("DATE: " + Calendar::get(Calendar::DATE));
- logln("DAY_OF_MONTH: " +
+ logln("DAY_OF_MONTH: " +
Calendar::get(Calendar::DAY_OF_MONTH));
logln("DAY_OF_YEAR: " + Calendar::get(Calendar::DAY_OF_YEAR));
logln("DAY_OF_WEEK: " + Calendar::get(Calendar::DAY_OF_WEEK));
+ (Calendar::get(Calendar::ZONE_OFFSET)/(60*60*1000)));
logln("DST_OFFSET: "
+ (Calendar::get(Calendar::DST_OFFSET)/(60*60*1000)));
- calendar = new GregorianCalendar(1997,3,10);
- Calendar::getTime();
+ calendar = new GregorianCalendar(1997,3,10);
+ Calendar::getTime();
logln("April 10, 1997");
logln("ERA: " + Calendar::get(Calendar::ERA));
logln("YEAR: " + Calendar::get(Calendar::YEAR));
logln("MONTH: " + Calendar::get(Calendar::MONTH));
- logln("WEEK_OF_YEAR: " +
+ logln("WEEK_OF_YEAR: " +
Calendar::get(Calendar::WEEK_OF_YEAR));
- logln("WEEK_OF_MONTH: " +
+ logln("WEEK_OF_MONTH: " +
Calendar::get(Calendar::WEEK_OF_MONTH));
logln("DATE: " + Calendar::get(Calendar::DATE));
- logln("DAY_OF_MONTH: " +
+ logln("DAY_OF_MONTH: " +
Calendar::get(Calendar::DAY_OF_MONTH));
logln("DAY_OF_YEAR: " + Calendar::get(Calendar::DAY_OF_YEAR));
logln("DAY_OF_WEEK: " + Calendar::get(Calendar::DAY_OF_WEEK));
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;
}
-
+
gc->set(1997, 3, 1, 15, 16, 17); // April 1, 1997
gc->set(UCAL_HOUR, 0);
/**
* @bug 4061476
*/
-void CalendarRegressionTest::test4061476()
+void CalendarRegressionTest::test4061476()
{
UErrorCode status = U_ZERO_ERROR;
SimpleDateFormat *fmt = new SimpleDateFormat(UnicodeString("ddMMMyy"), Locale::getUK(),status);
- Calendar *cal = Calendar::createInstance(TimeZone::createTimeZone("GMT"),
+ 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;
/**
* @bug 4070502
*/
-void CalendarRegressionTest::test4070502()
+void CalendarRegressionTest::test4070502()
{
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;
}
* <p>
* @param date The date to start from
*/
-UDate
-CalendarRegressionTest::getAssociatedDate(UDate d, UErrorCode& status)
+UDate
+CalendarRegressionTest::getAssociatedDate(UDate d, UErrorCode& status)
{
GregorianCalendar *cal = new GregorianCalendar(status);
cal->setTime(d,status);
- //cal.add(field, amount); //<-- PROBLEM SEEN WITH field = DATE,MONTH
+ //cal.add(field, amount); //<-- PROBLEM SEEN WITH field = DATE,MONTH
// cal.getTime(); // <--- REMOVE THIS TO SEE BUG
for (;;) {
int32_t wd = cal->get(UCAL_DAY_OF_WEEK, status);
else
break;
}
-
+
UDate dd = cal->getTime(status);
delete cal;
return dd;
/**
* @bug 4071197
*/
-void CalendarRegressionTest::test4071197()
+void CalendarRegressionTest::test4071197()
{
dowTest(FALSE);
dowTest(TRUE);
}
-void CalendarRegressionTest::dowTest(UBool lenient)
+void CalendarRegressionTest::dowTest(UBool lenient)
{
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;
}
//logln(cal.getTime().toString());
if (min != UCAL_SUNDAY || max != UCAL_SATURDAY)
errln("FAIL: Min/max bad");
- if (dow < min || dow > max)
- errln(UnicodeString("FAIL: Day of week ") + dow + " out of range");
- if (dow != UCAL_SUNDAY)
- errln("FAIL: Day of week should be SUNDAY Got " + dow);
+ 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(UnicodeString("FAIL: Day of week should be SUNDAY Got ") + dow);
if(U_FAILURE(status)) {
errln("Error checking Calendar: %s", u_errorName(status));
return;
}
- if(cal->getActualMinimum(UCAL_DAY_OF_WEEK) != min) {
+ if(cal->getActualMinimum(UCAL_DAY_OF_WEEK, status) != min) {
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");
}
errln("Error getting actual minimum: %s", u_errorName(status));
return;
}
-
+
delete cal;
}
/**
* @bug 4071385
*/
-void CalendarRegressionTest::test4071385()
+void CalendarRegressionTest::test4071385()
{
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;
}
/**
* @bug 4073929
*/
-void CalendarRegressionTest::test4073929()
+void CalendarRegressionTest::test4073929()
{
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;
}
+ logln("foo1@%.0f - %d-%d-%d %d:%d:%d.%ds\n", foo1->getTime(status),
+ foo1->get(UCAL_YEAR, status),
+ foo1->get(UCAL_MONTH, status),
+ foo1->get(UCAL_DATE, status),
+ foo1->get(UCAL_HOUR, status),
+ foo1->get(UCAL_MINUTE, status),
+ foo1->get(UCAL_SECOND, status),
+ foo1->get(UCAL_MILLISECOND,status));
+ foo1->add(UCAL_DATE, + 1, status);
+ logln("foo1@%.0f - %d-%d-%d %d:%d:%d.%ds after +\n", foo1->getTime(status),
+ foo1->get(UCAL_YEAR, status),
+ foo1->get(UCAL_MONTH, status),
+ foo1->get(UCAL_DATE, status),
+ foo1->get(UCAL_HOUR, status),
+ foo1->get(UCAL_MINUTE, status),
+ foo1->get(UCAL_SECOND, status),
+ foo1->get(UCAL_MILLISECOND ,status));
+ foo1->add(UCAL_DATE, - 1, status);
+ logln("foo1@%.0f - %d-%d-%d %d:%d:%d.%ds after -\n", foo1->getTime(status),
+ foo1->get(UCAL_YEAR, status),
+ foo1->get(UCAL_MONTH, status),
+ foo1->get(UCAL_DATE, status),
+ foo1->get(UCAL_HOUR, status),
+ foo1->get(UCAL_MINUTE, status),
+ foo1->get(UCAL_SECOND, status),
+ foo1->get(UCAL_MILLISECOND, status));
+
foo1->add(UCAL_DATE, + 1, status);
int32_t testyear = foo1->get(UCAL_YEAR, status);
int32_t testmonth = foo1->get(UCAL_MONTH, status);
/**
* @bug 4083167
*/
-void CalendarRegressionTest::test4083167()
+void CalendarRegressionTest::test4083167()
{
UErrorCode status = U_ZERO_ERROR;
TimeZone *saveZone = TimeZone::createDefault();
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;
}
int32_t sec = cal->get(UCAL_SECOND, status);
int32_t msec = cal->get(UCAL_MILLISECOND, status);
double firstMillisInDay = hr * 3600000 + min * 60000 + sec * 1000 + msec;
-
+
//logln("Current time: " + firstDate.toString());
for (int32_t validity=0; validity<30; validity++) {
sec = cal->get(UCAL_SECOND, status);
msec = cal->get(UCAL_MILLISECOND, status);
double millisInDay = hr * 3600000.0 + min * 60000.0 + sec * 1000.0 + msec;
- if (firstMillisInDay != millisInDay)
+ if (firstMillisInDay != millisInDay)
errln(UnicodeString("Day has shifted ") + lastDate);
}
//}
/**
* @bug 4086724
*/
-void CalendarRegressionTest::test4086724()
+void CalendarRegressionTest::test4086724()
{
UErrorCode status = U_ZERO_ERROR;
SimpleDateFormat *date;
TimeZone *saveZone = TimeZone::createDefault();
Locale saveLocale = Locale::getDefault();
//try {
- Locale::setDefault(Locale::getUK(),status);
+ Locale::setDefault(Locale::getUK(),status);
TimeZone *newZone = TimeZone::createTimeZone("GMT");
TimeZone::setDefault(*newZone);
- date = new SimpleDateFormat(UnicodeString("dd MMM yyy (zzzz) 'is in week' ww"),status);
- Calendar *cal = Calendar::createInstance(status);
+ 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;
return;
}
- cal->set(1997,UCAL_SEPTEMBER,30);
- UDate now = cal->getTime(status);
+ cal->set(1997,UCAL_SEPTEMBER,30);
+ UDate now = cal->getTime(status);
UnicodeString temp;
FieldPosition pos(FieldPosition::DONT_CARE);
- logln(date->format(now, temp, pos));
- cal->set(1997,UCAL_JANUARY,1);
- now=cal->getTime(status);
- logln(date->format(now,temp, pos));
- cal->set(1997,UCAL_JANUARY,8);
- now=cal->getTime(status);
- logln(date->format(now,temp, pos));
- cal->set(1996,UCAL_DECEMBER,31);
- now=cal->getTime(status);
- logln(date->format(now,temp, pos));
+ logln(date->format(now, temp, pos));
+ cal->set(1997,UCAL_JANUARY,1);
+ now=cal->getTime(status);
+ logln(date->format(now,temp, pos));
+ cal->set(1997,UCAL_JANUARY,8);
+ now=cal->getTime(status);
+ logln(date->format(now,temp, pos));
+ cal->set(1996,UCAL_DECEMBER,31);
+ now=cal->getTime(status);
+ logln(date->format(now,temp, pos));
//}
//finally {
Locale::setDefault(saveLocale,status);
*/
void CalendarRegressionTest::test4092362() {
UErrorCode status = U_ZERO_ERROR;
- GregorianCalendar *cal1 = new GregorianCalendar(1997, 10, 11, 10, 20, 40,status);
- /*cal1.set( Calendar::YEAR, 1997 );
- cal1.set( Calendar::MONTH, 10 );
- cal1.set( Calendar::DATE, 11 );
- cal1.set( Calendar::HOUR, 10 );
- cal1.set( Calendar::MINUTE, 20 );
+ 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 );
+ cal1.set( Calendar::HOUR, 10 );
+ cal1.set( Calendar::MINUTE, 20 );
cal1.set( Calendar::SECOND, 40 ); */
- 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++ );
-
- GregorianCalendar *cal2 = new GregorianCalendar(1997, 10, 11, 10, 20, 40,status);
- /*cal2.set( Calendar::YEAR, 1997 );
- cal2.set( Calendar::MONTH, 10 );
- cal2.set( Calendar::DATE, 11 );
- cal2.set( Calendar::HOUR, 10 );
- cal2.set( Calendar::MINUTE, 20 );
+ 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++)
+ ;
+
+ GregorianCalendar *cal2 = new GregorianCalendar(1997, 10, 11, 10, 20, 40,status);
+ /*cal2.set( Calendar::YEAR, 1997 );
+ cal2.set( Calendar::MONTH, 10 );
+ cal2.set( Calendar::DATE, 11 );
+ cal2.set( Calendar::HOUR, 10 );
+ cal2.set( Calendar::MINUTE, 20 );
cal2.set( Calendar::SECOND, 40 ); */
- logln( UnicodeString(" Cal2 = ") + cal2->getTime(status) );
- logln( UnicodeString(" Cal2 time in ms = ") + cal2->get(UCAL_MILLISECOND,status) );
- if( *cal1 != *cal2 )
+ logln( UnicodeString(" Cal2 = ") + cal2->getTime(status) );
+ logln( UnicodeString(" Cal2 time in ms = ") + cal2->get(UCAL_MILLISECOND,status) );
+ if( *cal1 != *cal2 )
errln("Fail: Milliseconds randomized");
delete cal1;
/**
* @bug 4095407
*/
-void CalendarRegressionTest::test4095407()
+void CalendarRegressionTest::test4095407()
{
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;
}
/**
* @bug 4096231
*/
-void CalendarRegressionTest::test4096231()
+void CalendarRegressionTest::test4096231()
{
UErrorCode status = U_ZERO_ERROR;
TimeZone *GMT = TimeZone::createTimeZone("GMT");
TimeZone *PST = TimeZone::createTimeZone("PST");
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
+ // represented time. The old API, pre 1.2.2a requires
// setTime to be called in order to update the time fields after the time
// zone has been set.
int32_t h1,h2;
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),
/**
* @bug 4096539
*/
-void CalendarRegressionTest::test4096539()
+void CalendarRegressionTest::test4096539()
{
UErrorCode status = U_ZERO_ERROR;
int32_t y [] = {31,28,31,30,31,30,31,31,30,31,30,31};
for (int32_t x=0;x<12;x++) {
- GregorianCalendar *gc = new
+ 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)+
errln(UnicodeString("Fail: Want ") + m + " Got " + m2);
delete gc;
}
-
+
}
/**
* @bug 4100311
*/
-void CalendarRegressionTest::test41003112()
+void CalendarRegressionTest::test41003112()
{
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;
}
/**
* @bug 4103271
*/
-void CalendarRegressionTest::test4103271()
+void CalendarRegressionTest::test4103271()
{
UErrorCode status = U_ZERO_ERROR;
- SimpleDateFormat sdf(status);
- int32_t numYears=40, startYear=1997, numDays=15;
- UnicodeString output, testDesc, str, str2;
- GregorianCalendar *testCal = (GregorianCalendar*)Calendar::createInstance(status);
+ SimpleDateFormat sdf(status);
+ int32_t numYears=40, startYear=1997, numDays=15;
+ 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;
}
testCal->clear();
- sdf.adoptCalendar(testCal);
- sdf.applyPattern("EEE dd MMM yyyy 'WOY'ww'-'YYYY 'DOY'DDD");
+ sdf.adoptCalendar(testCal);
+ sdf.applyPattern("EEE dd MMM yyyy 'WOY'ww'-'YYYY 'DOY'DDD");
UBool fail = FALSE;
- for (int32_t firstDay=1; firstDay<=2; firstDay++) {
- for (int32_t minDays=1; minDays<=7; minDays++) {
- testCal->setMinimalDaysInFirstWeek((uint8_t)minDays);
- testCal->setFirstDayOfWeek((UCalendarDaysOfWeek)firstDay);
- testDesc = (UnicodeString("Test") + firstDay + minDays);
+ for (int32_t firstDay=1; firstDay<=2; firstDay++) {
+ for (int32_t minDays=1; minDays<=7; minDays++) {
+ testCal->setMinimalDaysInFirstWeek((uint8_t)minDays);
+ testCal->setFirstDayOfWeek((UCalendarDaysOfWeek)firstDay);
+ testDesc = (UnicodeString("Test") + firstDay + minDays);
logln(testDesc + " => 1st day of week=" +
firstDay +
", minimum days in first week=" +
- minDays);
- for (int32_t j=startYear; j<=startYear+numYears; j++) {
- testCal->set(j,11,25);
- for(int32_t i=0; i<numDays; i++) {
- testCal->add(UCAL_DATE,1,status);
- UnicodeString calWOY;
+ minDays);
+ for (int32_t j=startYear; j<=startYear+numYears; j++) {
+ testCal->set(j,11,25);
+ for(int32_t i=0; i<numDays; i++) {
+ testCal->add(UCAL_DATE,1,status);
+ UnicodeString calWOY;
int32_t actWOY = testCal->get(UCAL_WEEK_OF_YEAR,status);
if (actWOY < 1 || actWOY > 53) {
- UDate d = testCal->getTime(status);
+ UDate d = testCal->getTime(status);
//calWOY = String.valueOf(actWOY);
UnicodeString temp;
FieldPosition pos(FieldPosition::DONT_CARE);
- output = testDesc + " - " + sdf.format(d,temp,pos) + "\t";
- output = output + "\t" + actWOY;
- logln(output);
+ output = testDesc + " - " + sdf.format(d,temp,pos) + "\t";
+ output = output + "\t" + actWOY;
+ logln(output);
fail = TRUE;
}
- }
- }
- }
- }
+ }
+ }
+ }
+ }
int32_t DATA [] = {
3, 52, 52, 52, 52, 52, 52, 52,
fail = TRUE;
}
logln("");
-
+
// Now compute the time from the fields, and make sure we
// get the same answer back. This is a round-trip test.
UDate save = testCal->getTime(status);
testCal->add(UCAL_DATE, 1,status);
}
}
-
// Test field disambiguation with a few special hard-coded cases.
// This shouldn't fail if the above cases aren't failing.
int32_t DISAM_int [] = {
makeDate(1998, UCAL_DECEMBER, 31),
makeDate(1999, UCAL_JANUARY, 1)
};
-
+
testCal->setMinimalDaysInFirstWeek(3);
testCal->setFirstDayOfWeek(UCAL_SUNDAY);
int32_t i = 0;
"-DOW" + dow + " expect:" + sdf.format(exp, str) +
" got:" + sdf.format(got, str2));
if (got != exp) {
- log(" FAIL");
+ log(" FAIL (%s:%d, i=%d)", __FILE__, __LINE__, i);
+ logln(CalendarTest::calToStr(*testCal));
+ testCal->setTime(exp, status);
+ logln(CalendarTest::calToStr(*testCal) + UnicodeString( " <<< expected "));
fail = TRUE;
}
logln("");
}
logln("");
}
-
// Now try adding and rolling
UDate ADDROLL_date [] = {
makeDate(1998, UCAL_DECEMBER, 25), makeDate(1999, UCAL_JANUARY, 1),
UDate after = ADDROLL_date[i+1];
testCal->setTime(before,status);
- if (ADDROLL_bool[i/2])
+ if (ADDROLL_bool[i/2])
testCal->add(UCAL_WEEK_OF_YEAR, amount,status);
- else
+ else
testCal->roll(UCAL_WEEK_OF_YEAR, amount,status);
UDate got = testCal->getTime(status);
str.remove();
str2.remove();
- log((ADDROLL_bool[i/2]? UnicodeString("add(WOY,"):UnicodeString("roll(WOY,")) +
- amount + ") " + sdf.format(before, str) + " => " +
- sdf.format(got, str2));
+ UnicodeString opTypeStr;
+ if (ADDROLL_bool[i/2]) {
+ opTypeStr = UnicodeString("add(WOY,", "");
+ } else {
+ opTypeStr = UnicodeString("roll(WOY,", "");
+ }
+ log(opTypeStr + amount + ") " + sdf.format(before, str) + " => " +
+ sdf.format(got, str2));
if (after != got) {
str.remove();
logln(UnicodeString(" exp:") + sdf.format(after, str) + " FAIL");
else logln(" ok");
testCal->setTime(after,status);
- if (ADDROLL_bool[i/2])
+ if (ADDROLL_bool[i/2])
testCal->add(UCAL_WEEK_OF_YEAR, -amount,status);
- else
+ else
testCal->roll(UCAL_WEEK_OF_YEAR, -amount,status);
got = testCal->getTime(status);
str.remove();
str2.remove();
- log((ADDROLL_bool[i/2]?UnicodeString("add(WOY,"):UnicodeString("roll(WOY,")) +
- (-amount) + ") " + sdf.format(after, str) + " => " +
- sdf.format(got, str2));
+ log(opTypeStr + (-amount) + ") " + sdf.format(after, str) + " => " +
+ sdf.format(got, str2));
if (before != got) {
str.remove();
logln(UnicodeString(" exp:") + sdf.format(before, str) + " FAIL");
}
else logln(" ok");
}
-
- if (fail)
+ if (fail)
errln("Fail: Week of year misbehaving");
-}
+}
/**
* @bug 4106136
*/
-void CalendarRegressionTest::test4106136()
+void CalendarRegressionTest::test4106136()
{
UErrorCode status = U_ZERO_ERROR;
Locale saveLocale = Locale::getDefault();
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());
}
}
//}
/**
* @bug 4108764
*/
-void CalendarRegressionTest::test4108764()
+void CalendarRegressionTest::test4108764()
{
UErrorCode status = U_ZERO_ERROR;
- Calendar *cal = Calendar::createInstance(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;
return;
}
cal->setTime(d11,status);
- cal->clear( UCAL_MINUTE );
- logln(UnicodeString("") + cal->getTime(status));
+ cal->clear( UCAL_MINUTE );
+ logln(UnicodeString("") + cal->getTime(status));
if (cal->getTime(status) != d01)
errln("Fail: clear(MINUTE) broken");
- cal->set( UCAL_SECOND, 0 );
- logln(UnicodeString("") + cal->getTime(status));
+ cal->set( UCAL_SECOND, 0 );
+ logln(UnicodeString("") + cal->getTime(status));
if (cal->getTime(status) != d00)
errln("Fail: set(SECOND, 0) broken");
cal->setTime(d11,status);
- cal->set( UCAL_SECOND, 0 );
- logln(UnicodeString("") + cal->getTime(status));
+ cal->set( UCAL_SECOND, 0 );
+ logln(UnicodeString("") + cal->getTime(status));
if (cal->getTime(status) != d10)
errln("Fail: set(SECOND, 0) broken #2");
- cal->clear( UCAL_MINUTE );
- logln(UnicodeString("") + cal->getTime(status));
+ cal->clear( UCAL_MINUTE );
+ logln(UnicodeString("") + cal->getTime(status));
if (cal->getTime(status) != d00)
errln("Fail: clear(MINUTE) broken #2");
cal->clear();
- logln(UnicodeString("") + cal->getTime(status));
+ logln(UnicodeString("") + cal->getTime(status));
if (cal->getTime(status) != epoch)
errln(UnicodeString("Fail: clear() broken Want ") + epoch);
/**
* @bug 4114578
*/
-void CalendarRegressionTest::test4114578()
+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;
}
UDate cease = makeDate(1998, UCAL_OCTOBER, 25, 0, 0) + 2*ONE_HOUR;
UBool fail = FALSE;
-
+
const int32_t ADD = 1;
const int32_t ROLL = 2;
UDate date = DATA[i];
int32_t amt = (int32_t) DATA[i+2];
double expectedChange = DATA[i+3];
-
+
log(UnicodeString("") + date);
cal->setTime(date,status);
* @bug 4118384
* Make sure maximum for HOUR field is 11, not 12.
*/
-void CalendarRegressionTest::test4118384()
+void CalendarRegressionTest::test4118384()
{
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;
}
}
delete cal;
- cal = Calendar::createInstance(Locale("th_TH_TRADITIONAL"),status);
+ cal = Calendar::createInstance(Locale("th_TH@calendar=buddhist"),status);
// test deprecated functions
if (cal->getLeastMaximum(Calendar::HOUR) != 11 ||
cal->getMaximum(Calendar::HOUR) != 11) {
delete cal;
// test deprecated functions
- cal = Calendar::createInstance(Locale("ja_JP_TRADITIONAL"),status);
+ cal = Calendar::createInstance(Locale("ja_JP@calendar=japanese"),status);
if (cal->getLeastMaximum(Calendar::HOUR) != 11 ||
cal->getMaximum(Calendar::HOUR) != 11) {
errln("Fail: Japanese:[deprecated functions] maximum of HOUR field should be 11\n");
* @bug 4125881
* Check isLeapYear for BC years.
*/
-void CalendarRegressionTest::test4125881()
+void CalendarRegressionTest::test4125881()
{
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)
* @bug 4141665
* GregorianCalendar::equals() ignores cutover date
*/
-void CalendarRegressionTest::test4141665()
+void CalendarRegressionTest::test4141665()
{
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;
}
* Bug states that ArrayIndexOutOfBoundsException is thrown by GregorianCalendar::roll()
* when IllegalArgumentException should be.
*/
-void CalendarRegressionTest::test4142933()
+void CalendarRegressionTest::test4142933()
{
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;
}
//catch (Exception e) {
//errln("Test failed. Unexpected exception is thrown: " + e);
//e.printStackTrace();
- //}
+ //}
delete calendar;
}
* report to therefore only check the behavior of a calendar with a zero raw
* offset zone.
*/
-void CalendarRegressionTest::test4145158()
+void CalendarRegressionTest::test4145158()
{
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;
}
calendar->setTime(makeDate(INT32_MAX),status);
int32_t year2 = calendar->get(UCAL_YEAR,status);
int32_t era2 = calendar->get(UCAL_ERA,status);
-
+
if (year1 == year2 && era1 == era2) {
errln("Fail: Long.MIN_VALUE or Long.MAX_VALUE wrapping around");
}
*/
// {sfb} this is not directly applicable in C++, since all
// possible doubles are not representable by our Calendar.
-// In Java, all longs are representable.
+// In Java, all longs are representable.
// We can determine limits programmatically
// Using DBL_MAX is a bit of a hack, since for large doubles
// Calendar gets squirrely and doesn't behave in any sort
// of linear fashion (ie years jump around, up/down, etc) for a
// small change in millis.
-void CalendarRegressionTest::test4145983()
+void CalendarRegressionTest::test4145983()
{
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;
}
* report test was written. In reality the bug is restricted to the DAY_OF_YEAR
* field. - liu 6/29/98
*/
-void CalendarRegressionTest::test4147269()
+void CalendarRegressionTest::test4147269()
{
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;
}
// use getActualMaximum(), since that's too costly.
int32_t max = calendar->getMaximum((UCalendarDateFields)field);
int32_t value = max+1;
- calendar->set((UCalendarDateFields)field, value);
+ calendar->set((UCalendarDateFields)field, value);
//try {
calendar->getTime(status); // Force time computation
// We expect an exception to be thrown. If we fall through
", date before: " + date +
", date after: " + calendar->getTime(status) +
", value: " + value + " (max = " + max +")");
- //} catch (IllegalArgumentException e) {}
+ //} catch (IllegalArgumentException e) {}
}
delete calendar;
* doesn't behave as a pure Julian calendar.
* CANNOT REPRODUCE THIS BUG
*/
-void
-CalendarRegressionTest::Test4149677()
+void
+CalendarRegressionTest::Test4149677()
{
UErrorCode status = U_ZERO_ERROR;
- TimeZone *zones [] = {
+ TimeZone *zones [] = {
TimeZone::createTimeZone("GMT"),
TimeZone::createTimeZone("PST"),
- TimeZone::createTimeZone("EAT")
+ TimeZone::createTimeZone("EAT")
};
if(U_FAILURE(status)) {
errln("Couldn't create zones");
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;
}
if(U_FAILURE(status))
errln("setGregorianChange failed");
// to obtain a pure Julian calendar
-
+
UBool is100Leap = calendar->isLeapYear(100);
if (!is100Leap) {
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;
}
-
+
// no need for cleanup- zones were adopted
}
* Calendar and Date HOUR broken. If HOUR is out-of-range, Calendar
* and Date classes will misbehave.
*/
-void
-CalendarRegressionTest::Test4162587()
+void
+CalendarRegressionTest::Test4162587()
{
UErrorCode status = U_ZERO_ERROR;
TimeZone *savedef = TimeZone::createDefault();
TimeZone *tz = TimeZone::createTimeZone("PST");
//TimeZone::adoptDefault(tz);
TimeZone::setDefault(*tz);
-
+
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;
-
+
for(int32_t i=0; i<5; ++i) {
if (i>0) logln("---");
* @bug 4165343
* Adding 12 months behaves differently from adding 1 year
*/
-void
-CalendarRegressionTest::Test4165343()
+void
+CalendarRegressionTest::Test4165343()
{
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);
if(U_FAILURE(status))
errln("Couldn't getTime (1)");
logln(UnicodeString("init date: ") + start);
- calendar->add(UCAL_MONTH, 12, status);
+ calendar->add(UCAL_MONTH, 12, status);
if(U_FAILURE(status))
errln("Couldn't add(MONTH, 12)");
UDate date1 = calendar->getTime(status);
* @bug 4166109
* GregorianCalendar.getActualMaximum() does not account for first day of week.
*/
-void
-CalendarRegressionTest::Test4166109()
+void
+CalendarRegressionTest::Test4166109()
{
/* Test month:
*
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);
calendar->setMinimalDaysInFirstWeek(1);
- logln(UnicodeString("Date: ") + calendar->getTime(status));
+ logln(UnicodeString("Date: ") + calendar->getTime(status)); // 888817448000
int32_t firstInMonth = calendar->get(UCAL_DATE, status);
if(U_FAILURE(status))
for(int32_t firstInWeek = UCAL_SUNDAY; firstInWeek <= UCAL_SATURDAY; firstInWeek++) {
calendar->setFirstDayOfWeek((UCalendarDaysOfWeek)firstInWeek);
- int32_t returned = calendar->getActualMaximum(field);
+ int32_t returned = calendar->getActualMaximum(field, status);
int32_t expected = (31 + ((firstInMonth - firstInWeek + 7)% 7) + 6) / 7;
logln(UnicodeString("First day of week = ") + firstInWeek +
- " getActualMaximum(WEEK_OF_MONTH) = " + returned +
+ " getActualMaximum(WEEK_OF_MONTH, status) = " + returned +
" expected = " + expected +
((returned == expected) ? " ok" : " FAIL"));
* @bug 4167060
* Calendar.getActualMaximum(YEAR) works wrong.
*/
-void
-CalendarRegressionTest::Test4167060()
+void
+CalendarRegressionTest::Test4167060()
{
UErrorCode status = U_ZERO_ERROR;
UCalendarDateFields field = UCAL_YEAR;
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;
}
GregorianCalendar *calendar = calendars[j];
if (k == 1) {
calendar->setGregorianChange(EARLIEST_SUPPORTED_MILLIS, status);
- }
+ }
else if (k == 2) {
calendar->setGregorianChange(LATEST_SUPPORTED_MILLIS, status);
}
if(U_FAILURE(status))
errln("getTime() failed");
- int32_t maxYear = calendar->getActualMaximum(field);
+ int32_t maxYear = calendar->getActualMaximum(field, status);
UnicodeString temp;
logln(UnicodeString("maxYear: ") + maxYear + " for " + format->format(calendar->getTime(status), temp));
temp.remove();
" => " + format->format(dateAfter, temp));
if (valid && newYear != years[i]) {
errln(UnicodeString(" FAIL: ") + newYear + " should be valid; date, month and time shouldn't change");
- }
+ }
// {sfb} this next line is a hack, but it should work since if a
// double has an exponent, adding 1 should not yield the same double
else if (!valid && /*newYear == years[i]*/ dateAfter + 1.0 == dateAfter) {
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;
}
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;
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);
// Get the Gregorian cutover
UDate cutover = cal.getGregorianChange();
+ UDate days = ONE_DAY;
+ days = cutover/days;
logln(UnicodeString("Cutover: {") +
- fmt.format(cutover, temp) + "}(" + cutover/ONE_DAY + ")");
+ fmt.format(cutover, temp) + "}(epoch days-" + (int)days + ", jd" + (2440588 + days) +")");
// Check woy and doy handling. Reference data:
/* w40 d274 Mon 1 Oct 1582
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
cal.set(1582, UCAL_OCTOBER, DOY_DATA[i]);
int32_t woy = cal.get(UCAL_WEEK_OF_YEAR, status);
int32_t doy = cal.get(UCAL_DAY_OF_YEAR, status);
+ int32_t dow = cal.get(UCAL_DAY_OF_WEEK, status);
if (U_FAILURE(status)) {
errln("Error: get() failed");
break;
}
- if (woy != DOY_DATA[i+1] || doy != DOY_DATA[i+2]) {
+ if (woy != DOY_DATA[i+1] || doy != DOY_DATA[i+2] || dow != DOY_DATA[i+3]) {
errln((UnicodeString)"Fail: expect woy=" + DOY_DATA[i+1] +
- ", doy=" + DOY_DATA[i+2] + " on " +
- fmt.format(cal.getTime(status), temp.remove()));
+ ", doy=" + DOY_DATA[i+2] + ", dow=" + DOY_DATA[i+3] + " on " +
+ fmt.format(cal.getTime(status), temp.remove()) +
+ " set(1582,OCTOBER, " + DOY_DATA[i] + ")");
+ logln(CalendarTest::calToStr(cal));
status = U_ZERO_ERROR;
+ } else {
+ logln((UnicodeString)"PASS: expect woy=" + DOY_DATA[i+1] +
+ ", doy=" + DOY_DATA[i+2] + ", dow=" + DOY_DATA[i+3] + " on " +
+ fmt.format(cal.getTime(status), temp.remove()));
+ logln(CalendarTest::calToStr(cal));
+ status = U_ZERO_ERROR;
}
-
// Test fields->time for WOY
cal.clear();
cal.set(UCAL_YEAR, 1582);
" dow=" + DOY_DATA[i+3] + " => " +
fmt.format(cal.getTime(status), temp.remove()) +
", expected 1582 Oct " + DOY_DATA[i]);
+ logln(CalendarTest::calToStr(cal));
status = U_ZERO_ERROR;
}
// { 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) {
}
status = U_ZERO_ERROR;
int32_t amount = DATA[i].amount * (sign==MINUS?-1:1);
- UDate date = cutover +
+ UDate date = cutover +
(sign==PLUS ? DATA[i].before : DATA[i].after);
- UDate expected = cutover +
+ UDate expected = cutover +
(sign==PLUS ? DATA[i].after : DATA[i].before);
cal.setTime(date, status);
if (U_FAILURE(status)) {
continue;
}
if (result == expected) {
- logln((UnicodeString)"Ok: {" +
+ logln((UnicodeString)"Ok: {" +
fmt.format(date, temp.remove()) +
"}(" + date/ONE_DAY +
- (action==ADD?") add ":") roll ") +
+ (action==ADD?") add ":") roll ") +
amount + " " + FIELD_NAME[DATA[i].field] + " -> {" +
fmt.format(result, temp2.remove()) +
- "}(" + result/ONE_DAY + ")");
+ "}(" + result/ONE_DAY + ")");
} else {
- errln((UnicodeString)"FAIL: {" +
+ errln((UnicodeString)"FAIL: {" +
fmt.format(date, temp.remove()) +
"}(" + date/ONE_DAY +
- (action==ADD?") add ":") roll ") +
+ (action==ADD?") add ":") roll ") +
amount + " " + FIELD_NAME[DATA[i].field] + " -> {" +
fmt.format(result, temp2.remove()) +
"}(" + result/ONE_DAY + "), expect {" +
}
}
}
-
+
/**
* Test fieldDifference().
*/
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)) {
- 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];
if (failure(ec, "fieldDifference"))
break;
- {
+ {
Calendar *cal2 = cal.clone();
UErrorCode ec2 = U_ZERO_ERROR;
- cal2->setTime(date1, ec2);
+ cal2->setTime(date1, ec2);
int32_t dy2 = cal2->fieldDifference(date2, Calendar::YEAR, ec2);
int32_t dm2 = cal2->fieldDifference(date2, Calendar::MONTH, ec2);
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
// in the first week so that the weeks shift in August 2001.
- // August 2001
+ // August 2001
// Su Mo Tu We Th Fr Sa
// 1 2 3 4
// 5 6 7 8 9 10 11
// 12 13 14 15 16 17 18
// 19 20 21 22 23 24 25
- // 26 27 28 29 30 31
+ // 26 27 28 29 30 31
for (int32_t pass=0; pass<2; ++pass) {
if (pass==0) {
cal.setFirstDayOfWeek(UCAL_WEDNESDAY);
StringEnumeration *tz = TimeZone::createEnumeration();
if (tz == NULL) {
- errln("FAIL: TimeZone::createEnumeration");
+ dataerrln("FAIL: TimeZone::createEnumeration");
return;
}
errln("FAIL: StringEnumeration::unext");
break;
}
-
+
TimeZone *t = TimeZone::createTimeZone(id);
if (t == NULL) {
errln("FAIL: TimeZone::createTimeZone");
}
if (U_FAILURE(ec)) {
- errln("FAIL: %s", u_errorName(ec));
+ dataerrln("FAIL: %s", u_errorName(ec));
}
delete tz;
cal->clear();
cal->set(UCAL_YEAR, y);
-
+
if(m != 0) cal->set(UCAL_MONTH, m);
if(d != 0) cal->set(UCAL_DATE, d);
if(hr != 0) cal->set(UCAL_HOUR, hr);
void CalendarRegressionTest::TestDeprecates(void)
{
UErrorCode status = U_ZERO_ERROR;
- Calendar *c1 = Calendar::createInstance("ja_JP_TRADITIONAL",status);
+ Calendar *c1 = Calendar::createInstance("ja_JP@calendar=japanese",status);
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;
}
status = U_ZERO_ERROR;
c1 = Calendar::createInstance("th_TH_TRADITIONAL",status);
- c2 = Calendar::createInstance("th_TH_TRADITIONAL",status);
+ c2 = Calendar::createInstance("th_TH@calendar=buddhist",status);
if(!c1 || !c2 || U_FAILURE(status)) {
errln("Couldn't create calendars for add of HOUR");
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);
+ }
+}
+
+/**
+ * @bug ticket 13454
+ */
+void CalendarRegressionTest::TestPersianCalOverflow(void) {
+ const char* localeID = "bs_Cyrl@calendar=persian";
+ UErrorCode status = U_ZERO_ERROR;
+ Calendar* cal = Calendar::createInstance(Locale(localeID), status);
+ if(U_FAILURE(status)) {
+ dataerrln("FAIL: Calendar::createInstance for localeID %s: %s", localeID, u_errorName(status));
+ } else {
+ int32_t maxMonth = cal->getMaximum(UCAL_MONTH);
+ int32_t maxDayOfMonth = cal->getMaximum(UCAL_DATE);
+ int32_t jd, month, dayOfMonth;
+ for (jd = 67023580; jd <= 67023584; jd++) { // year 178171, int32_t overflow if jd >= 67023582
+ status = U_ZERO_ERROR;
+ cal->clear();
+ cal->set(UCAL_JULIAN_DAY, jd);
+ month = cal->get(UCAL_MONTH, status);
+ dayOfMonth = cal->get(UCAL_DATE, status);
+ if ( U_FAILURE(status) ) {
+ errln("FAIL: Calendar->get MONTH/DATE for localeID %s, julianDay %d, status %s", localeID, jd, u_errorName(status));
+ } else if (month > maxMonth || dayOfMonth > maxDayOfMonth) {
+ errln("FAIL: localeID %s, julianDay %d; maxMonth %d, got month %d; maxDayOfMonth %d, got dayOfMonth %d",
+ localeID, jd, maxMonth, month, maxDayOfMonth, dayOfMonth);
+ }
+ }
+ delete cal;
+ }
}
+/**
+ * @bug tickets 12661, 13538
+ */
+void CalendarRegressionTest::TestIslamicCalOverflow(void) {
+ const char* localeID = "ar@calendar=islamic-civil";
+ UErrorCode status = U_ZERO_ERROR;
+ Calendar* cal = Calendar::createInstance(Locale(localeID), status);
+ if(U_FAILURE(status)) {
+ dataerrln("FAIL: Calendar::createInstance for localeID %s: %s", localeID, u_errorName(status));
+ } else {
+ int32_t maxMonth = cal->getMaximum(UCAL_MONTH);
+ int32_t maxDayOfMonth = cal->getMaximum(UCAL_DATE);
+ int32_t jd, year, month, dayOfMonth;
+ for (jd = 73530872; jd <= 73530876; jd++) { // year 202002, int32_t overflow if jd >= 73530874
+ status = U_ZERO_ERROR;
+ cal->clear();
+ cal->set(UCAL_JULIAN_DAY, jd);
+ year = cal->get(UCAL_YEAR, status);
+ month = cal->get(UCAL_MONTH, status);
+ dayOfMonth = cal->get(UCAL_DATE, status);
+ if ( U_FAILURE(status) ) {
+ errln("FAIL: Calendar->get YEAR/MONTH/DATE for localeID %s, julianDay %d, status %s", localeID, jd, u_errorName(status));
+ } else if (month > maxMonth || dayOfMonth > maxDayOfMonth) {
+ errln("FAIL: localeID %s, julianDay %d; got year %d; maxMonth %d, got month %d; maxDayOfMonth %d, got dayOfMonth %d",
+ localeID, jd, year, maxMonth, month, maxDayOfMonth, dayOfMonth);
+ }
+ }
+ delete cal;
+ }
+}
#endif /* #if !UCONFIG_NO_FORMATTING */