From 9b53288cfb099a168924c80bb287610540a56490 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Sun, 17 Dec 2023 12:31:52 -0300 Subject: [PATCH] Refactor TimeZone class to handle empty time zones. --- src/TimeZone.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/TimeZone.php b/src/TimeZone.php index 3ea5146..cd877a9 100644 --- a/src/TimeZone.php +++ b/src/TimeZone.php @@ -24,15 +24,17 @@ public static function getAll(): array $listsIdentifiers = DateTimeZone::listIdentifiers(); foreach ($listsIdentifiers as $timeZone) { - $name = str_replace('_', ' ', $timeZone); - $date = new DateTime('now', new DateTimeZone($timeZone)); - $timeZones[] = - [ - 'timezone' => $timeZone, - 'name' => "$name (UTC {$date->format('P')})", - 'offset' => $date->getOffset(), - ] - ; + if (!empty($timeZone)) { + $name = str_replace('_', ' ', $timeZone); + $date = new DateTime('now', new DateTimeZone($timeZone)); + $timeZones[] = + [ + 'timezone' => $timeZone, + 'name' => "$name (UTC {$date->format('P')})", + 'offset' => $date->getOffset(), + ] + ; + } } $offsets = array_column($timeZones, 'offset');