fix excluded first dates

master
Tanguy Pruvot 2010-10-31 16:23:56 +01:00
rodzic ff9c8e202c
commit 30d1dfa4a9
3 zmienionych plików z 33 dodań i 6 usunięć

Wyświetl plik

@ -144,7 +144,10 @@ class SG_iCal_Freq {
* @return int timestamp
*/
public function firstOccurrence() {
return $this->start;
$t = $this->start;
if (in_array($t, $this->excluded))
$t = $this->findNext($t);
return $t;
}
/**

Wyświetl plik

@ -57,10 +57,11 @@ class SG_iCal_Recurrence {
* @param string $line the line to be parsed
*/
protected function parseLine($line) {
$this->rrule = $line;
//split up the properties
$recurProperties = explode(';', $line);
$recur = array();
$this->rrule = $line;
//loop through the properties in the line and set their associated
//member variables

Wyświetl plik

@ -605,7 +605,15 @@ class FreqTest extends PHPUnit_Framework_TestCase {
}
}
//weird : in this test $start is not a matched occurrence but...
/*
weird : in this test $start is not a matched occurrence but...
to do something like that, we need EXDATE :
DTSTART;TZID=US-Eastern:19970902T090000
EXDATE;TZID=US-Eastern:19970902T090000
RRULE:FREQ=MONTHLY;BYDAY=FR;BYMONTHDAY=13
*/
public function testFirstOccurrencesByYearDay() {
$rule = 'FREQ=YEARLY;INTERVAL=2;BYYEARDAY=1;COUNT=5';
$start = strtotime('2009-10-27T090000');
@ -614,6 +622,13 @@ class FreqTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(strtotime('2011-01-01T09:00:00'), $freq->nextOccurrence($start));
}
public function testFirstOccurrencesByYearDayWithoutFirstDate() {
$rule = 'FREQ=YEARLY;INTERVAL=2;BYYEARDAY=1;COUNT=5';
$start = strtotime('2009-10-27T090000');
$freq = new SG_iCal_Freq($rule, $start, array($start));
$this->assertEquals(strtotime('2011-01-01T09:00:00'), $freq->firstOccurrence());
}
public function testLastOccurrenceByYearDay() {
$rule = 'FREQ=YEARLY;INTERVAL=2;BYYEARDAY=1;COUNT=5';
$start = strtotime('2011-01-01T090000');
@ -626,13 +641,21 @@ class FreqTest extends PHPUnit_Framework_TestCase {
$start = strtotime('2011-01-01T090000');
$freq = new SG_iCal_Freq($rule, $start);
$this->assertEquals(5, count($freq->getAllOccurrences()));
$this->assertEquals(5, count($freq->getAllOccurrences()));
$this->assertEquals(strtotime('2019-01-01T09:00:00'), $freq->lastOccurrence());
}
// TODO: WKST rule
/* TODO: BYSETPOS rule :
The 3rd instance into the month of one of Tuesday, Wednesday or
Thursday, for the next 3 months:
DTSTART;TZID=US-Eastern:19970904T090000
RRULE:FREQ=MONTHLY;COUNT=3;BYDAY=TU,WE,TH;BYSETPOS=3
*/
/* TODO: WKST rule
*/
//check a serie of dates
private function assertRule( $rule, $start, $dateset ) {
$freq = new SG_iCal_Freq($rule, $start);
reset($dateset);