Skip to content
Permalink
Browse files

Correctly handle string timestamps.

Use is_numeric() to ensure that timestamps that are strings end up being
handled like an integer.

Refs #7761
  • Loading branch information...
markstory committed Dec 8, 2015
1 parent 492cb4b commit a1f1f834464df0928378e0a9a8e2a375f9f32f5a
Showing with 3 additions and 2 deletions.
  1. +2 −2 src/View/Widget/DateTimeWidget.php
  2. +1 −0 tests/TestCase/View/Widget/DateTimeWidgetTest.php
@@ -218,11 +218,11 @@ protected function _deconstructDate($value, $options)
];
}
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 = [
@@ -137,6 +137,7 @@ public static function selectedValuesProvider()
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',

0 comments on commit a1f1f83

Please sign in to comment.
You can’t perform that action at this time.