/**
* Checks if a date range is allocated or not for a given resource.
* @param {Date} start The start date
* @param {Date} end The end date
* @param {Mixed} eventId The event id (or null)
* @param {Mixed} resourceId The id of the resource
* @return {Boolean} True if the timespan is available for the resource
*/
isDateRangeAvailable : function(start, end, eventId, resourceId) {
var available = true;
this.eventStore.each(function(r) {
if (Date.intersectSpans(start, end, r.get('StartDate'), r.get('EndDate')) && (resourceId === r.get('ResourceId') && (!eventId || eventId !== r.id))){
available = false;
return false;
}
});
return available;
},
Case I.
Event A. Start date is 15 Dec 2010 & End date is 18 Dec 2010
Event B. Start date is 19 Dec 2010 & End date is 21 Dec 2010
isDateRangeAvailable returns true. Which is correct as the dates are not overlapping.
Case II.
Event A. Start date is 15 Dec 2010 & End date is 18 Dec 2010
Event B. Start date is 18 Dec 2010 & End date is 21 Dec 2010
isDateRangeAvailable returns false. Which is incorrect as the dates are overlapping(end date of event A and Start date of Event B).
As per our requirement date should be inclusive i.e, schedule start date is 15 dec 2010 - 20 Dec 2010 then 15 and 20 dec 2010 are occupied for added schedule.