expanding repeating event with recurrence exception
Hey :)
I need help (and would also like to suggest a helper function) to expand a repeating event with recurrence exceptions. I'm testing this with version 1.2.2 (via bower).
Issue
The code below has a bug. Instead of 4 events, like expected, it creates 5 events.
Expected:
- Jan 3rd
- Jan 10th
- Jan 18th
- Jan 24th
Actual:
- Jan 3rd
- Jan 10th
- Jan 17th
- Jan 18th
- Jan 24th
I'd appreciate input how to get the expected result and I'd also be happy to help developing a helper function.
I have a similar issues for events with recurrence exceptions specifying RANGE:THISANDFUTURE
Code and example data
My current approach is the following:
const vevents = context.comp.getAllSubcomponents('vevent');
vevents.forEach(function (vevent) {
const iCalEvent = new ICAL.Event(vevent);
if (!vevent.hasProperty('dtstart')) {
return;
}
// ...
if (iCalEvent.isRecurring()) {
// ...
let next;
while ((next = iterator.next())) {
// ...
// push event into some array
}
} else {
// ...
// push event into some array
}
});
Some example ics data:
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Apple Inc.//Mac OS X 10.12.2//EN
CALSCALE:GREGORIAN
BEGIN:VTIMEZONE
TZID:Europe/Berlin
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
DTSTART:19810329T020000
TZNAME:GMT+2
TZOFFSETTO:+0200
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
DTSTART:19961027T030000
TZNAME:GMT+1
TZOFFSETTO:+0100
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
CREATED:20170119T180642Z
UID:99C096E7-0A03-48C2-B606-0BC558147842
RRULE:FREQ=WEEKLY;INTERVAL=1;COUNT=4
DTEND;TZID=Europe/Berlin:20170103T100000
TRANSP:OPAQUE
SUMMARY:test event
DTSTART;TZID=Europe/Berlin:20170103T090000
DTSTAMP:20170119T180700Z
X-APPLE-TRAVEL-ADVISORY-BEHAVIOR:AUTOMATIC
SEQUENCE:0
END:VEVENT
BEGIN:VEVENT
CREATED:20170119T180642Z
UID:99C096E7-0A03-48C2-B606-0BC558147842
DTEND;TZID=Europe/Berlin:20170118T100000
TRANSP:OPAQUE
X-APPLE-TRAVEL-ADVISORY-BEHAVIOR:AUTOMATIC
SUMMARY:test event
DTSTART;TZID=Europe/Berlin:20170118T090000
DTSTAMP:20170119T180706Z
SEQUENCE:0
RECURRENCE-ID;TZID=Europe/Berlin:20170117T090000
END:VEVENT
END:VCALENDAR
@kewisch I remember you saying that thunderbird has its own routine for this. Any chance you can point me to that code in thunderbird? :)
I made a wrapper for ical.js that solves this problem: https://github.com/mifi/ical-expander
I'm currently swamped with work and really want to integrate a new recurrence iterator that will drastically improve performance, but generally this sounds like something that we could integrate with ical.js. Thanks for working on this and pointing it out!
@georgehrke check out https://dxr.mozilla.org/comm-central/source/calendar/base/backend/icaljs/calRecurrenceRule.js#41