Skip to content

Commit e8c8667

Browse files
authored
Added support of empty ranges (#19)
* Date range may empty, ends exactly at start * Update CHANGELOG
1 parent 53c70d5 commit e8c8667

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Security - in case of vulnerabilities.
1818

1919
_TBD_
2020

21+
### Changed
22+
- Added support of empty ranges, allowing you to use the end time exactly the same as the start time. ([#18](../../pull/19)).
23+
2124
## [0.4.0] 2018-02-16
2225

2326
### Added

src/States/FiniteState.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class FiniteState extends RangeState
2626
*/
2727
public function __construct(DateTimeInterface $startDate, DateTimeInterface $endDate)
2828
{
29-
if ($endDate <= $startDate) {
29+
if ($endDate < $startDate) {
3030
throw new DateRangeException('Invalid end date, must be after start');
3131
}
3232

tests/States/FiniteRangeTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,14 @@ public function guardRangeSequence()
7878

7979
/**
8080
* @test
81+
* @depends checkFiniteState
8182
*/
82-
public function guardRangeDatesDifference()
83+
public function rangeMayBeEmptyWhenEndsExactlyAtStart()
8384
{
84-
$this->expectException(DateRangeException::class);
85-
$this->expectExceptionMessage('Invalid end date, must be after start');
86-
87-
new FiniteState($this->tomorrow, $this->tomorrow);
85+
$subject = new FiniteState($this->tomorrow, $this->tomorrow);
86+
self::assertTrue($subject->hasStartDate());
87+
self::assertTrue($subject->hasEndDate());
88+
self::assertSame($this->tomorrow, $subject->getStartDate());
89+
self::assertSame($this->tomorrow, $subject->getEndDate());
8890
}
8991
}

0 commit comments

Comments
 (0)