public function __construct($cal, $siteId = null) { if (!isset($cal) || !is_array($cal) && !is_string($cal)) { return; } $this->component = new CDavICalendarComponent(); if (is_string($cal)) { $this->component->InitializeFromString($cal); } else { $this->component->SetType('VCALENDAR'); $this->component->SetProperties(array(new CDavICalendarProperty('VERSION:2.0'), new CDavICalendarProperty('PRODID:-//davical.org//NONSGML AWL Calendar//EN'), new CDavICalendarProperty('METHOD:PUBLISH'))); $arComps = array(); $tz = CDavICalendarTimeZone::GetTimezone(CDavICalendarTimeZone::getTimeZoneId()); if (!empty($tz)) { $comptz = new CDavICalendarComponent(); $comptz->InitializeFromString($tz); $arComps[] = $comptz; } $comp = new CDavICalendarComponent(); $comp->InitializeFromArray($cal); $arComps[] = $comp; $this->component->SetComponents($arComps); } }
public static function getTimezoneByOffset($date, $offset) { foreach (self::$arTimeZones as $timeZoneCode => $timeZoneText) { $t = new CDavICalendarComponent(); $t->InitializeFromString($timeZoneText); if ($t) { $arTimeMap = array(); $comps = $t->GetComponents(); foreach ($comps as $comp) { $t = self::ParseVTimezone($comp, intval(date("Y", $date))); if ($t !== false) { $arTimeMap[] = $t; } } if ($arTimeMap) { usort($arTimeMap, function ($a, $b) { return $a['time'] > $b['time'] ? 1 : ($a['time'] < $b['time'] ? -1 : 0); }); if ($date < $arTimeMap[0]['time'] && $arTimeMap[0]['from'] == $offset) { return $timeZoneCode; } for ($i = 0, $n = count($arTimeMap); $i < $n - 1; $i++) { if ($date >= $arTimeMap[$i]['time'] && $date < $arTimeMap[$i + 1]['time'] && $arTimeMap[$i]['to'] == $offset) { return $timeZoneCode; } } if ($date >= $arTimeMap[$n - 1]['time'] && $arTimeMap[$n - 1]['to'] == $offset) { return $timeZoneCode; } } } } return false; }