Replace function getTimezones
in to collect
This commit is contained in:
parent
70e6cce306
commit
fbbc24e4b4
@ -2,9 +2,11 @@
|
|||||||
|
|
||||||
namespace App\Traits;
|
namespace App\Traits;
|
||||||
|
|
||||||
use App\Traits\SearchString;
|
|
||||||
use Carbon\CarbonPeriod;
|
|
||||||
use Date;
|
use Date;
|
||||||
|
use DateTimeZone;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Carbon\CarbonPeriod;
|
||||||
|
use App\Traits\SearchString;
|
||||||
|
|
||||||
trait DateTime
|
trait DateTime
|
||||||
{
|
{
|
||||||
@ -59,42 +61,13 @@ trait DateTime
|
|||||||
|
|
||||||
public function getTimezones()
|
public function getTimezones()
|
||||||
{
|
{
|
||||||
$groups = [];
|
return collect(DateTimeZone::listIdentifiers())
|
||||||
|
->mapWithKeys(function ($timezone) {
|
||||||
// The list of available timezone groups to use.
|
return [$timezone => Str::after($timezone, '/')];
|
||||||
$use_zones = array('Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific');
|
})
|
||||||
|
->groupBy(function ($item, $key) {
|
||||||
// Get the list of time zones from the server.
|
return Str::before($key, '/');
|
||||||
$zones = \DateTimeZone::listIdentifiers();
|
}, preserveKeys: true);;
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFinancialStart($year = null)
|
public function getFinancialStart($year = null)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user