1: <?php
2: /*
3: You may not change or alter any portion of this comment or credits
4: of supporting developers from this source code or any supporting source code
5: which is considered copyrighted (c) material of the original comment or credit authors.
6:
7: This program is distributed in the hope that it will be useful,
8: but WITHOUT ANY WARRANTY; without even the implied warranty of
9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: */
11:
12: namespace Xoops\Core\Lists;
13:
14: use Xoops\Core\Locale\Punic\Calendar;
15: use Punic\Territory;
16:
17: /**
18: * TimeZone - provide list of timezone names
19: *
20: * @category Xoops\Core\Lists\TimeZone
21: * @package Xoops\Core
22: * @author Richard Griffith <richard@geekwright.com>
23: * @copyright 2015 XOOPS Project (http://xoops.org)/
24: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
25: * @link http://xoops.org
26: */
27: class TimeZone extends ListAbstract
28: {
29: /**
30: * Get a list of localized timezone names
31: *
32: * @return array
33: */
34: public static function getList()
35: {
36: $xoops = \Xoops::getInstance();
37: $locale = \Xoops\Locale::getCurrent();
38: $key = ['system', 'lists', 'timezone', $locale];
39: //$xoops->cache()->delete($key);
40: $timeZones = $xoops->cache()->cacheRead(
41: $key,
42: function () {
43: $timeZones = array();
44: $territories = Territory::getContinentsAndCountries();
45: $maxLen = 0;
46: $utcDtz = new \DateTimeZone('UTC');
47: foreach ($territories as $byContinent) {
48: $continent = $byContinent['name'];
49: foreach ($byContinent['children'] as $cCode => $cName) {
50: $allZones = $utcDtz->listIdentifiers(\DateTimeZone::PER_COUNTRY, $cCode);
51: foreach ($allZones as $zone) {
52: $maxLen = max(strlen($zone), $maxLen);
53: $name = Calendar::getTimezoneExemplarCity($zone);
54: if (!isset($timeZones[$zone]) && !empty($name)) {
55: $timeZones[$zone] = $continent . '/' . $name;
56: }
57: }
58: }
59: }
60: \XoopsLocale::asort($timeZones);
61: $default = array(
62: 'UTC' => Calendar::getTimezoneNameNoLocationSpecific(new \DateTimeZone('GMT')),
63: );
64: $timeZones = array_merge($default, $timeZones);
65: return $timeZones;
66: }
67: );
68:
69: return $timeZones;
70: }
71: }
72: