1: <?php
2: declare(strict_types=1);
3:
4: namespace om\ICal;
5:
6: use DateTimeImmutable;
7: use DateTimeZone;
8: use om\ICal\Value\DateTimeValue;
9:
10: /**
11: * One instance of an event, task or journal entry.
12: *
13: * For a modified instance, $item is the override (the component with the RECURRENCE-ID)
14: * and $master the recurring item; otherwise both are the same.
15: */
16: final readonly class Occurrence {
17: /**
18: * @param ?DateTimeValue $recurrenceId original start of a recurring instance, null for a single item
19: */
20: public function __construct(
21: public DateTimeValue $start,
22: public DateTimeValue $end,
23: public Item $item,
24: public Item $master,
25: public ?DateTimeValue $recurrenceId = null,
26: ) {
27: }
28:
29: public function isRecurring(): bool {
30: return $this->recurrenceId !== null;
31: }
32:
33: /** True when the instance comes from an override (a component with a RECURRENCE-ID). */
34: public function isModified(): bool {
35: return $this->item !== $this->master;
36: }
37:
38: public function isCancelled(): bool {
39: return $this->item->isCancelled();
40: }
41:
42: public function isAllDay(): bool {
43: return $this->start->isDate();
44: }
45:
46: public function summary(): ?string {
47: return $this->item->summary();
48: }
49:
50: /**
51: * Start as an instant; dates and floating times use the given timezone or the
52: * floating timezone of the calendar.
53: */
54: public function startTime(?DateTimeZone $timezone = null): DateTimeImmutable {
55: return $this->start->toDateTime($timezone, $this->item->calendar()->floatingTimezone());
56: }
57:
58: public function endTime(?DateTimeZone $timezone = null): DateTimeImmutable {
59: return $this->end->toDateTime($timezone, $this->item->calendar()->floatingTimezone());
60: }
61: }
62: