41 lines
946 B
PHP
41 lines
946 B
PHP
<?php
|
|
|
|
namespace App\Helper;
|
|
|
|
use DateTimeZone;
|
|
|
|
class Timezones
|
|
{
|
|
|
|
public function groups(): array
|
|
{
|
|
return ['Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Australia', 'Europe', 'Indian', 'Pacific', 'UTC'];
|
|
}
|
|
|
|
public function locations(string $group): array
|
|
{
|
|
return DateTimeZone::listIdentifiers(DateTimeZone::{strtoupper($group)});
|
|
}
|
|
|
|
public function toArray(): array
|
|
{
|
|
$tzForSelect = [];
|
|
|
|
foreach (DateTimeZone::listIdentifiers() as $timezone) {
|
|
$tz = explode('/', $timezone);
|
|
if (!isset($tz[1])) {
|
|
$tzForSelect['UTC']['UTC'] = 'UTC';
|
|
} else {
|
|
if (isset($tz[2])) {
|
|
$tzForSelect[$tz[0]][$tz[1]] = $tz[1]."/".$tz[2];
|
|
} else {
|
|
$tzForSelect[$tz[0]][$timezone] = $tz[1];
|
|
}
|
|
}
|
|
}
|
|
|
|
return $tzForSelect;
|
|
}
|
|
|
|
}
|