Skip to content

Commit

Permalink
Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
EnesSacid-Buker committed Feb 16, 2023
1 parent 25a4aaf commit 7093afe
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions app/Traits/DateTime.php
Expand Up @@ -2,11 +2,9 @@

namespace App\Traits;

use Date;
use DateTimeZone;
use Illuminate\Support\Str;
use Carbon\CarbonPeriod;
use App\Traits\SearchString;
use App\Utilities\Date;
use Carbon\CarbonPeriod;

trait DateTime
{
Expand Down Expand Up @@ -61,13 +59,24 @@ public function scopeMonthsOfYear($query, $field)

public function getTimezones()
{
return collect(DateTimeZone::listIdentifiers())
->mapWithKeys(function ($timezone) {
return [$timezone => Str::after($timezone, '/')];
})
->groupBy(function ($item, $key) {
return Str::before($key, '/');
}, preserveKeys: true);
// The list of available timezone groups to use.
$use_zones = ['Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific'];

// Get the list of time zones from the server.
$zones = \DateTimeZone::listIdentifiers();

return collect($zones)
->mapWithKeys(function ($timezone) use ($use_zones) {
if (! in_array(str($timezone)->before('/'), $use_zones)) {
return [];
}

return [$timezone => str($timezone)->after('/')->value()];
})
->groupBy(function ($item, $key) {
return str($key)->before('/')->value();
}, preserveKeys: true)
->toArray();
}

public function getFinancialStart($year = null)
Expand Down

0 comments on commit 7093afe

Please sign in to comment.