From 30d1dfa4a978dfa96c6421dfa4451964b6f3d70a Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sun, 31 Oct 2010 16:23:56 +0100 Subject: [PATCH] fix excluded first dates --- helpers/SG_iCal_Freq.php | 5 ++++- helpers/SG_iCal_Recurrence.php | 3 ++- tests/helpers/FreqTest.php | 31 +++++++++++++++++++++++++++---- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/helpers/SG_iCal_Freq.php b/helpers/SG_iCal_Freq.php index 5be7eef..67e59de 100755 --- a/helpers/SG_iCal_Freq.php +++ b/helpers/SG_iCal_Freq.php @@ -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; } /** diff --git a/helpers/SG_iCal_Recurrence.php b/helpers/SG_iCal_Recurrence.php index a80d1db..29e6ab8 100755 --- a/helpers/SG_iCal_Recurrence.php +++ b/helpers/SG_iCal_Recurrence.php @@ -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 diff --git a/tests/helpers/FreqTest.php b/tests/helpers/FreqTest.php index 7d82505..26ad5f4 100755 --- a/tests/helpers/FreqTest.php +++ b/tests/helpers/FreqTest.php @@ -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);