new static calendar_timezones::DateTimeZone($tzid) method returning a

DateTimeZone object resolving by PHP not supported Windows timezones
with their standard alias
This commit is contained in:
Ralf Becker 2009-11-10 20:07:33 +00:00
parent 4865854281
commit 9df8b0bdbf
2 changed files with 50 additions and 2 deletions

View File

@ -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)

View File

@ -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 '<h3>'.count($found).' found, '.count($not_found)." <b>NOT</b> found</h3>\n";
if ($not_found) echo "<pre>\n\$no_vtimezone = array(\n\t'".implode("',\n\t'",$not_found)."',\n);\n</pre>\n";
echo "<h3>Testing availability of PHP support for each TZID supported by EGroupware's timezone database:</h3>\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<br />\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 <b>alias</b><br />\n";
unset($e);
}
catch(Exception $e)
{
// ignore
}
}
if (isset($e)) echo $row['tz_tzid'].": <b>NOT</b> available<br />\n";
}
}
}
else*/
calendar_timezones::init_static();