Show cool things you have done with our products


Post by praveen.shastri »

As per the below method it returns true if there is overlap of dates and false if there is no overlap.
/**
         * 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;
        },
Let me explain the other cases too.

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.
Attachments
Screen shot of date overlapp
Screen shot of date overlapp
schedulerDateRange.gif (63.65 KiB) Viewed 6519 times

Post by mats »

"As per the below method it returns true if there is overlap of dates and false if there is no overlap."

This is the misunderstanding, the method returns true if the timeslot _is available_ (e.g. no overlap).

Post by mats »

Ok I think I understand you now. Dates in the scheduler are exact, so if you want inclusive dates you'll need to specify exact time.

If you want the date range December 15-20 then you really mean:

start : 2010-12-15 00:00
end : 2010-12-21 00:00

as the end date in the scheduler is not inclusive. You could use the 'convert' feature of your DataReader to solve this if you don't want to change your backend date structure....

Post by praveen.shastri »

We do not want to change the database structure . Please post some example for given solution.

Post by mats »

This goes in your reader config:
    fields : [
 
        {name : "EndDate", type : "date", convert : function(v, r) {
   return Date.parseDate(v, "Y-m-d").add(Date.DAY, 1);
}},
...
]
Untested, might need some tweaking to suit your case.

Post by praveen.shastri »

As I see you are adding one day to the end date in DataReader itself.
Following are the problem:
1. There is event added for date 20 - 25 dec 2010. If you click to update it shows as 20 - 26 dec 2010, which is not accurate.
2. If the event updated then backend end date is stored as 26 Dec 2010.
3. On view the end date of event is 26 Dec 2010

Is it possible to change the code of 'isDateRangeAvailable' or 'Date.intersectSpans' so that check is done by including the end date? I appreciate help on this without changing the rest of the code.
Thanks in advance.

Post by praveen.shastri »

Hi Mats,

Things are working fine. We could solve the problem by adding the time to event dates as suggested by you. Example if the event is from 15 dec - 23 dec 2010 we take it as 15 dec 2010 00:00:00 - 23 dec 2010 23:59:59 , in this way the end date is inclusive. 'isDateRangeAvailable' checks end to end dates perfect i.e, includes the endate for check.

Thanks a lot.

Praveen

Post by mats »

Glad to hear :). Happy holidays!

Post Reply