From 1595287290b6daa2f26c93b529c82882537b2b7e Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Thu, 15 Aug 2013 08:58:05 +0200 Subject: [PATCH 1/2] Added workaround for strtotime("0000-00-00 00:00:00") returning -62169955200 on a 64 bit system --- lib/Cake/Test/Case/Utility/CakeTimeTest.php | 3 +++ lib/Cake/Utility/CakeTime.php | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Utility/CakeTimeTest.php b/lib/Cake/Test/Case/Utility/CakeTimeTest.php index 028723b93..95370c25b 100644 --- a/lib/Cake/Test/Case/Utility/CakeTimeTest.php +++ b/lib/Cake/Test/Case/Utility/CakeTimeTest.php @@ -583,6 +583,9 @@ class CakeTimeTest extends CakeTestCase { $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); } /** diff --git a/lib/Cake/Utility/CakeTime.php b/lib/Cake/Utility/CakeTime.php index 635d0612b..21100cc64 100644 --- a/lib/Cake/Utility/CakeTime.php +++ b/lib/Cake/Utility/CakeTime.php @@ -328,7 +328,12 @@ class CakeTime { } 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)) { From 97aaa89b3f83f760431c56dab108482cbf4f1434 Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Thu, 15 Aug 2013 17:13:31 +0200 Subject: [PATCH 2/2] Refactored the fix --- lib/Cake/Utility/CakeTime.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Cake/Utility/CakeTime.php b/lib/Cake/Utility/CakeTime.php index 21100cc64..dc546d6ce 100644 --- a/lib/Cake/Utility/CakeTime.php +++ b/lib/Cake/Utility/CakeTime.php @@ -316,6 +316,11 @@ class CakeTime { return false; } + $containsDummyDate = (is_string($dateString) && substr($dateString, 0, 10) === '0000-00-00'); + if ($containsDummyDate) { + return false; + } + if (is_int($dateString) || is_numeric($dateString)) { $date = intval($dateString); } elseif ( @@ -328,12 +333,7 @@ class CakeTime { } elseif ($dateString instanceof DateTime) { $date = (int)$dateString->format('U'); } else { - // 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); - } + $date = strtotime($dateString); } if ($date === -1 || empty($date)) {