validateStartAndEnd(); } public static function new(): self { return new DateTimeInterval(); } public function getArray(): array { if (!isset($this->start) && !isset($this->end)) { throw new LtiException(self::ERROR_NO_START_OR_END); } $this->validateStartAndEnd(); return [ 'startDateTime' => $this->start?->format(DateTime::ATOM), 'endDateTime' => $this->end?->format(DateTime::ATOM), ]; } public function setStart(?DateTime $start): self { $this->start = $start; return $this; } public function getStart(): ?DateTime { return $this->start; } public function setEnd(?DateTime $end): self { $this->end = $end; return $this; } public function getEnd(): ?DateTime { return $this->end; } /** * @throws LtiException */ private function validateStartAndEnd(): void { if (isset($this->start) && isset($this->end) && $this->start > $this->end) { throw new LtiException(self::ERROR_START_GT_END); } } }