Permalink
Browse files

php datetime apparently sets the time to midnight with relative dates…

…, switched to new found modify method
  • Loading branch information...
1 parent 9599403 commit cf84396e1e1ef37fd52a58139105d58e53125776 @nicholas-eden committed Sep 7, 2013
Showing with 25 additions and 16 deletions.
  1. +18 −10 src/Carbon/Carbon.php
  2. +7 −6 tests/TestingAidsTest.php
View
@@ -71,13 +71,22 @@ class Carbon extends DateTime
self::SATURDAY => 'Saturday'
);
- private static $relativeKeywords = array(
- 'this',
- 'next',
- 'last',
- 'tomorrow',
- 'yesterday'
- );
+ /**
+ * Terms used to detect if a time passed is a relative date for testing purposes
+ *
+ * @var array
+ */
+ private static $relativeKeywords = array(
+ 'this',
+ 'next',
+ 'last',
+ 'tomorrow',
+ 'yesterday',
+ '+',
+ '-',
+ 'first',
+ 'last'
+ );
/**
* Number of X in Y
@@ -743,9 +752,8 @@ public static function hasRelativeKeywords($time) {
*/
public static function getRelativeTest($time) {
$testNow = static::getTestNow();
-
- $instance = new static($testNow->toDateString() . ' ' . $time);
- $instance->setTime($testNow->format('h'), $testNow->format('i'), $testNow->format('s'));
+ $instance = new static();
+ $instance->modify($time);
return $instance;
}
View
@@ -61,14 +61,15 @@ public function testParseWithTestValueSet()
public function testParseRelativeWithTestValueSet()
{
- $notNow = Carbon::parse('2013-09-01 05:30:15');
- Carbon::setTestNow($notNow);
-
- $this->assertEquals('05:30:15', Carbon::parse('tomorrow')->toTimeString());
+ $notNow = Carbon::parse('2013-09-01');
+ Carbon::setTestNow($notNow);
$this->assertEquals('2013-09-02', Carbon::parse('tomorrow')->toDateString());
$this->assertEquals('2013-08-31', Carbon::parse('yesterday')->toDateString());
+ $this->assertEquals('2013-09-02', Carbon::parse('+1 day')->toDateString());
+ $this->assertEquals('2013-08-31', Carbon::parse('-1 day')->toDateString());
+
$this->assertEquals('2013-09-02', Carbon::parse('next monday')->toDateString());
$this->assertEquals('2013-09-03', Carbon::parse('next tuesday')->toDateString());
$this->assertEquals('2013-09-04', Carbon::parse('next wednesday')->toDateString());
@@ -93,7 +94,7 @@ public function testParseRelativeWithTestValueSet()
$this->assertEquals('2013-09-07', Carbon::parse('this saturday')->toDateString());
$this->assertEquals('2013-09-01', Carbon::parse('this sunday')->toDateString());
-
-
+ $this->assertEquals('2013-10-01', Carbon::parse('first day of next month')->toDateString());
+ $this->assertEquals('2013-09-30', Carbon::parse('last day of this month')->toDateString());
}
}

0 comments on commit cf84396

Please sign in to comment.