Selaa lähdekoodia

[Locale] Fix #2179 StubIntlDateFormatter support yy format

Fix #2179 Year limit is 2031 like IntlDateFormatter
stealth35 13 vuotta sitten
vanhempi
commit
43b55efd04

+ 7 - 0
src/Symfony/Component/Locale/Stub/DateFormat/FullTransformer.php

@@ -294,6 +294,13 @@ class FullTransformer
             $dateTime->setTimezone(new \DateTimeZone($timezone));
         }
 
+        // Normalize yy year
+        preg_match_all($this->regExp, $this->pattern, $matches);
+        if (in_array('yy', $matches[0])) {
+            $dateTime->setTimestamp(time());
+            $year = $year > $dateTime->format('y') + 20 ? 1900 + $year : 2000 + $year;
+        }
+
         $dateTime->setDate($year, $month, $day);
         $dateTime->setTime($hour, $minute, $second);
 

+ 1 - 2
tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php

@@ -544,8 +544,7 @@ class StubIntlDateFormatterTest extends LocaleTestCase
         return array(
             // years
             array('y-M-d', '1970-1-1', 0),
-            // TODO: review to support or not this variant
-            // array('yy-M-d', '70-1-1', 0),
+            array('yy-M-d', '70-1-1', 0),
 
             // months
             array('y-M-d', '1970-1-1', 0),