/********************************************************************
* COPYRIGHT:
- * Copyright (c) 1997-2003, International Business Machines Corporation and
+ * Copyright (c) 1997-2010, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
/*
DateFormat* CalendarTimeZoneTest::fgDateFormat = 0;
Calendar* CalendarTimeZoneTest::fgCalendar = 0;
-UBool CalendarTimeZoneTest::failure(UErrorCode status, const char* msg)
+UBool CalendarTimeZoneTest::failure(UErrorCode status, const char* msg, UBool possibleDataError)
{
if (U_FAILURE(status))
{
- errln(UnicodeString("FAIL: ") + msg + " failed, error " + u_errorName(status));
+ if (possibleDataError) {
+ dataerrln(UnicodeString("FAIL: ") + msg + " failed, error " + u_errorName(status));
+ } else {
+ errcheckln(status, UnicodeString("FAIL: ") + msg + " failed, error " + u_errorName(status));
+ }
return TRUE;
}
return FALSE;
{
delete theFormat;
theFormat = 0;
- errln("FAIL: Could not create SimpleDateFormat");
+ dataerrln("FAIL: Could not create SimpleDateFormat - %s", u_errorName(status));
}
}
{
delete theCalendar;
theCalendar = 0;
- errln("FAIL: Calendar::createInstance failed");
+ dataerrln("FAIL: Calendar::createInstance failed: %s", u_errorName(status));
}
}
return theCalendar;
return str;
}
+UnicodeString&
+CalendarTimeZoneTest::dateToString(UDate d, UnicodeString& str,
+ const TimeZone& tz)
+{
+ str.remove();
+ DateFormat* format = getDateFormat();
+ if (format == 0)
+ {
+ str += "DATE_FORMAT_FAILURE";
+ return str;
+ }
+ TimeZone* save = format->getTimeZone().clone();
+ format->setTimeZone(tz);
+ format->format(d, str);
+ format->adoptTimeZone(save);
+ releaseDateFormat(format);
+ return str;
+}
+
// Utility methods to create a date. This is useful for converting Java constructs
// which create a Date object.
UDate
releaseCalendar(cal);
if (U_FAILURE(status))
{
- errln("FAIL: Calendar::getTime failed");
+ errln("FAIL: Calendar::getTime failed: %s", u_errorName(status));
return 0.0;
}
return dt;