Skip to content

Commit

Permalink
[FEATURE] Enable TimeSpan with null end
Browse files Browse the repository at this point in the history
This commit allows creating TimeSpan Object only with `DTSTART` set.
As a starting time without ending is allowed in iCal definitions,
this package should respect the ability having no end time set, too.
  • Loading branch information
calien666 committed Oct 17, 2023
1 parent 8be6855 commit 7493665
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/Domain/ValueObject/TimeSpan.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
final class TimeSpan extends Occurrence
{
private DateTime $begin;
private DateTime $end;
private ?DateTime $end;

public function __construct(DateTime $begin, DateTime $end)
public function __construct(DateTime $begin, ?DateTime $end = null)
{
$this->begin = $begin;
$this->end = $end;
}

public static function create(DateTime $begin, DateTime $end): self
public static function create(DateTime $begin, ?DateTime $end = null): self
{
return new static($begin, $end);
}
Expand All @@ -32,7 +32,7 @@ public function getBegin(): DateTime
return $this->begin;
}

public function getEnd(): DateTime
public function getEnd(): ?DateTime
{
return $this->end;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Presentation/Factory/EventFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ private function getOccurrenceProperties(Occurrence $occurrence): Generator

if ($occurrence instanceof TimeSpan) {
yield $this->dateTimeFactory->createProperty('DTSTART', $occurrence->getBegin());
yield $this->dateTimeFactory->createProperty('DTEND', $occurrence->getEnd());
if ($occurrence->getEnd() !== null) {
yield $this->dateTimeFactory->createProperty('DTEND', $occurrence->getEnd());
}
}
}

Expand Down

0 comments on commit 7493665

Please sign in to comment.