Skip to content

Commit

Permalink
Merge pull request #263 from lucianholt97/master
Browse files Browse the repository at this point in the history
Fix bug with COUNT in conjunction with EXDATE. COUNT should include e…
  • Loading branch information
u01jmg3 authored Mar 23, 2020
2 parents 116588e + b2eb360 commit 002a3b0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
16 changes: 9 additions & 7 deletions src/ICal/ICal.php
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,7 @@ protected function processRecurrences()
* Where:
* enddate = <icalDate> || <icalDateTime>
*/
$count = (int) !$initialDateIsExdate;
$count = 1;
$countLimit = (isset($rrules['COUNT'])) ? intval($rrules['COUNT']) : 0;
$until = date_create()->modify("{$this->defaultSpan} years")->setTime(23, 59, 59)->getTimestamp();

Expand Down Expand Up @@ -1500,14 +1500,15 @@ function ($weekday) use ($initialDayOfWeek, $wkstTransition, $interval) {
if (!$isExcluded) {
$eventRecurrences[] = $candidate;
$this->eventCount++;
}

if (isset($rrules['COUNT'])) {
$count++;
// count all evaluated candidates, also excluded ones
if (isset($rrules['COUNT'])) {
$count++;

// If RRULE[COUNT] is reached then break
if ($count >= $countLimit) {
break 2;
}
// If RRULE[COUNT] is reached then break
if ($count >= $countLimit) {
break 2;
}
}
}
Expand Down Expand Up @@ -1700,6 +1701,7 @@ protected function filterValuesUsingBySetPosRRule($bySetPos, $valuesList)
* time zone depending on the event `TZID`.
*
* @return void
* @throws \Exception
*/
protected function processDateConversions()
{
Expand Down
24 changes: 23 additions & 1 deletion tests/RecurrencesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public function testStartDateIsExdateUsingCount()
'Europe/London',
array(
'DTSTART;TZID=Europe/London:20190911T095000',
'RRULE:FREQ=WEEKLY;WKST=SU;COUNT=3;BYDAY=WE',
'RRULE:FREQ=WEEKLY;WKST=SU;COUNT=7;BYDAY=WE',
'EXDATE;TZID=Europe/London:20191023T095000',
'EXDATE;TZID=Europe/London:20191009T095000',
'EXDATE;TZID=Europe/London:20190925T095000',
Expand All @@ -255,6 +255,28 @@ public function testStartDateIsExdateUsingCount()
);
}

public function testCountWithExdate()
{
$checks = array(
array('index' => 0, 'dateString' => '20200323T050000', 'timezone' => 'Europe/Paris', 'message' => '1st event: '),
array('index' => 1, 'dateString' => '20200324T050000', 'timezone' => 'Europe/Paris', 'message' => '2nd event: '),
array('index' => 2, 'dateString' => '20200327T050000', 'timezone' => 'Europe/Paris', 'message' => '3rd event: ')
);
$this->assertVEVENT(
'Europe/London',
array(
'DTSTART;TZID=Europe/Paris:20200323T050000',
'DTEND;TZID=Europe/Paris:20200323T070000',
'RRULE:FREQ=DAILY;COUNT=5',
'EXDATE;TZID=Europe/Paris:20200326T050000',
'EXDATE;TZID=Europe/Paris:20200325T050000',
'DTSTAMP:20200318T141057Z'
),
3,
$checks
);
}

public function testRFCDaily10BerlinFromNewYork()
{
$checks = array(
Expand Down

0 comments on commit 002a3b0

Please sign in to comment.