get('timeZone'); if (!$string) { return null; } return new DateTimeZone($string); } /** * @return TimeRange[] */ public function getTimeRanges(): array { return self::convertRanges($this->get('timeRanges')); } /** * @param int<0,6> $weekday */ private function hasCustomWeekdayRanges(int $weekday): bool { $attribute = 'weekday' . $weekday . 'TimeRanges'; return $this->get($attribute) !== null && $this->get($attribute) !== []; } /** * @param int<0,6> $weekday * @return TimeRange[] */ private function getWeekdayTimeRanges(int $weekday): array { $attribute = 'weekday' . $weekday . 'TimeRanges'; $raw = $this->hasCustomWeekdayRanges($weekday) ? $this->get($attribute) : $this->get('timeRanges'); return self::convertRanges($raw); } /** * @return WorkingWeekday[] */ public function getWorkingWeekdays(): array { $list = []; for ($i = 0; $i <= 6; $i++) { if (!$this->get('weekday' . $i)) { continue; } $list[] = new WorkingWeekday($i, $this->getWeekdayTimeRanges($i)); } return $list; } /** * @param array{string, string}[] $ranges * @return TimeRange[] */ private static function convertRanges(array $ranges): array { $list = []; foreach ($ranges as $range) { $list[] = new TimeRange( self::convertTime($range[0]), self::convertTime($range[1]) ); } return $list; } private static function convertTime(string $time): Time { /** @var int<0, 23> $h */ $h = (int) explode(':', $time)[0]; /** @var int<0, 59> $m */ $m = (int) explode(':', $time)[1]; return new Time($h, $m); } }