0.1.0
This commit is contained in:
41
app/Helper/Timezones.php
Normal file
41
app/Helper/Timezones.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user