]> granicus.if.org Git - icu/commitdiff
ICU-8719 Skip date field range check added by r30018 when lenient mode. Reverted...
authorYoshito Umaoka <y.umaoka@gmail.com>
Mon, 15 Aug 2011 20:54:36 +0000 (20:54 +0000)
committerYoshito Umaoka <y.umaoka@gmail.com>
Mon, 15 Aug 2011 20:54:36 +0000 (20:54 +0000)
X-SVN-Rev: 30508

icu4c/source/i18n/smpdtfmt.cpp
icu4c/source/test/intltest/dtfmrgts.cpp
icu4c/source/test/intltest/dtfmttst.cpp

index 5a88539a65601394dbdd95046428c856c36a0a30..8316ea37b8800a6ac9b57a7c15941389c1ffff79 100644 (file)
@@ -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;
     }
index e348cded07bfe4963e750905c1727f469ff6480f..0bd0e7016a1ac5fddc81c435bc6384b7ab3f70eb 100644 (file)
@@ -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());
index 3cb949189bb3df729ff315e6d2e9adcb77debb4e..918cd4945e0d56dde000bf0272e176f8d5949db1 100644 (file)
@@ -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;