Skip to content

Commit

Permalink
Support edge case for two period diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
brendt committed Dec 18, 2018
1 parent e1c1189 commit b33927c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
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.3.3 - 2018-12-18

- Support edge case for two period diffs

## 0.3.2 - 2018-12-11

- Add better return types to support inherited periods
Expand Down
6 changes: 2 additions & 4 deletions src/Period.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,10 @@ public function diffSingle(Period $period): PeriodCollection

public function diff(Period ...$periods): PeriodCollection
{
if (count($periods) === 1) {
if (count($periods) === 1 && ! $this->overlapsWith($periods[0])) {
$collection = new PeriodCollection();

if (! $this->overlapsWith($periods[0])) {
$collection[] = $this->gap($periods[0]);
}
$collection[] = $this->gap($periods[0]);

return $collection;
}
Expand Down
18 changes: 18 additions & 0 deletions tests/PeriodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -476,4 +476,22 @@ public function if_will_use_the_start_of_day_when_passing_strings_to_a_period()
)
));
}

/**
* @test
*
* A [=============================]
* B [========]
*
* DIFF [==] [===============]
*/
public function diff_with_one_period_within()
{
$a = Period::make('2018-01-01', '2018-01-31');
$b = Period::make('2018-01-10', '2018-01-15');

$diff = $a->diff($b);

$this->assertCount(2, $diff);
}
}

0 comments on commit b33927c

Please sign in to comment.