Skip to content

Commit

Permalink
Fix for PeriodCollection::gaps() with excluded boundaries (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
brendt committed Feb 5, 2020
1 parent 88076b7 commit 7ed3ae7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to `period` will be documented in this file

## 1.4.5 - 2020-02-05

- Fix for PeriodCollection::gaps() with excluded boundaries (#58)

## 1.4.4 - 2019-08-05

- ~Performance improvement in `Period::contains()` (#46)~ edit: this change wasn't merged and targeted at 2.0
Expand Down
4 changes: 2 additions & 2 deletions src/PeriodCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ public function boundaries(): ?Period

foreach ($this as $period) {
if ($start === null || $start > $period->getIncludedStart()) {
$start = $period->getStart();
$start = $period->getIncludedStart();
}

if ($end === null || $end < $period->getIncludedEnd()) {
$end = $period->getEnd();
$end = $period->getIncludedEnd();
}
}

Expand Down
23 changes: 23 additions & 0 deletions tests/PeriodCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Spatie\Period\Tests;

use DateTimeImmutable;
use Spatie\Period\Boundaries;
use Spatie\Period\Period;
use PHPUnit\Framework\TestCase;
use Spatie\Period\PeriodCollection;
Expand Down Expand Up @@ -122,6 +123,28 @@ public function it_can_determine_the_gaps_of_a_collection()
$this->assertTrue($gaps[2]->equals(Period::make('2018-01-26', '2018-01-29')));
}

/**
* @test
*
* A [=====)
* B [=====)
* C [=====)
*
* GAP
*/
public function no_gaps_when_periods_fully_overlap_and_end_excluded()
{
$collection = new PeriodCollection(
Period::make('2018-01-01', '2018-01-05', null, Boundaries::EXCLUDE_END),
Period::make('2018-01-01', '2018-01-05', null, Boundaries::EXCLUDE_END),
Period::make('2018-01-01', '2018-01-05', null, Boundaries::EXCLUDE_END),
);

$gaps = $collection->gaps();

$this->assertCount(0, $gaps);
}

/**
* @test
*
Expand Down

0 comments on commit 7ed3ae7

Please sign in to comment.