tzid = $data['tzid']; $this->daylight = $data['daylight']; $this->standard = $data['standard']; } /** * Returns the timezone-id for this timezone. (Used to * differentiate between different tzs in a calendar) * @return string */ public function getTimeZoneId() { return $this->tzid; } /** * Returns the given offset in this timezone for the given * timestamp. (eg +0200) * @param int $ts * @return string */ public function getOffset( $ts ) { $act = $this->getActive($ts); return $this->{$act}['tzoffsetto']; } /** * Returns the timezone name for the given timestamp (eg CEST) * @param int $ts * @return string */ public function getTimeZoneName($ts) { $act = $this->getActive($ts); return $this->{$act}['tzname']; } /** * Determines which of the daylight or standard is the active * setting. * The call is cached for a given timestamp, so a call to * getOffset and getTimeZoneName with the same ts won't calculate * the answer twice. * @param int $ts * @return string standard|daylight */ private function getActive( $ts ) { if (class_exists('DateTimeZone')) { //PHP >= 5.2 $tz = new DateTimeZone( $this->tzid ); $date = new DateTime("@$ts", $tz); return ($date->format('I') == 1) ? 'daylight' : 'standard'; } else { if( isset($this->cache[$ts]) ) { return $this->cache[$ts]; } $daylight_freq = new SG_iCal_Freq($this->daylight['rrule'], strtotime($this->daylight['dtstart'])); $standard_freq = new SG_iCal_Freq($this->standard['rrule'], strtotime($this->standard['dtstart'])); $last_standard = $standard_freq->previousOccurrence($ts); $last_dst = $daylight_freq->previousOccurrence($ts); if( $last_dst > $last_standard ) { $this->cache[$ts] = 'daylight'; } else { $this->cache[$ts] = 'standard'; } return $this->cache[$ts]; } } }