start = $start !== null ? \DateTimeImmutable::createFromInterface($start) : null; $this->end = $end !== null ? \DateTimeImmutable::createFromInterface($end) : null; if ($this->start !== null && $this->end !== null) { Assert::true($this->start <= $this->end, 'The start date must be before or equal to the end date.'); } } public function isActiveAt(?\DateTimeInterface $date = null): bool { $target = $date !== null ? \DateTimeImmutable::createFromInterface($date) : new \DateTimeImmutable(); if ($this->start !== null && $target < $this->start) { return false; } if ($this->end !== null && $target > $this->end) { return false; } return true; } }