Bug 330496: fixed getOccurrencesBetween() to respect half-open intervals. r=jminta

This commit is contained in:
michael.buettner%sun.com 2006-08-17 12:03:25 +00:00
parent 36a6624e1b
commit d73f8a6e7c
2 changed files with 63 additions and 10 deletions

View File

@ -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;

View File

@ -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;