Skip to content
Permalink
Browse files

Fix datetime comparison in relative datetime functions.

Closes #2987,#3514
  • Loading branch information...
ADmad committed Apr 20, 2013
1 parent 842b180 commit ae8386c48a08a49a4ff6146e453cfc71b2ae8d5c
Showing with 16 additions and 8 deletions.
  1. +16 −8 lib/Cake/Utility/CakeTime.php
@@ -468,7 +468,8 @@ public static function dayAsSql($dateString, $fieldName, $timezone = null) {
*/
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 @@ public static function isToday($dateString, $timezone = null) {
*/
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 @@ public static function isThisWeek($dateString, $timezone = null) {
*/
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 @@ public static function isThisMonth($dateString, $timezone = null) {
*/
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 @@ public static function isThisYear($dateString, $timezone = null) {
*/
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 @@ public static function wasYesterday($dateString, $timezone = null) {
*/
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 @@ public static function wasWithinLast($timeInterval, $dateString, $timezone = nul
$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 @@ public static function isWithinNext($timeInterval, $dateString, $timezone = null
$date = self::fromString($dateString, $timezone);
$interval = self::fromString('+' . $timeInterval);
$now = self::fromString('now', $timezone);
return $date <= $interval && $date >= time();
return $date <= $interval && $date >= $now;
}
/**

0 comments on commit ae8386c

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