Skip to content

Commit

Permalink
Refactor TimeZone class to handle empty time zones.
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Dec 17, 2023
1 parent eb2d9fa commit 9b53288
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/TimeZone.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 9b53288

Please sign in to comment.