function get($base, $opts=array())
{
- self::getOffsets();
+ self::getTimezones();
$data = array();
- foreach(self::$offsets as $tz => $o) {
- $arr = explode('/', $tz);
-
- if(!empty($_REQUEST['region']) && $_REQUEST['region'] != $arr[0]) {
+ foreach(self::$timezones as $tz => $o) {
+ if(!empty($_REQUEST['region']) && $_REQUEST['region'] != $o['region']) {
continue;
}
- $areaStartSeach = $_REQUEST['query']['area_start'];
- if(!empty($areaStartSeach) && substr(strtolower($arr[1]), 0, strlen($areaStartSeach)) != strtolower($areaStartSeach)){
+ if(
+ !empty($_REQUEST['query']['area_start'])
+ &&
+ substr(strtolower($o['area']), 0, strlen($_REQUEST['query']['area_start'])) != strtolower($_REQUEST['query']['area_start'])
+ ){
continue;
}
$data[] = array(
- 'region' => $arr[0],
- 'area' => $arr[1],
- 'offset' => $o,
- 'displayArea' => self::getDisplayArea($tz)
+ 'region' => $o['region'],
+ 'area' => $o['area'],
+ 'displayArea' => $o['displayArea']
);
}
'fields' => array(
'region',
'area',
- 'offset',
'displayArea'
)
),
die('Invalid post');
}
- static $offsets = array();
+ static $timezones = array();
- static function getOffsets()
+ static function getTimezones()
{
- if(!empty(self::$offsets)) {
- return self::$offsets;
+ if(!empty(self::$timezones)) {
+ return self::$timezones;
}
$ce = DB_DataObject::factory('core_enum');
- $ce->query('
+ $ce->query("
SELECT
- *, TIME_FORMAT(TIMEDIFF(NOW(), CONVERT_TZ(NOW(), Name, "UTC")), "%H:%i") as offset
+ *, TIME_FORMAT(TIMEDIFF(NOW(), CONVERT_TZ(NOW(), Name, 'UTC')), '%H:%i') as timeOffset
FROM
mysql.time_zone_name
+ WHERE
+ Name NOT LIKE '%/%'
+ AND
+ NAME NOT LIKE 'Etc%'
ORDER BY
- offset DESC,
+ timeoffset DESC,
Name DESC
- ');
+ ");
while($ce->fetch()) {
// ignroe timezone such as 'CET' and 'America/Argentina/Buenos_Aires'
continue;
}
- self::$offsets[$ce->Name] = substr($ce->offset, 0, 1) == '-' ? $ce->offset : '+' . $ce->offset;
- }
+ $displayArea = str_replace('_', ' ', $ar[1]);
- return self::$offsets;
- }
+ $timeOffset = ((substr($ce->timeOffset, 0, 1) == '-') ? '' : '+') . $ce->timeOffset;
+ $displayOffset = '(GMT ' . $timeOffset . ')';
- static function getDisplayArea($timezone)
- {
- self::getOffsets();
-
- // invalid timezone
- if(!isset(self::$offsets[$timezone])) {
- return '';
+ self::$timezones[$ce->Name] = array(
+ 'region' => $ar[0],
+ 'area' => $ar[1],
+ 'displayName' => $ar[0] . '/' . $displayArea . ' ' . $displayOffset,
+ 'displayArea' => $displayArea . ' ' . $displayOffset,
+ 'timeOffset' => $timeOffset
+ );
}
- $ar = explode('/', $timezone);
-
- // e.g. 'Hong_Kong (GMT +08:00)'
- return $ar[1] . ' (GMT ' . self::$offsets[$timezone] . ')';
+ return self::$timezones;
}