Skip to content

Commit

Permalink
Add interval support
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenDeDauw committed Mar 13, 2021
1 parent 3ec42cb commit 1d9f772
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/Services/TimeValueBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use EDTF\EdtfValue;
use EDTF\Model\ExtDate;
use EDTF\Model\ExtDateTime;
use EDTF\Model\Interval;
use EDTF\Model\Season;
use EDTF\Model\Set;

Expand All @@ -33,6 +34,13 @@ public function edtfToTimeValues( string $edtfString ): array {
);
}

if ( $edtf instanceof Interval ) {
return [
$this->singleValueEdtfToTimeValue( $edtf->getStartDate() ),
$this->singleValueEdtfToTimeValue( $edtf->getEndDate() )
];
}

return [
$this->singleValueEdtfToTimeValue( $edtf )
];
Expand Down
12 changes: 11 additions & 1 deletion tests/php/Unit/TimeValueBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,19 @@ public function testSet(): void {

public function testSeason(): void {
$this->assertEquals(
$this->newTimeValue( '+2021-01-00T00:00:00Z', 0, TimeValue::PRECISION_MONTH ),
$this->newTimeValue( '+2021-01-00T00:00:00Z', 0, TimeValue::PRECISION_MONTH ), // TODO
$this->edtfToTimeValue( '2021-21' )
);
}

public function testInterval(): void {
$this->assertEquals(
[
$this->newTimeValue( '+2020-11-00T00:00:00Z', 0, TimeValue::PRECISION_MONTH ),
$this->newTimeValue( '+2021-03-00T00:00:00Z', 0, TimeValue::PRECISION_MONTH )
],
$this->edtfToMultipleTimeValues( '2020-11/2021-03' )
);
}

}

0 comments on commit 1d9f772

Please sign in to comment.