Merge pull request #2482 from michaelnabil230/master
Replace function `getTimezones` in to collect
This commit is contained in:
@ -3,8 +3,8 @@
|
||||
namespace App\Traits;
|
||||
|
||||
use App\Traits\SearchString;
|
||||
use App\Utilities\Date;
|
||||
use Carbon\CarbonPeriod;
|
||||
use Date;
|
||||
|
||||
trait DateTime
|
||||
{
|
||||
@ -60,42 +60,24 @@ 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');
|
||||
$use_zones = ['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;
|
||||
}
|
||||
return collect($zones)
|
||||
->mapWithKeys(function ($timezone) use ($use_zones) {
|
||||
if (! in_array(str($timezone)->before('/'), $use_zones)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// 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 [$timezone => str($timezone)->after('/')->value()];
|
||||
})
|
||||
->groupBy(function ($item, $key) {
|
||||
return str($key)->before('/')->value();
|
||||
}, preserveKeys: true)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
public function getFinancialStart($year = null)
|
||||
|
Reference in New Issue
Block a user