Skip to content

Commit

Permalink
Add hasStartDate and hasEndDate to Interval
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenDeDauw committed Mar 14, 2021
1 parent 3cddc1f commit 24e8861
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Model/Interval.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,20 @@ public function getStartDate(): ExtDate
return $this->start->getDate();
}

public function hasStartDate(): bool {
return $this->start->isNormalInterval();
}

public function getEndDate(): ExtDate
{
// TODO: why do we need this method?
return $this->end->getDate();
}

public function hasEndDate(): bool {
return $this->end->isNormalInterval();
}

public function getSignificantDigit(): ?int
{
return $this->significantDigit;
Expand Down
41 changes: 41 additions & 0 deletions tests/Unit/Model/IntervalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,45 @@ public function testUnknownIntervalIsOnlyUnknown(): void {
$this->assertFalse( $interval->isOpenInterval() );
$this->assertTrue( $interval->isUnknownInterval() );
}

public function testHasStartAndEndDateForIntervalWithOpenStart(): void {
$interval = new Interval(
IntervalSide::newOpenInterval(),
IntervalSide::newFromDate( new ExtDate( 2020, 2, 8 ) )
);

$this->assertFalse( $interval->hasStartDate() );
$this->assertTrue( $interval->hasEndDate() );
}

public function testHasStartAndEndDateForIntervalWithUnknownStart(): void {
$interval = new Interval(
IntervalSide::newUnknownInterval(),
IntervalSide::newFromDate( new ExtDate( 2020, 2, 8 ) )
);

$this->assertFalse( $interval->hasStartDate() );
$this->assertTrue( $interval->hasEndDate() );
}

public function testHasStartAndEndDateForIntervalWithOpenEnd(): void {
$interval = new Interval(
IntervalSide::newFromDate( new ExtDate( 2020, 2, 8 ) ),
IntervalSide::newOpenInterval()
);

$this->assertFalse( $interval->hasEndDate() );
$this->assertTrue( $interval->hasStartDate() );
}

public function testHasStartAndEndDateForIntervalWithUnknownEnd(): void {
$interval = new Interval(
IntervalSide::newFromDate( new ExtDate( 2020, 2, 8 ) ),
IntervalSide::newUnknownInterval()
);

$this->assertFalse( $interval->hasEndDate() );
$this->assertTrue( $interval->hasStartDate() );
}

}

0 comments on commit 24e8861

Please sign in to comment.