From 0fe55fd2e816585c20f7cae601e3cba3dc04b614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B8=D0=BB=D1=8F=D0=BD=20=D0=9F=D0=B0=D0=BB=D0=B0?= =?UTF-8?q?=D1=83=D0=B7=D0=BE=D0=B2?= Date: Sun, 19 Apr 2020 20:36:21 +0000 Subject: [PATCH] recur_expansion: EXDATE can be DATE and DTSTART can be DATE-TIME When EXDATE is in DATE format and DTSTART is DATE-TIME, then to determine whether a ocurrence shall be excluded, the occurence shall be converted to DATE and then compared to EXDATE. This applies also for the very first EXDATE, when it coincides with DTSTART. --- lib/ical/recur_expansion.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/ical/recur_expansion.js b/lib/ical/recur_expansion.js index 903906df..4f282e12 100644 --- a/lib/ical/recur_expansion.js +++ b/lib/ical/recur_expansion.js @@ -213,6 +213,21 @@ ICAL.RecurExpansion = (function() { } }, + /** + * 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: function(a, b) { + if (!a.isDate && b.isDate) + return new ICAL.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} @@ -264,9 +279,10 @@ ICAL.RecurExpansion = (function() { // 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(); } @@ -418,10 +434,12 @@ ICAL.RecurExpansion = (function() { 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 = ICAL.helpers.binsearchInsert( this.exDates, this.last, - compareTime + this._compare_special ); this.exDate = this.exDates[this.exDateInc];