1: <?php
2: declare(strict_types=1);
3:
4: namespace om\ICal;
5:
6: use DateInterval;
7: use om\ICal\Value\DateTimeValue;
8: use om\ICal\Value\Period;
9:
10: /**
11: * VFREEBUSY (RFC 5545, section 3.6.4).
12: */
13: final class FreeBusy extends Item {
14: public function end(): ?DateTimeValue {
15: return $this->date('DTEND');
16: }
17:
18: public function duration(): DateInterval {
19: $start = $this->start();
20: $end = $this->end();
21: return $start !== null && $end !== null ? self::between($start, $end) : new DateInterval('PT0S');
22: }
23:
24: /**
25: * FREEBUSY periods with their type (FBTYPE: BUSY by default, FREE, BUSY-UNAVAILABLE, BUSY-TENTATIVE).
26: *
27: * @return list<array{Period, string}>
28: */
29: public function periods(): array {
30: $result = [];
31: foreach ($this->properties('FREEBUSY') as $property) {
32: $type = strtoupper($property->parameter('FBTYPE') ?? 'BUSY');
33: foreach ($this->calendar->values()->periods($property) as $period) {
34: $result[] = [$period, $type];
35: }
36: }
37: return $result;
38: }
39: }
40: