X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/374ca955a76ecab1204ca8bfa63ff9238d998416..4388f060552cc537e71e957d32f35e9d75a61233:/icuSources/test/intltest/dtfmtrtts.cpp?ds=sidebyside diff --git a/icuSources/test/intltest/dtfmtrtts.cpp b/icuSources/test/intltest/dtfmtrtts.cpp index 032b2dbd..a8fd9669 100644 --- a/icuSources/test/intltest/dtfmtrtts.cpp +++ b/icuSources/test/intltest/dtfmtrtts.cpp @@ -1,6 +1,6 @@ /*********************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2004, International Business Machines Corporation + * Copyright (c) 1997-2010, International Business Machines Corporation * and others. All Rights Reserved. ***********************************************************************/ @@ -28,8 +28,10 @@ #define INFINITE 0 #endif +static const UVersionInfo ICU_452 = {4,5,2,0}; + // Define this to test just a single locale -//#define TEST_ONE_LOC "ja_JP_TRADITIONAL" +//#define TEST_ONE_LOC "cs_CZ" // If SPARSENESS is > 0, we don't run each exhaustive possibility. // There are 24 total possible tests per each locale. A SPARSENESS @@ -54,6 +56,7 @@ DateFormatRoundTripTest::runIndexedTest( int32_t index, UBool exec, const char* optionv = (par && *par=='v'); switch (index) { CASE(0,TestDateFormatRoundTrip) + CASE(1, TestCentury) default: name = ""; break; } } @@ -82,6 +85,45 @@ DateFormatRoundTripTest::failure(UErrorCode status, const char* msg, const Unico return FALSE; } +void DateFormatRoundTripTest::TestCentury() +{ + UErrorCode status = U_ZERO_ERROR; + Locale locale("es_PA"); + UnicodeString pattern = "MM/dd/yy hh:mm:ss a z"; + SimpleDateFormat fmt(pattern, locale, status); + if (U_FAILURE(status)) { + dataerrln("Fail: construct SimpleDateFormat: %s", u_errorName(status)); + return; + } + UDate date[] = {-55018555891590.05, 0, 0}; + UnicodeString result[2]; + + fmt.format(date[0], result[0]); + date[1] = fmt.parse(result[0], status); + fmt.format(date[1], result[1]); + date[2] = fmt.parse(result[1], status); + + /* This test case worked OK by accident before. date[1] != date[0], + * because we use -80/+20 year window for 2-digit year parsing. + * (date[0] is in year 1926, date[1] is in year 2026.) result[1] set + * by the first format call returns "07/13/26 07:48:28 p.m. PST", + * which is correct, because DST was not used in year 1926 in zone + * America/Los_Angeles. When this is parsed, date[1] becomes a time + * in 2026, which is "07/13/26 08:48:28 p.m. PDT". There was a zone + * offset calculation bug that observed DST in 1926, which was resolved. + * Before the bug was resolved, result[0] == result[1] was true, + * but after the bug fix, the expected result is actually + * result[0] != result[1]. -Yoshito + */ + /* TODO: We need to review this code and clarify what we really + * want to test here. + */ + //if (date[1] != date[2] || result[0] != result[1]) { + if (date[1] != date[2]) { + errln("Round trip failure: \"%S\" (%f), \"%S\" (%f)", result[0].getBuffer(), date[1], result[1].getBuffer(), date[2]); + } +} + // == void DateFormatRoundTripTest::TestDateFormatRoundTrip() @@ -89,7 +131,10 @@ void DateFormatRoundTripTest::TestDateFormatRoundTrip() UErrorCode status = U_ZERO_ERROR; getFieldCal = Calendar::createInstance(status); - failure(status, "Calendar::createInstance"); + if (U_FAILURE(status)) { + dataerrln("Fail: Calendar::createInstance: %s", u_errorName(status)); + return; + } int32_t locCount = 0; @@ -126,7 +171,7 @@ void DateFormatRoundTripTest::TestDateFormatRoundTrip() #if 1 // installed locales for (int i=0; i < locCount; ++i) { - test(avail[i]); + test(avail[i]); } #endif @@ -220,7 +265,7 @@ void DateFormatRoundTripTest::test(const Locale& loc) logln("Testing dstyle" + UnicodeString(styleName((DateFormat::EStyle)dstyle)) + ", tstyle" + UnicodeString(styleName((DateFormat::EStyle)tstyle)) ); DateFormat *df = DateFormat::createDateTimeInstance((DateFormat::EStyle)dstyle, (DateFormat::EStyle)tstyle, loc); if(df == NULL) { - errln(UnicodeString("Could not DF::createDateTimeInstance ") + UnicodeString(styleName((DateFormat::EStyle)dstyle)) + ", tstyle" + UnicodeString(styleName((DateFormat::EStyle)tstyle)) + "Locale: " + loc.getDisplayName(temp)); + dataerrln(UnicodeString("Could not DF::createDateTimeInstance ") + UnicodeString(styleName((DateFormat::EStyle)dstyle)) + ", tstyle" + UnicodeString(styleName((DateFormat::EStyle)tstyle)) + "Locale: " + loc.getDisplayName(temp)); } else { test(df, loc); delete df; @@ -255,7 +300,8 @@ void DateFormatRoundTripTest::test(DateFormat *fmt, const Locale &origLocale, UB // patterns we have, but it may be a problem later. UBool hasEra = (pat.indexOf(UnicodeString("G")) != -1); - UBool hasZone = (pat.indexOf(UnicodeString("z")) != -1); + UBool hasZoneDisplayName = (pat.indexOf(UnicodeString("z")) != -1) || (pat.indexOf(UnicodeString("v")) != -1) + || (pat.indexOf(UnicodeString("V")) != -1); // Because patterns contain incomplete data representing the Date, // we must be careful of how we do the roundtrip. We start with @@ -289,7 +335,7 @@ void DateFormatRoundTripTest::test(DateFormat *fmt, const Locale &origLocale, UB for(loop = 0; loop < DEPTH; ++loop) { if (loop > 0) { d[loop] = fmt->parse(s[loop-1], status); - failure(status, "fmt->parse", s[loop-1]); + failure(status, "fmt->parse", s[loop-1]+" in locale: " + origLocale.getName()); status = U_ZERO_ERROR; /* any error would have been reported */ } @@ -337,9 +383,18 @@ void DateFormatRoundTripTest::test(DateFormat *fmt, const Locale &origLocale, UB int maxSmatch = 1; if (dmatch > maxDmatch) { // Time-only pattern with zone information and a starting date in PST. - if(timeOnly && hasZone && fmt->getTimeZone().inDaylightTime(d[0], status) && ! failure(status, "TimeZone::inDST()")) { - maxDmatch = 3; - maxSmatch = 2; + if(timeOnly && hasZoneDisplayName) { + int32_t startRaw, startDst; + fmt->getTimeZone().getOffset(d[0], FALSE, startRaw, startDst, status); + failure(status, "TimeZone::getOffset"); + // if the start offset is greater than the offset on Jan 1, 1970 + // in PST, then need one more round trip. There are two cases + // fall into this category. The start date is 1) DST or + // 2) LMT (GMT-07:52:58). + if (startRaw + startDst > -28800000) { + maxDmatch = 3; + maxSmatch = 2; + } } } @@ -364,21 +419,25 @@ void DateFormatRoundTripTest::test(DateFormat *fmt, const Locale &origLocale, UB && getField(d[0], UCAL_YEAR) != getField(d[dmatch], UCAL_YEAR) && !failure(status, "error status [smatch>maxSmatch]") - && ((hasZone + && ((hasZoneDisplayName && (fmt->getTimeZone().inDaylightTime(d[0], status) == fmt->getTimeZone().inDaylightTime(d[dmatch], status) || getField(d[0], UCAL_MONTH) == UCAL_APRIL || getField(d[0], UCAL_MONTH) == UCAL_OCTOBER)) - || !hasZone) + || !hasZoneDisplayName) ) { maxSmatch = 2; - } + } + // If zone display name is used, fallback format might be used before 1970 + else if (hasZoneDisplayName && d[0] < 0) { + maxSmatch = 2; + } } if(dmatch > maxDmatch || smatch > maxSmatch) { // Special case for Japanese and Islamic (could have large negative years) const char *type = fmt->getCalendar()->getType(); - if(!strcmp(type,"japanese")) { + if(!strcmp(type,"japanese") || (!strcmp(type,"buddhist"))) { maxSmatch = 4; maxDmatch = 4; }