<?php
namespace Moto\Application\Util; class Timezones { protected static $_timezoneList = null; protected static $_timezoneValues = array(); public static function getList() { if (static::$_timezoneList !== null) { return static::$_timezoneList; } if (static::getFailedDependency()) { return null; } $result = array_merge(static::_getIdentifiersList(), static::_getManualList()); $result = array_values($result); return $result; } public static function getFailedDependency() { $result = array(); if (!function_exists('timezone_identifiers_list')) { $result[] = 'timezone_identifiers_list'; } if (!function_exists('date_default_timezone_set')) { $result[] = 'date_default_timezone_set'; } if (empty($result)) { $result = null; } return $result; } public static function isExists($value) { static::getList(); return array_key_exists($value, static::$_timezoneValues); } protected static function _getIdentifiersList() { $timezones = array(); $identifiers = timezone_identifiers_list(); foreach ($identifiers as $value) { $zoneParts = explode('/', $value, 2); if (count($zoneParts) < 2) { continue; } $category = $zoneParts[0]; $name = $zoneParts[1]; $name = str_replace(array('/', '_'), array(', ', ' '), $name); static::$_timezoneValues[$value] = true; $timezones[] = array( 'name' => $name, 'value' => $value, 'category' => $category ); } return $timezones; } protected static function _getManualList() { $timezones = array(); for ($offset = -12; $offset <= 14; $offset++) { if ($offset === 0) { $value = 'UTC'; $name = 'UTC 0'; } else { $value = 'Etc/GMT' . ($offset > 0 ? '-' : '+') . abs($offset); $name = 'UTC ' . ($offset > 0 ? '+' : '-') . abs($offset); } static::$_timezoneValues[$value] = true; $timezones[] = array( 'name' => $name, 'value' => $value, 'category' => 'Manual Offsets' ); } return $timezones; } } 