/** * Get a TZID string from this VEVENT/VTODO/... component if we can * @param vComponent $comp * @return The TZID value we found, or null */ private static function GetTZID(vComponent $comp) { $p = $comp->GetProperty('DTSTART'); if (!isset($p) && $comp->GetType() == 'VTODO') { $p = $comp->GetProperty('DUE'); } if (!isset($p)) { return null; } return $p->GetParameterValue('TZID'); }
static function getInstance($name) { $qry = new AwlQuery('SELECT * FROM timezones WHERE tzid = ? ORDER BY active DESC', $name); if ($qry->Exec('VTimezone', __LINE__, __FILE__) && $qry->rows() > 0 && ($row = $qry->Fetch())) { $vtz = new vComponent($row->vtimezone); if ($vtz->GetType() == 'VTIMEZONE') { return $vtz; } $tmp = $vtz->GetComponents('VTIMEZONE'); if (count($tmp) < 1 || $tmp[0]->GetType() != 'VTIMEZONE') { return null; } $vtz = $tmp[0]; return $vtz; } return null; }
/** * Return a date range for this component. * @param vComponent $comp * @throws Exception (1) When DTSTART is not present but the RFC says MUST and (2) when we get an unsupported component * @return RepeatRuleDateRange */ function getComponentRange(vComponent $comp) { $dtstart_prop = $comp->GetProperty('DTSTART'); $duration_prop = $comp->GetProperty('DURATION'); if (isset($duration_prop)) { if (!isset($dtstart_prop)) { throw new Exception('Invalid ' . $comp->GetType() . ' containing DURATION without DTSTART', 0); } $dtstart = new RepeatRuleDateTime($dtstart_prop); $dtend = clone $dtstart; $dtend->modify(new Rfc5545Duration($duration_prop->Value())); } else { $completed_prop = null; switch ($comp->GetType()) { case 'VEVENT': if (!isset($dtstart_prop)) { throw new Exception('Invalid VEVENT without DTSTART', 0); } $dtend_prop = $comp->GetProperty('DTEND'); break; case 'VTODO': $completed_prop = $comp->GetProperty('COMPLETED'); $dtend_prop = $comp->GetProperty('DUE'); break; case 'VJOURNAL': if (!isset($dtstart_prop)) { $dtstart_prop = $comp->GetProperty('DTSTAMP'); } $dtend_prop = $dtstart_prop; default: throw new Exception('getComponentRange cannot handle "' . $comp->GetType() . '" components', 0); } if (isset($dtstart_prop)) { $dtstart = new RepeatRuleDateTime($dtstart_prop); } else { $dtstart = null; } if (isset($dtend_prop)) { $dtend = new RepeatRuleDateTime($dtend_prop); } else { $dtend = null; } if (isset($completed_prop)) { $completed = new RepeatRuleDateTime($completed_prop); if (!isset($dtstart) || isset($dtstart) && $completed < $dtstart) { $dtstart = $completed; } if (!isset($dtend) || isset($dtend) && $completed > $dtend) { $dtend = $completed; } } } return new RepeatRuleDateRange($dtstart, $dtend); }