Browse Source

Merge pull request #7810 from cakephp/issue-7761

Correctly handle string timestamps.
José Lorenzo Rodríguez 10 years ago
parent
commit
8634fb4e1e

+ 2 - 2
src/View/Widget/DateTimeWidget.php

@@ -218,11 +218,11 @@ class DateTimeWidget implements WidgetInterface
             ];
         }
         try {
-            if (is_string($value)) {
+            if (is_string($value) && !is_numeric($value)) {
                 $date = new DateTime($value);
             } elseif (is_bool($value)) {
                 $date = new DateTime();
-            } elseif (is_int($value)) {
+            } elseif (is_int($value) || is_numeric($value)) {
                 $date = new DateTime('@' . $value);
             } elseif (is_array($value)) {
                 $dateArray = [

+ 1 - 0
tests/TestCase/View/Widget/DateTimeWidgetTest.php

@@ -137,6 +137,7 @@ class DateTimeWidgetTest extends TestCase
         return [
             'DateTime' => [$date],
             'string' => [$date->format('Y-m-d H:i:s')],
+            'int string' => [$date->format('U')],
             'int' => [$date->getTimestamp()],
             'array' => [[
                 'year' => '2014', 'month' => '01', 'day' => '20',