diff --git a/app/Providers/ExtendedTimezonelistProvider.php b/app/Providers/ExtendedTimezonelistProvider.php new file mode 100644 index 00000000..3c5a8912 --- /dev/null +++ b/app/Providers/ExtendedTimezonelistProvider.php @@ -0,0 +1,30 @@ +app->singleton('timezonelist', function ($app) { + return new TimezonelistExtended; + }); + } +} diff --git a/app/Support/TimezonelistExtended.php b/app/Support/TimezonelistExtended.php new file mode 100644 index 00000000..9a708adb --- /dev/null +++ b/app/Support/TimezonelistExtended.php @@ -0,0 +1,107 @@ +format('P'); + if ($htmlencode) { + $offset = str_replace('-', ' − ', $offset); + $offset = str_replace('+', ' + ', $offset); + } + $timezone = substr($timezone, strlen($continent) + 1); + $timezone = str_replace('St_', 'St. ', $timezone); + $timezone = str_replace('_', ' ', $timezone); + $formatted = '(GMT/UTC' . $offset . ')' . self::WHITESPACE_SEP . $timezone; + return $formatted; + } + + /** + * Create a GMT timezone select element for form + * + * @param string $name + * @param string $selected + * @param mixed $attr + * @param bool $htmlencode + * @return string + */ + public function create($name, $selected='', $attr='', $htmlencode=true) + { + // Attributes for select element + $attrSet = null; + if (!empty($attr)) { + if (is_array($attr)) { + foreach ($attr as $attr_name => $attr_value) { + $attrSet .= ' ' .$attr_name. '="' .$attr_value. '"'; + } + } else { + $attrSet = ' ' .$attr; + } + } + // start select element + $listbox = ''; + return $listbox; + } + + /** + * Create a timezone array + * + * @param bool $htmlencode + * @return mixed + */ + public function toArray($htmlencode=false) + { + $list = []; + // Add popular timezones to list + foreach ($this->popularTimezones as $key => $value) { + $list['General'][$key] = $value; + } + // Add all timezone of continents to list + foreach ($this->continents as $continent => $mask) { + $timezones = DateTimeZone::listIdentifiers($mask); + foreach ($timezones as $timezone) { + $list[$continent][$timezone] = $this->formatTimezone($timezone, $continent, $htmlencode); + } + } + return $list; + } +} \ No newline at end of file diff --git a/config/app.php b/config/app.php index 6b496b9a..4a1ca401 100755 --- a/config/app.php +++ b/config/app.php @@ -90,6 +90,7 @@ return [ App\Providers\EventServiceProvider::class, App\Providers\RouteServiceProvider::class, App\Providers\vaCentralServiceProvider::class, + App\Providers\ExtendedTimezonelistProvider::class, ], 'aliases' => [