mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 17:16:18 +00:00
Merge branch 'caketime-improvements' into 2.4
Add CakeTime::isPast() and CakeTime::isFuture(). Closes #GH-1190
This commit is contained in:
commit
d681a191db
2 changed files with 60 additions and 0 deletions
|
@ -597,6 +597,40 @@ class CakeTimeTest extends CakeTestCase {
|
|||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testIsFuture method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIsFuture() {
|
||||
$this->assertTrue($this->Time->isFuture('+1 month'));
|
||||
$this->assertTrue($this->Time->isFuture('+1 days'));
|
||||
$this->assertTrue($this->Time->isFuture('+1 minute'));
|
||||
$this->assertTrue($this->Time->isFuture('+1 second'));
|
||||
|
||||
$this->assertFalse($this->Time->isFuture('-1 second'));
|
||||
$this->assertFalse($this->Time->isFuture('-1 day'));
|
||||
$this->assertFalse($this->Time->isFuture('-1 week'));
|
||||
$this->assertFalse($this->Time->isFuture('-1 month'));
|
||||
}
|
||||
|
||||
/**
|
||||
* testIsPast method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIsPast() {
|
||||
$this->assertFalse($this->Time->isPast('+1 month'));
|
||||
$this->assertFalse($this->Time->isPast('+1 days'));
|
||||
$this->assertFalse($this->Time->isPast('+1 minute'));
|
||||
$this->assertFalse($this->Time->isPast('+1 second'));
|
||||
|
||||
$this->assertTrue($this->Time->isPast('-1 second'));
|
||||
$this->assertTrue($this->Time->isPast('-1 day'));
|
||||
$this->assertTrue($this->Time->isPast('-1 week'));
|
||||
$this->assertTrue($this->Time->isPast('-1 month'));
|
||||
}
|
||||
|
||||
/**
|
||||
* testIsThisWeek method
|
||||
*
|
||||
|
|
|
@ -466,6 +466,32 @@ class CakeTime {
|
|||
return date('Y-m-d', $timestamp) == date('Y-m-d', time());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if given datetime string is in the future.
|
||||
*
|
||||
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param string|DateTimeZone $timezone Timezone string or DateTimeZone object
|
||||
* @return boolean True if datetime string is in the future
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
|
||||
*/
|
||||
public static function isFuture($dateString, $timezone = null) {
|
||||
$timestamp = self::fromString($dateString, $timezone);
|
||||
return $timestamp > time();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if given datetime string is in the past.
|
||||
*
|
||||
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param string|DateTimeZone $timezone Timezone string or DateTimeZone object
|
||||
* @return boolean True if datetime string is in the past
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
|
||||
*/
|
||||
public static function isPast($dateString, $timezone = null) {
|
||||
$timestamp = self::fromString($dateString, $timezone);
|
||||
return $timestamp < time();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if given datetime string is within this week.
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue