From ae8386c48a08a49a4ff6146e453cfc71b2ae8d5c Mon Sep 17 00:00:00 2001 From: ADmad Date: Sat, 20 Apr 2013 13:10:06 +0530 Subject: [PATCH] Fix datetime comparison in relative datetime functions. Closes #2987,#3514 --- lib/Cake/Utility/CakeTime.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/Cake/Utility/CakeTime.php b/lib/Cake/Utility/CakeTime.php index 91337d954..60784cc30 100644 --- a/lib/Cake/Utility/CakeTime.php +++ b/lib/Cake/Utility/CakeTime.php @@ -468,7 +468,8 @@ class CakeTime { */ public static function isToday($dateString, $timezone = null) { $timestamp = self::fromString($dateString, $timezone); - return date('Y-m-d', $timestamp) == date('Y-m-d', time()); + $now = self::fromString('now', $timezone); + return date('Y-m-d', $timestamp) == date('Y-m-d', $now); } /** @@ -481,7 +482,8 @@ class CakeTime { */ public static function isThisWeek($dateString, $timezone = null) { $timestamp = self::fromString($dateString, $timezone); - return date('W o', $timestamp) == date('W o', time()); + $now = self::fromString('now', $timezone); + return date('W o', $timestamp) == date('W o', $now); } /** @@ -494,7 +496,8 @@ class CakeTime { */ public static function isThisMonth($dateString, $timezone = null) { $timestamp = self::fromString($dateString, $timezone); - return date('m Y', $timestamp) == date('m Y', time()); + $now = self::fromString('now', $timezone); + return date('m Y', $timestamp) == date('m Y', $now); } /** @@ -507,7 +510,8 @@ class CakeTime { */ public static function isThisYear($dateString, $timezone = null) { $timestamp = self::fromString($dateString, $timezone); - return date('Y', $timestamp) == date('Y', time()); + $now = self::fromString('now', $timezone); + return date('Y', $timestamp) == date('Y', $now); } /** @@ -521,7 +525,8 @@ class CakeTime { */ public static function wasYesterday($dateString, $timezone = null) { $timestamp = self::fromString($dateString, $timezone); - return date('Y-m-d', $timestamp) == date('Y-m-d', strtotime('yesterday')); + $yesterday = self::fromString('yesterday', $timezone); + return date('Y-m-d', $timestamp) == date('Y-m-d', $yesterday); } /** @@ -534,7 +539,8 @@ class CakeTime { */ public static function isTomorrow($dateString, $timezone = null) { $timestamp = self::fromString($dateString, $timezone); - return date('Y-m-d', $timestamp) == date('Y-m-d', strtotime('tomorrow')); + $tomorrow = self::fromString('tomorrow', $timezone); + return date('Y-m-d', $timestamp) == date('Y-m-d', $tomorrow); } /** @@ -880,8 +886,9 @@ class CakeTime { $date = self::fromString($dateString, $timezone); $interval = self::fromString('-' . $timeInterval); + $now = self::fromString('now', $timezone); - return $date >= $interval && $date <= time(); + return $date >= $interval && $date <= $now; } /** @@ -902,8 +909,9 @@ class CakeTime { $date = self::fromString($dateString, $timezone); $interval = self::fromString('+' . $timeInterval); + $now = self::fromString('now', $timezone); - return $date <= $interval && $date >= time(); + return $date <= $interval && $date >= $now; } /**