From 3b11db76a482c0af3f6e5454c36753e9bb482500 Mon Sep 17 00:00:00 2001 From: Yoshito Umaoka Date: Mon, 15 Aug 2011 20:54:36 +0000 Subject: [PATCH] ICU-8719 Skip date field range check added by r30018 when lenient mode. Reverted some date format test cases to accept out of range date fields when lenient. X-SVN-Rev: 30508 --- icu4c/source/i18n/smpdtfmt.cpp | 32 ++++++++++++++----------- icu4c/source/test/intltest/dtfmrgts.cpp | 8 +++---- icu4c/source/test/intltest/dtfmttst.cpp | 5 ++-- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/icu4c/source/i18n/smpdtfmt.cpp b/icu4c/source/i18n/smpdtfmt.cpp index 5a88539a656..8316ea37b88 100644 --- a/icu4c/source/i18n/smpdtfmt.cpp +++ b/icu4c/source/i18n/smpdtfmt.cpp @@ -2619,14 +2619,15 @@ int32_t SimpleDateFormat::subParse(const UnicodeString& text, int32_t& start, UC else { txtLoc = checkIntSuffix(text, txtLoc, patLoc+1, FALSE); } - - // Check the range of the value - int32_t bias = gFieldRangeBias[patternCharIndex]; - - if (bias >= 0 && (value > cal.getMaximum(field) + bias || value < cal.getMinimum(field) + bias)) { - return -start; + + if (!lenient) { + // Check the range of the value + int32_t bias = gFieldRangeBias[patternCharIndex]; + if (bias >= 0 && (value > cal.getMaximum(field) + bias || value < cal.getMinimum(field) + bias)) { + return -start; + } } - + pos.setIndex(txtLoc); } } @@ -3141,14 +3142,17 @@ int32_t SimpleDateFormat::subParse(const UnicodeString& text, int32_t& start, UC parseInt(*src, number, pos, allowNegative,currentNumberFormat); if (pos.getIndex() != parseStart) { int32_t value = number.getLong(); - - // Check the range of the value - int32_t bias = gFieldRangeBias[patternCharIndex]; - - if (bias < 0 || (value >= cal.getMinimum(field) + bias && value <= cal.getMaximum(field) + bias)) { - cal.set(field, value); - return pos.getIndex(); + + if (!lenient) { + // Check the range of the value + int32_t bias = gFieldRangeBias[patternCharIndex]; + if (bias >= 0 && (value > cal.getMaximum(field) + bias || value < cal.getMinimum(field) + bias)) { + return -start; + } } + + cal.set(field, value); + return pos.getIndex(); } return -start; } diff --git a/icu4c/source/test/intltest/dtfmrgts.cpp b/icu4c/source/test/intltest/dtfmrgts.cpp index e348cded07b..0bd0e7016a1 100644 --- a/icu4c/source/test/intltest/dtfmrgts.cpp +++ b/icu4c/source/test/intltest/dtfmrgts.cpp @@ -362,7 +362,6 @@ void DateFormatRegressionTest::Test4060212(void) errln((UnicodeString) "Fail: Got " + cal->get(UCAL_DAY_OF_YEAR, status) + " Want 40"); -#if 0 // this is an odd usage of "ddd" and it doesn't // work now that date values are range checked per #3579. logln("Using yyyy-ddd.hh:mm:ss"); @@ -379,7 +378,6 @@ void DateFormatRegressionTest::Test4060212(void) if ((cal->get(UCAL_DAY_OF_YEAR, status) != 40) || failure(status, "cal->get")) errln((UnicodeString) "Fail: Got " + cal->get(UCAL_DAY_OF_YEAR, status) + " Want 40"); -#endif delete formatter; delete fmt; @@ -401,8 +399,8 @@ void DateFormatRegressionTest::Test4061287(void) } failure(status, "new SimpleDateFormat"); //try { - logln(UnicodeString("") + df->parse("30/02/1971", status)); - failure(status, "df->parse(\"30/02/1971\")"); + logln(UnicodeString("") + df->parse("35/01/1971", status)); + failure(status, "df->parse(\"35/01/1971\")"); //logln(df.parse("35/01/1971").toString()); //} /*catch (ParseException e) { @@ -412,7 +410,7 @@ void DateFormatRegressionTest::Test4061287(void) df->setLenient(FALSE); UBool ok = FALSE; //try { - logln(UnicodeString("") + df->parse("30/02/1971", status)); + logln(UnicodeString("") + df->parse("35/01/1971", status)); if(U_FAILURE(status)) ok = TRUE; //logln(df.parse("35/01/1971").toString()); diff --git a/icu4c/source/test/intltest/dtfmttst.cpp b/icu4c/source/test/intltest/dtfmttst.cpp index 3cb949189bb..918cd4945e0 100644 --- a/icu4c/source/test/intltest/dtfmttst.cpp +++ b/icu4c/source/test/intltest/dtfmttst.cpp @@ -683,9 +683,8 @@ DateFormatTest::TestLetterDPattern212() { UErrorCode status = U_ZERO_ERROR; UnicodeString dateString("1995-040.05:01:29"); - UnicodeString ddateString("1995-02-09.05:01:29"); UnicodeString bigD("yyyy-DDD.hh:mm:ss"); - UnicodeString littleD("yyyy-MM-dd.hh:mm:ss"); + UnicodeString littleD("yyyy-ddd.hh:mm:ss"); UDate expLittleD = date(95, 0, 1, 5, 1, 29); UDate expBigD = expLittleD + 39 * 24 * 3600000.0; expLittleD = expBigD; // Expect the same, with default lenient parsing @@ -704,7 +703,7 @@ DateFormatTest::TestLetterDPattern212() formatter = new SimpleDateFormat(littleD, status); ASSERT_OK(status); pos = ParsePosition(0); - myDate = formatter->parse(ddateString, pos); + myDate = formatter->parse(dateString, pos); logln((UnicodeString)"Using " + littleD + " -> " + dateToString(myDate)); if (myDate != expLittleD) errln((UnicodeString)"FAIL: littleD - Expected " + dateToString(expLittleD)); delete formatter; -- 2.40.0