user = $user; $this->resource = $resource; // Normalised to midnight so a stray time component cannot shift which day this belongs to. $this->date = $date->setTime(0, 0); $this->startMinute = $time->startMinute; $this->endMinute = $time->endMinute; $this->series = $series; $this->createdAt = new \DateTimeImmutable(); } public function getId(): ?int { return $this->id; } public function getUser(): User { return $this->user; } public function getResource(): Resource { return $this->resource; } public function getDate(): \DateTimeImmutable { return $this->date; } public function getTimeRange(): TimeRange { return TimeRange::fromMinutes($this->startMinute, $this->endMinute); } /** * Changing the times of an occurrence marks it as an override, so the UI can show that it * no longer matches its series. */ public function changeTime(TimeRange $time): void { $this->startMinute = $time->startMinute; $this->endMinute = $time->endMinute; if (null !== $this->series) { $this->overridden = !$this->series->getTimeRange()->equals($time); } } public function getSeries(): ?BookingSeries { return $this->series; } public function isPartOfSeries(): bool { return null !== $this->series; } public function isOverridden(): bool { return $this->overridden; } public function getCreatedAt(): \DateTimeImmutable { return $this->createdAt; } public function belongsTo(User $user): bool { return $this->user->getId() === $user->getId(); } public function overlaps(TimeRange $time): bool { return $this->getTimeRange()->overlaps($time); } }