Skip to content

Commit

Permalink
Merge branch '1.3.x' of https://github.com/joy2362/php-time-zone into…
Browse files Browse the repository at this point in the history
… 1.3.x
  • Loading branch information
joy2362 committed Jun 28, 2024
2 parents df9bad9 + a81fde6 commit 4925ab5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/PhpTimeZoneServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ public function register()
return new TimeZoneService();
});
}
}
}
28 changes: 14 additions & 14 deletions src/TimeZoneService.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function listWithoutLabel(): array
{
$list = [];
foreach ($this->regions as $region) {
$list[] = $this->getTimeZoneList(DateTimeZone::listIdentifiers($region) ?? [] , false);
$list[] = $this->getTimeZoneList(DateTimeZone::listIdentifiers($region) ?? [], false);
}
return $list;
}
Expand All @@ -76,7 +76,7 @@ public function listWithoutValue(): array
{
$list = [];
foreach ($this->regions as $region) {
$list[] = $this->getTimeZoneList(DateTimeZone::listIdentifiers($region) ?? [] , true , false);
$list[] = $this->getTimeZoneList(DateTimeZone::listIdentifiers($region) ?? [], true, false);
}
return $list;
}
Expand Down Expand Up @@ -119,8 +119,8 @@ private function getLabel($timezone): string
$time = new DateTime('', new DateTimeZone($timezone));
$time_diff = $this->getTimeDiff($time);
$zone = $this->getZone($time);
$defaultTimeZone = Config::get('Timezone.DEFAULT_TIME_ZONE' , 'GMT');

$defaultTimeZone = Config::get('Timezone.DEFAULT_TIME_ZONE', 'GMT');
$defaultTimeZone = in_array($defaultTimeZone, $this->supportedTimeZone) ? $defaultTimeZone : $this->supportedTimeZone[0];
return "({$defaultTimeZone} {$time_diff}) {$zone}";
} catch (Exception $ex) {
Expand All @@ -134,7 +134,7 @@ private function getLabel($timezone): string
*/
private function getTimeDiff($time): string
{
$time_diff_symbol = Config::get('Timezone.TIME_DIFF_SYMBOL','.');
$time_diff_symbol = Config::get('Timezone.TIME_DIFF_SYMBOL', '.');
$str_time_diff = $time->format('p');
return str_replace(':', $time_diff_symbol, $str_time_diff);
}
Expand All @@ -147,31 +147,31 @@ private function getZone($time): string
{
return str_replace('_', ' ', $time->format('e'));
}

/**
* @param array $timezones
* @param bool $isLabel
* @param bool $isValue
* @return array
*/
private function getTimeZoneList(array $timezones , bool $isLabel = true , bool $isValue = true): array
private function getTimeZoneList(array $timezones, bool $isLabel = true, bool $isValue = true): array
{
$label = Config::get('Timezone.LABEL_FIELD_NAME','label');
$value = Config::get('Timezone.VALUE_FIELD_NAME','value');
$label = Config::get('Timezone.LABEL_FIELD_NAME', 'label');
$value = Config::get('Timezone.VALUE_FIELD_NAME', 'value');

$data = [];

foreach ($timezones as $timezone) {
if($isLabel ){
if($isLabel) {
$data[$label] = $this->getLabel($timezone);
}

if($isValue ){
if($isValue) {
$data[$value] = $timezone;
}

}

return $data;
}
}
}

0 comments on commit 4925ab5

Please sign in to comment.