/** * 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 (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]; }
/** * 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]; } }
public function testWeeklyIntervalUntilByday() { $dateset = array(873183600, 873270000, 873442800, 874306800, 874479600, 874652400, 875516400, 875689200, 875862000, 876726000, 876898800); $rule = 'FREQ=WEEKLY;INTERVAL=2;UNTIL=19971224T000000Z;WKST=SU;BYDAY=MO,WE,FR'; $start = strtotime('19970902T090000'); $this->assertRule($rule, $start, $dateset); $freq = new SG_iCal_Freq($rule, $start); $this->assertEquals(882777600, $freq->previousOccurrence(time()), 'Failed getting correct end date'); }