Skip to content

Commit

Permalink
recur_expansion: EXDATE can be DATE and DTSTART can be DATE-TIME
Browse files Browse the repository at this point in the history
When EXDATE is in DATE format and DTSTART is DATE-TIME, then
to determine whether an occurrence shall be excluded, the
occurrence shall be converted to DATE and then compared to EXDATE.

This applies also for the very first EXDATE, when it coincides with
DTSTART.
  • Loading branch information
dilyanpalauzov committed Apr 21, 2024
1 parent 2f880d3 commit be9214c
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions lib/ical/recur_expansion.js
Expand Up @@ -198,6 +198,21 @@ class RecurExpansion {
}
}

/**
* Compare two ICAL.Time objects. When the second parameter is a timeless date
* and the first parameter is date-with-time, strip the time and compare only
* the days.
*
* @private
* @param {ICAL.Time} a The one object to compare
* @param {ICAL.Time} b The other object to compare
*/
_compare_special(a, b) {
if (!a.isDate && b.isDate)
return new Time({ year: a.year, month: a.month, day: a.day }).compare(b);
else return a.compare(b);
}

/**
* Retrieve the next occurrence in the series.
* @return {ICAL.Time}
Expand Down Expand Up @@ -248,9 +263,10 @@ class RecurExpansion {

// check the negative rules
if (this.exDate) {
compare = this.exDate.compare(this.last);
//EXDATE can be in DATE format, but DTSTART is in DATE-TIME format
compare = this._compare_special(this.last, this.exDate);

if (compare < 0) {
if (compare > 0) {
this._nextExDay();
}

Expand Down Expand Up @@ -397,10 +413,12 @@ class RecurExpansion {
if (component.hasProperty('exdate')) {
this.exDates = this._extractDates(component, 'exdate');
// if we have a .last day we increment the index to beyond it.
// When DTSTART is in DATE-TIME format, EXDATE is in DATE format and EXDATE is
// the date of DTSTART, _compare_special finds this out and compareTime fails.
this.exDateInc = binsearchInsert(
this.exDates,
this.last,
(a, b) => a.compare(b)
this._compare_special
);

this.exDate = this.exDates[this.exDateInc];
Expand Down

0 comments on commit be9214c

Please sign in to comment.