mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #1235 from ADmad/2.3-caketime
Fix datetime comparison in relative datetime functions.
This commit is contained in:
commit
e26a05ce04
1 changed files with 16 additions and 8 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue