1: <?php
2: declare(strict_types=1);
3:
4: namespace om\ICal;
5:
6: use om\ICal\Timezone\ResolvedTimezone;
7: use om\ICal\Timezone\VTimezoneResolver;
8: use om\ICal\Value\Text;
9:
10: /**
11: * A VTIMEZONE component (RFC 5545, section 3.6.5).
12: */
13: final class TimezoneDefinition {
14: /**
15: * @internal use Calendar::timezones()
16: */
17: public function __construct(
18: public readonly Component $component,
19: private readonly Calendar $calendar,
20: ) {
21: }
22:
23: public function tzid(): ?string {
24: $tzid = $this->component->property('TZID')?->value;
25: return $tzid === null ? null : Text::unescape($tzid);
26: }
27:
28: /**
29: * The PHP timezone used for this TZID (see TimezoneResolver).
30: */
31: public function resolve(): ?ResolvedTimezone {
32: $tzid = $this->tzid();
33: return $tzid === null ? null : $this->calendar->values()->timezone($tzid);
34: }
35:
36: /**
37: * STANDARD and DAYLIGHT observances.
38: *
39: * @return list<array{start: string, offsetFrom: string, offsetTo: string, rrule: ?string, rdates: list<string>}>
40: */
41: public function observances(): array {
42: return VTimezoneResolver::observances($this->component);
43: }
44: }
45: