Forum Discussion

Re: Eliminating double scheduling

This is actually a very simple problem if you understand "Allen's Interval Algebra":

Allen's Interval Algebra
https://en.wikipedia.org/wiki/Allen%27s_interval_algebra

Years ago I posted a solution to this but it was about 3 forum versions ago and I don't know if my post survived into the current version of the forum.

Let's assume you have no overlaps in your existing table and you have a start and end fields (and that in all cases < ). Now consider adding a new record and lets refer to the values sitting in the form as "new start" ns and "new end" ne (and of course ns < ne). Note that there are only two fields we are referring to here and . The values ns and ne are just the proposed values a user is trying to enter into a new record if there is no overlap with existing records.

You can't successfully submit the form with the new values ns and ne if there is an existing record for which following condition holds:

  < ne AND ns <=

So all the script has to do is monitor changes in the form for ns and ne and perform an AJAX query to see if there is a conflict with an existing record using the above criteria. If there is a conflict your prevent the form from saving. If there is no conflict you save the form. It really is that simple.

The only real thing you have to address is that you probably want to have some discrete time interval for your start and end fields such as 15 minutes, a day, a week etc.


No RepliesBe the first to reply