2 require_once 'Pman.php';
4 class Pman_Core_TimeZone extends Pman
10 if (!$this->getAuthUser()) {
11 $this->jerr("Not authenticated", array('authFailure' => true));
17 function get($base, $opts=array())
23 foreach(self::$timezones as $tz => $o) {
24 if(!empty($_REQUEST['region']) && $_REQUEST['region'] != $o['region']) {
29 !empty($_REQUEST['query']['area_start'])
31 substr(strtolower($o['area']), 0, strlen($_REQUEST['query']['area_start'])) != strtolower($_REQUEST['query']['area_start'])
36 'region' => $o['region'],
38 'displayArea' => $o['displayArea']
42 echo json_encode(array(
46 'successProperty' => 'success',
47 'totalProperty' => 'total',
55 'total' => count($data),
61 function post($base) {
65 static $timezones = array();
67 static function getTimezones()
69 if(!empty(self::$timezones)) {
70 return self::$timezones;
73 $ce = DB_DataObject::factory('core_enum');
76 *, TIME_FORMAT(TIMEDIFF(NOW(), CONVERT_TZ(NOW(), Name, 'UTC')), '%H:%i') as timeOffset
85 // ignroe timezone such as 'CET' and 'America/Argentina/Buenos_Aires'
86 if(substr_count($ce->Name, '/') != 1) {
90 $ar = explode('/', $ce->Name);
91 // ignore timezone such as 'Etc/GMT+8'
96 $displayArea = str_replace('_', ' ', $ar[1]);
98 $timeOffset = ((substr($ce->timeOffset, 0, 1) == '-') ? '' : '+') . $ce->timeOffset;
99 $displayOffset = '(GMT ' . $timeOffset . ')';
101 self::$timezones[$ce->Name] = array(
104 'displayName' => $ar[0] . '/' . $displayArea . ' ' . $displayOffset,
105 'displayArea' => $displayArea . ' ' . $displayOffset,
106 'timeOffset' => $timeOffset
110 return self::$timezones;
113 static function getTimeOffset($dt, $tz)
115 $date = new DateTime($dt, new DateTimeZone($tz));
116 return $date->format('P');