Skip to content

Commit

Permalink
Correctly handle string timestamps.
Browse files Browse the repository at this point in the history
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 a1f1f83
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/View/Widget/DateTimeWidget.php
Expand Up @@ -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 = [
Expand Down
1 change: 1 addition & 0 deletions tests/TestCase/View/Widget/DateTimeWidgetTest.php
Expand Up @@ -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',
Expand Down

0 comments on commit a1f1f83

Please sign in to comment.