Skip to content

Commit

Permalink
Remove reced()
Browse files Browse the repository at this point in the history
Users should use advance() and pass an inverted interval
to achieve the same effect
  • Loading branch information
adamnicholson committed Sep 8, 2016
1 parent dff8e70 commit 2eca231
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 27 deletions.
13 changes: 0 additions & 13 deletions src/Period.php
Original file line number Diff line number Diff line change
Expand Up @@ -924,19 +924,6 @@ public function advance($interval)
return new static($this->startDate->add($interval), $this->endDate->add($interval));
}

/**
* Returns a new Period instance where the start/end dates have moved backwards in time by the given DateInterval
*
* @param DateInterval|int|string $interval The interval
* @return Period
*/
public function recede($interval)
{
$interval = static::filterDateInterval($interval);

return new static($this->startDate->sub($interval), $this->endDate->sub($interval));
}

/**
* Create a new instance given two datepoints
*
Expand Down
21 changes: 7 additions & 14 deletions test/PeriodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -926,33 +926,26 @@ public function testAdvance()
$this->assertEquals(new Period('2016-01-02 15:32:12', '2016-01-16 12:00:01'), $moved);
}

public function testRecede()
{
$period = new Period('2016-01-02 15:32:12', '2016-01-16 12:00:01');
$moved = $period->recede(new DateInterval('P1D'));
$this->assertEquals(new Period('2016-01-01 15:32:12', '2016-01-15 12:00:01'), $moved);
}

public function testAdvanceAndRecedeSupportStringIntervals()
public function testAdvanceSupportStringIntervals()
{
$period = new Period('2016-01-01 15:32:12', '2016-01-15 12:00:01');
$advanced = $period->advance('1 DAY');
$this->assertEquals(new Period('2016-01-02 15:32:12', '2016-01-16 12:00:01'), $advanced);
$receded = $advanced->recede('1 DAY');
$this->assertEquals(new Period('2016-01-01 15:32:12', '2016-01-15 12:00:01'), $receded);
}

public function testAdvanceWithInvertedInterval()
{
$period = new Period('2016-01-02 15:32:12', '2016-01-16 12:00:01');
$moved = $period->advance('- 1 day');
$lessOneDay = new DateInterval('P1D');
$lessOneDay->invert = true;
$moved = $period->advance($lessOneDay);
$this->assertEquals(new Period('2016-01-01 15:32:12', '2016-01-15 12:00:01'), $moved);
}

public function testRecedeWithInvertedInterval()
public function testAdvanceWithInvertedStringInterval()
{
$period = new Period('2016-01-02 15:32:12', '2016-01-16 12:00:01');
$moved = $period->recede('- 1 day');
$this->assertEquals(new Period('2016-01-03 15:32:12', '2016-01-17 12:00:01'), $moved);
$moved = $period->advance('- 1 day');
$this->assertEquals(new Period('2016-01-01 15:32:12', '2016-01-15 12:00:01'), $moved);
}
}

0 comments on commit 2eca231

Please sign in to comment.