u01jmg3 / ics-parser

Parser for iCalendar Events • PHP 8+, 7 (≥ 7.4), 5 (≥ 5.6)
MIT License
450 stars 144 forks source link

[Bug] EXDATE not counted in processRecurrences(), leads to unwanted additional events #262

Closed lucianholt97 closed 4 years ago

lucianholt97 commented 4 years ago

Description of the Issue:

The following recurring event (from google cal) results in 5 events instead of 3. The excluded dates were excluded correctly but additional dates were attached to the end of the set since the algorithm does not count excluded events and terminates when COUNT=5 is reached.

So I get:

instead of just

BEGIN:VEVENT
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
UID:28lgga9giutlmrubl4jqd2rhr5@google.com
CREATED:20200318T132902Z
DESCRIPTION:
LAST-MODIFIED:20200318T132902Z
LOCATION:
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Test
TRANSP:OPAQUE
END:VEVENT

I assume that the following lines of code are responsible for the bug (Lines 1496-1508 in ICal.php)

if (!$isExcluded) {
                        $eventRecurrences[] = $candidate;
                        $this->eventCount++;

                        if (isset($rrules['COUNT'])) {
                            $count++;

                            // If RRULE[COUNT] is reached then break
                            if ($count >= $countLimit) {
                                break 2;
                            }
                        }
                    }

Steps to Reproduce:

  1. Parse the ics event above
u01jmg3 commented 4 years ago

Happy to accept a PR

lucianholt97 commented 4 years ago

@u01jmg3 I am working on it. The official COUNT in an RRULE should include the excluded events, too. Somehow the existing test testStartDateIsExdateUsingCount does not conform with this as the count should be 7. Currently, the (imo wrong) test data has COUNT=3, 4 excluded events and results in 3 events.