Fix code & tests for isPast() and isFuture()

The methods and tests now follow coding standards and work.
This commit is contained in:
mark_story 2013-03-30 22:23:47 -04:00
parent 632c4feb5d
commit d28c2f8e72
2 changed files with 26 additions and 42 deletions

View file

@ -603,23 +603,15 @@ class CakeTimeTest extends CakeTestCase {
* @return void
*/
public function testIsFuture() {
$result = $this->Time->isFuture('+1 month');
$this->assertTrue($result);
$result = $this->Time->isFuture('+1 days');
$this->assertTrue($result);
$result = $this->Time->isFuture('+1 minute');
$this->assertTrue($result);
$result = $this->Time->isFuture('+1 second');
$this->assertTrue($result);
$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'));
$result = $this->Time->isFuture('-1 second');
$this->assertFalse($result);
$result = $this->Time->isFuture('-1 day');
$this->assertFalse($result);
$result = $this->Time->isFuture('-1 week');
$this->assertFalse($result);
$result = $this->Time->isFuture('-1 month');
$this->assertFalse($result);
$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'));
}
/**
@ -628,23 +620,15 @@ class CakeTimeTest extends CakeTestCase {
* @return void
*/
public function testIsPast() {
$result = $this->Time->isFuture('+1 month');
$this->assertFalse($result);
$result = $this->Time->isFuture('+1 days');
$this->assertFalse($result);
$result = $this->Time->isFuture('+1 minute');
$this->assertFalse($result);
$result = $this->Time->isFuture('+1 second');
$this->assertFalse($result);
$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'));
$result = $this->Time->isFuture('-1 second');
$this->assertTrue($result);
$result = $this->Time->isFuture('-1 day');
$this->assertTrue($result);
$result = $this->Time->isFuture('-1 week');
$this->assertTrue($result);
$result = $this->Time->isFuture('-1 month');
$this->assertTrue($result);
$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'));
}
/**

View file

@ -475,8 +475,8 @@ class CakeTime {
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
*/
public static function isFuture($dateString, $timezone = null) {
$date = self::fromString($dateString, $timezone);
return date('Y-m-d H:i:s', $date) < date('Y-m-d H:i:s', time());
$timestamp = self::fromString($dateString, $timezone);
return $timestamp > time();
}
/**
@ -488,8 +488,8 @@ class CakeTime {
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
*/
public static function isPast($dateString, $timezone = null) {
$date = self::fromString($dateString, $timezone);
return date('Y-m-d H:i:s', $date) > date('Y-m-d H:i:s', time());
$timestamp = self::fromString($dateString, $timezone);
return $timestamp < time();
}
/**