Skip to content

Commit

Permalink
Added workaround for strtotime("0000-00-00 00:00:00") returning -6216…
Browse files Browse the repository at this point in the history
…9955200 on a 64 bit system
  • Loading branch information
Mark van Driel authored and Mark van Driel committed Aug 15, 2013
1 parent 559fb58 commit 1595287
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/Cake/Test/Case/Utility/CakeTimeTest.php
Expand Up @@ -583,6 +583,9 @@ public function testFormat() {

$result = $this->Time->format('nonsense', '%d-%m-%Y', 'invalid', 'UTC');
$this->assertEquals('invalid', $result);

$result = $this->Time->format('0000-00-00', '%d-%m-%Y', 'invalid');
$this->assertEquals('invalid', $result);
}

/**
Expand Down
7 changes: 6 additions & 1 deletion lib/Cake/Utility/CakeTime.php
Expand Up @@ -328,7 +328,12 @@ public static function fromString($dateString, $timezone = null) {
} elseif ($dateString instanceof DateTime) {
$date = (int)$dateString->format('U');
} else {
$date = strtotime($dateString);
// workaround for strtotime("0000-00-00 00:00:00") returning -62169955200 on a 64 bit system.
if (substr($dateString, 0, 10) === '0000-00-00') {
$date = false;
} else {
$date = strtotime($dateString);
}
}

if ($date === -1 || empty($date)) {
Expand Down

0 comments on commit 1595287

Please sign in to comment.