Page 1 of 1

How To Find Time Conflicts

Posted: Wed Nov 03, 2004 3:09 pm
by pmcnally
I am working on a class scheduler, and I am having trouble figuring out how to solve the problems of deciding if a class is conflicting with one another.

Say I have 2 classes
Class 1 runs from 14:00 to 15:15
Class 2 runs from 15:00 to 15:50

Those class times are definately overlapping. Can anybody help me figure out how to tell if they are over lapping?

Here's another set of test data that is eluding me:
Class 1 runs from 18:00 to 21:00
Class 2 runs from 19:00 to 19:50

If anybody could help me out, that would be really great and much appreciated =)

-Pat

Posted: Wed Nov 03, 2004 4:13 pm
by swdev
A simpe test would be

Code: Select all

if (Class1EndTime > Class2StartTime)
{
  you have a clash
}
Hope this helps

Posted: Thu Nov 04, 2004 11:34 am
by pmcnally
That's too simple because all the classes that started or ended after the first class would show up.

Posted: Thu Nov 04, 2004 11:57 am
by hedge
overlap if:

class2.start <= class1.end and class2.end >= class1.start

Re: How To Find Time Conflicts

Posted: Thu Nov 04, 2004 5:45 pm
by Weirdan
pmcnally wrote:I am working on a class scheduler, and I am having trouble figuring out how to solve the problems of deciding if a class is conflicting with one another.
The solution depends on two things:
  • How do you store the data (database, php arrays, something else)?
  • Do you need to check for overlapping for just one class (i.e. when class is added you run the check if it would fit in schedule) or you would got entire schedule somehow and then check if it has any overlapping classes?