From d73f8a6e7c08b1ae7998242b67063eae445abd65 Mon Sep 17 00:00:00 2001 From: "michael.buettner%sun.com" Date: Thu, 17 Aug 2006 12:03:25 +0000 Subject: [PATCH] Bug 330496: fixed getOccurrencesBetween() to respect half-open intervals. r=jminta --- calendar/base/src/calEvent.js | 34 +++++++++++++++++++++++++----- calendar/base/src/calTodo.js | 39 ++++++++++++++++++++++++++++++----- 2 files changed, 63 insertions(+), 10 deletions(-) diff --git a/calendar/base/src/calEvent.js b/calendar/base/src/calEvent.js index be0b81f4c686..34d2d1f53626 100644 --- a/calendar/base/src/calEvent.js +++ b/calendar/base/src/calEvent.js @@ -242,11 +242,35 @@ calEvent.prototype = { return this.recurrenceInfo.getOccurrences(aStartDate, aEndDate, 0, aCount); } - if ((this.startDate.compare(aStartDate) >= 0 && this.startDate.compare(aEndDate) <= 0) || - (this.endDate.compare(aStartDate) >= 0 && this.endDate.compare(aEndDate) <= 0)) - { - aCount.value = 1; - return ([ this ]); + // We need to convert dates to regular datetime-objects + // here in order to correctly handle allday-events that + // don't match day borders. + function convertDate(date) { + if (date.isDate) { + var newDate = date.clone(); + newDate.hour = 0; + newDate.minute = 0; + newDate.second = 0; + newDate.isDate = false; + return newDate; + } else { + return date; + } + } + + var start = convertDate(this.startDate); + var end = convertDate(this.endDate); + + var isZeroLength = !start.compare(end); + if ((isZeroLength && + start.compare(aStartDate) >= 0 && + start.compare(aEndDate) < 0) || + (!isZeroLength && + start.compare(aEndDate) < 0 && + end.compare(aStartDate) > 0)) { + + aCount.value = 1; + return ([ this ]); } aCount.value = 0; diff --git a/calendar/base/src/calTodo.js b/calendar/base/src/calTodo.js index 5688703d8ffa..bc9856f1a921 100644 --- a/calendar/base/src/calTodo.js +++ b/calendar/base/src/calTodo.js @@ -247,11 +247,40 @@ calTodo.prototype = { if (!this.entryDate && !this.dueDate) return null; - if ((this.entryDate && this.entryDate.compare(aStartDate) >= 0 && this.entryDate.compare(aEndDate) <= 0) || - (this.dueDate && this.dueDate.compare(aStartDate) >= 0 && this.dueDate.compare(aEndDate) <= 0)) - { - aCount.value = 1; - return ([ this ]); + // We need to convert dates to regular datetime-objects + // here in order to correctly handle allday-todos that + // don't match day borders. + function convertDate(date) { + if (!date) + return null; + if (date.isDate) { + var newDate = date.clone(); + newDate.hour = 0; + newDate.minute = 0; + newDate.second = 0; + newDate.isDate = false; + return newDate; + } else { + return date; + } + } + + var entry = convertDate(this.entryDate); + var due = convertDate(this.dueDate); + + var isInterval = entry && due; + var isZeroLength = isInterval ? !entry.compare(due) : true; + var dateTime = entry ? entry : due; + + if ((isZeroLength && + dateTime.compare(aStartDate) >= 0 && + dateTime.compare(aEndDate) < 0) || + (!isZeroLength && + entry.compare(aEndDate) < 0 && + due.compare(aStartDate) > 0)) { + + aCount.value = 1; + return ([ this ]); } aCount.value = 0;