Check for overlapped times

Results 1 to 2 of 2

Thread: Check for overlapped times

  1. #1
    Join Date
    Sep 2008

    Default Check for overlapped times

    I am trying to figure out an efficient way to check if two times overlap each other. The scenario is people are selecting classes they want to take but if any of the classes overlap in any way it will detect and not allow them to add class.<BR><BR>Any tips or ideas would be appreciated.

  2. #2
    Join Date
    Dec 1969

    Default Think about it!

    &nbsp;<BR>Just consider all the possibilities of two ranges of times.<BR><BR>I&#039;ll use S and E for one range and s and e for the other:<BR><BR>---s---e----S----E----- &#039; no overlap<BR>---s-----S---e---E----- &#039; overlap<BR>---s----S---E---e------ &#039; overlap<BR>----S--s---e---E----- &#039; overlap<BR>----S---s---E---e----- &#039; overlap<BR>----S----E---s---e---- &#039; no overlap<BR><BR>So... the only time there is NO OVERLAP is when <BR> e &#060; S<BR>or<BR> s &#062; E<BR><BR>Right? So now it&#039;s easy to test for.<BR><BR>[If it&#039;s okay for class 1 to end and 2PM and class 2 to start at 2PM, then just use<BR> e &#060;= S<BR> OR<BR> s &#062;= E<BR>instead.]<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts