Replace function getTimezones
in to collect
This commit is contained in:
parent
70e6cce306
commit
fbbc24e4b4
@ -2,9 +2,11 @@
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use App\Traits\SearchString;
|
||||
use Carbon\CarbonPeriod;
|
||||
use Date;
|
||||
use DateTimeZone;
|
||||
use Illuminate\Support\Str;
|
||||
use Carbon\CarbonPeriod;
|
||||
use App\Traits\SearchString;
|
||||
|
||||
trait DateTime
|
||||
{
|
||||
@ -59,42 +61,13 @@ trait DateTime
|
||||
|
||||
public function getTimezones()
|
||||
{
|
||||
$groups = [];
|
||||
|
||||
// The list of available timezone groups to use.
|
||||
$use_zones = array('Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific');
|
||||
|
||||
// Get the list of time zones from the server.
|
||||
$zones = \DateTimeZone::listIdentifiers();
|
||||
|
||||
// Build the group lists.
|
||||
foreach ($zones as $zone) {
|
||||
// Time zones not in a group we will ignore.
|
||||
if (strpos($zone, '/') === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get the group/locale from the timezone.
|
||||
list ($group, $locale) = explode('/', $zone, 2);
|
||||
|
||||
// Only use known groups.
|
||||
if (in_array($group, $use_zones)) {
|
||||
// Initialize the group if necessary.
|
||||
if (!isset($groups[$group])) {
|
||||
$groups[$group] = [];
|
||||
}
|
||||
|
||||
// Only add options where a locale exists.
|
||||
if (!empty($locale)) {
|
||||
$groups[$group][$zone] = str_replace('_', ' ', $locale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sort the group lists.
|
||||
ksort($groups);
|
||||
|
||||
return $groups;
|
||||
return collect(DateTimeZone::listIdentifiers())
|
||||
->mapWithKeys(function ($timezone) {
|
||||
return [$timezone => Str::after($timezone, '/')];
|
||||
})
|
||||
->groupBy(function ($item, $key) {
|
||||
return Str::before($key, '/');
|
||||
}, preserveKeys: true);;
|
||||
}
|
||||
|
||||
public function getFinancialStart($year = null)
|
||||
|
Loading…
x
Reference in New Issue
Block a user