Skip to content

Commit

Permalink
No overlap returns empty collection
Browse files Browse the repository at this point in the history
  • Loading branch information
brendt committed Jan 8, 2019
1 parent 3615e43 commit fbb30b1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ All notable changes to `period` will be documented in this file

- initial release

## 0.4.1 - 2019-01-08

- No overlap returns empty collection

## 0.4.0 - 2018-12-19

- Add visualizer
Expand Down
8 changes: 7 additions & 1 deletion src/Period.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,13 @@ public function overlap(Period ...$periods): PeriodCollection
$overlapCollection = new PeriodCollection();

foreach ($periods as $period) {
$overlapCollection[] = $this->overlapSingle($period);
$overlap = $this->overlapSingle($period);

if ($overlap === null) {
continue;
}

$overlapCollection[] = $overlap;
}

return $overlapCollection;
Expand Down
9 changes: 9 additions & 0 deletions tests/PeriodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ public function it_can_determine_the_overlap_between_multiple_periods()
$this->assertTrue($overlap->equals(Period::make('2018-01-10', '2018-01-15')));
}

/** @test */
public function non_overlapping_dates_return_an_empty_collection()
{
$a = Period::make('2019-01-01', '2019-01-31');
$b = Period::make('2019-02-01', '2019-02-28');

$this->assertTrue($a->overlap($b)->isEmpty());
}

/** @test */
public function it_can_determine_that_two_periods_do_not_overlap()
{
Expand Down

0 comments on commit fbb30b1

Please sign in to comment.