diff --git a/lib/Cake/Test/Case/Utility/CakeTimeTest.php b/lib/Cake/Test/Case/Utility/CakeTimeTest.php index 78ab94efa..bab883761 100644 --- a/lib/Cake/Test/Case/Utility/CakeTimeTest.php +++ b/lib/Cake/Test/Case/Utility/CakeTimeTest.php @@ -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 * diff --git a/lib/Cake/Utility/CakeTime.php b/lib/Cake/Utility/CakeTime.php index 95da85d84..15473b898 100644 --- a/lib/Cake/Utility/CakeTime.php +++ b/lib/Cake/Utility/CakeTime.php @@ -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. *