From 9df8b0bdbf7bb3e8b723cd630b3a4d91bb8612c2 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 10 Nov 2009 20:07:33 +0000 Subject: [PATCH] new static calendar_timezones::DateTimeZone($tzid) method returning a DateTimeZone object resolving by PHP not supported Windows timezones with their standard alias --- calendar/inc/class.calendar_ical.inc.php | 4 +- calendar/inc/class.calendar_timezones.inc.php | 48 +++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/calendar/inc/class.calendar_ical.inc.php b/calendar/inc/class.calendar_ical.inc.php index d9ee350c7e..c2ef533067 100644 --- a/calendar/inc/class.calendar_ical.inc.php +++ b/calendar/inc/class.calendar_ical.inc.php @@ -752,7 +752,7 @@ class calendar_ical extends calendar_boupdate static $timezone_tzid; if (is_null($timezone) || $timezone_tzid != $tzid) { - $timezone = new DateTimeZone($timezone_tzid = $tzid); + $timezone = calendar_timezones::DateTimeZone($timezone_tzid = $tzid); } $time->setTimezone($timezone); $params['TZID'] = $tzid; @@ -1507,7 +1507,7 @@ class calendar_ical extends calendar_boupdate { try { - $tz = new DateTimeZone($attributes['params']['TZID']); + $tz = calendar_timezones::DateTimeZone($attributes['params']['TZID']); $event['tzid'] = $tz->getName(); } catch(Exception $e) diff --git a/calendar/inc/class.calendar_timezones.inc.php b/calendar/inc/class.calendar_timezones.inc.php index f84938d74b..71edefac5d 100644 --- a/calendar/inc/class.calendar_timezones.inc.php +++ b/calendar/inc/class.calendar_timezones.inc.php @@ -55,6 +55,24 @@ class calendar_timezones */ protected static $tz2id = array(); + /** + * Get DateTimeZone object for a given TZID + * + * We use our database to replace eg. Windows timezones not understood by PHP with their standard TZID + * + * @param string $tzid + * @return DateTimeZone + * @throws Exception if called with an unknown TZID + */ + public function DateTimeZone($tzid) + { + if (($id = self::tz2id($tzid,'alias'))) + { + $tzid = self::id2tz($id); + } + return new DateTimeZone($tzid); + } + /** * Get the nummeric id (or other data) for a given TZID * @@ -242,6 +260,36 @@ if (isset($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == __FILE_ echo '

'.count($found).' found, '.count($not_found)." NOT found

\n"; if ($not_found) echo "
\n\$no_vtimezone = array(\n\t'".implode("',\n\t'",$not_found)."',\n);\n
\n"; + + echo "

Testing availability of PHP support for each TZID supported by EGroupware's timezone database:

\n"; + foreach($GLOBALS['egw']->db->select('egw_cal_timezones','*',false,__LINE__,__FILE__,false,'','calendar') as $row) + { + try + { + $timezone = new DateTimeZone($row['tz_tzid']); + //$timezone = calendar_timezones::DateTimeZone($row['tz_tzid']); + echo $row['tz_tzid'].": available
\n"; + } + catch(Exception $e) + { + if (($id = calendar_timezones::tz2id($row['tz_tzid'],'alias')) && + ($alias = calendar_timezones::id2tz($id))) + { + + try + { + $timezone = new DateTimeZone($alias); + echo $row['tz_tzid']."='$alias': available through alias
\n"; + unset($e); + } + catch(Exception $e) + { + // ignore + } + } + if (isset($e)) echo $row['tz_tzid'].": NOT available
\n"; + } + } } else*/ calendar_timezones::init_static();