ical.js
ical.js copied to clipboard
Wrong First Occurrence for MONTHLY rrule when BYDAY & BYSETPOS are present
recur = ICAL.Recur.fromData({
freq:"MONTHLY",
byday: ['SU'],
bysetpos: [-1]
}); // last sunday in every month
start = ICAL.Time.fromDateString("2017-07-01") //saturday
it = recur.iterator(start)
console.log('Expected 2017-07-30, Actual ' + it.next()); // it.next() is giving 2017-07-02
looks like the recur_iterator's init which sets the first occurrence, has no logic for handling bysetpos
jsFiddle link: https://jsfiddle.net/ysg04wL5/1/
I think this is actually on purpose. When iterating a recurrence rule, the first instance is given by DTSTART. If you pass a date that is not covered by the rule, it is still the first instance. What you'd need to do is pass in a start that is covered by the rule. Does this help?