Forráskód Böngészése

[Locale] handle IntlDateFormatter::parse with non-integer timestamp

Igor Wiedler 14 éve
szülő
commit
195b2ebdde

+ 5 - 1
src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php

@@ -110,12 +110,16 @@ class StubIntlDateFormatter
     /**
      * Format the date/time value (timestamp) as a string
      *
-     * @param  int         $timestamp   Unix timestamp to format
+     * @param  mixed         $timestamp   Unix timestamp to format
      * @return string                   The formatted value
      * @throws NotImplementedException  If one of the formatting characters is not implemented
      */
     public function format($timestamp)
     {
+        if (!is_int($timestamp)) {
+            throw new MethodArgumentValueNotImplementedException(__METHOD__, 'timestamp', $timestamp, 'Only the integer unix timestamps are supported');
+        }
+
         $dateTime = $this->createDateTime($timestamp);
         $dateTime->setTimestamp($timestamp);
         $dateTime->setTimezone($this->dateTimeZone);

+ 9 - 0
tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php

@@ -302,6 +302,15 @@ class StubIntlDateFormatterTest extends LocaleTestCase
         $formatter->format(0);
     }
 
+    /**
+     * @expectedException Symfony\Component\Locale\Exception\NotImplementedException
+     */
+    public function testFormatWithNonIntegerTimestamp()
+    {
+        $formatter = $this->createStubFormatter();
+        $formatter->format(array());
+    }
+
     /**
     * @dataProvider dateAndTimeTypeProvider
     */