Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recur_expansion.js: fix iterator with RDATE-only recurrence #534

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions lib/ical/recur_expansion.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ ICAL.RecurExpansion = (function() {
* @type {Number}
* @private
*/
ruleDateInc: 0,
ruleDateInc: -1,

/**
* Current position in exDates array
Expand Down Expand Up @@ -241,6 +241,14 @@ ICAL.RecurExpansion = (function() {
// _after_ we choose a value this should be
// the only spot where we need to worry about the
// end of events.
if (this.ruleDateInc == -1) {
this._nextRuleDay();
if (!iter) {
// on the first iteration return DTSTART
return this.last;
}
}

if (!next && !iter) {
// there are no more iterators or rdates
this.complete = true;
Expand Down Expand Up @@ -278,7 +286,7 @@ ICAL.RecurExpansion = (function() {
}

//XXX: The spec states that after we resolve the final
// list of dates we execute exdate this seems somewhat counter
// list of dates we execute exdate. This seems somewhat counter
// intuitive to what I have seen most servers do so for now
// I exclude based on the original date not the one that may
// have been modified by the exception.
Expand Down Expand Up @@ -384,15 +392,14 @@ ICAL.RecurExpansion = (function() {

this.ruleDateInc = 0;
this.last = this.ruleDates[0].clone();
this.ruleDate = this.ruleDates[0];
} else {
this.ruleDateInc = ICAL.helpers.binsearchInsert(
this.ruleDates,
this.last,
compareTime
);
) - 1;
}

this.ruleDate = this.ruleDates[this.ruleDateInc];
}

if (component.hasProperty('rrule')) {
Expand Down
23 changes: 23 additions & 0 deletions test/recur_expansion_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,29 @@ suite('recur_expansion', function() {
}, ".ruleIterators or .component must be given");
});

test('only rdate without rrule', function() {
var component = primary.component.toJSON();
component = new ICAL.Component(component);
component.removeAllProperties('rrule');

var subject = new ICAL.RecurExpansion({
component,
dtstart: primary.startDate
});
var expected = [
new Date(2012, 09, 02, 10),
new Date(2012, 10, 05, 10),
new Date(2012, 10, 10, 10),
new Date(2012, 10, 30, 10)
], dates = [], next;

while (next = subject.next() ) {
dates.push(next.toJSDate());
}

assert.deepEqual(dates, expected);
});

test('default', function() {
var dtstart = ICAL.Time.fromData({
year: 2012,
Expand Down