I've run into a bit of a tricky issue. It'll probably be easy for most of you but I'm just not seeing it.
There are 3 parking spaces available: A, B, and C. All 3 can be booked at the same time, but no more than those 3 bookings can happen at once or we'll run out of spaces!
My current problem can be viewed in my masterpiece of a drawing here: https://i.stack.imgur.com/x31fG.png (This represents the scheduler object I'm using, with times labelled on the left).
That represents a scheduler control with "bookings" for parking spaces. Here is some pseudocode of what I'm currently doing:
function GetFreeSpace(Reservation Res)
boolean intersects;
for each Reservation R in ListOfReservationsInSpaceA
if (R and Reservation are not the same)
if (Res and R intersect)
intersects = true;
exit for;
end if
end if
next
if (intersects = false)
ListOfReservationsInSpaceA.Add(Res);
Return "A"
end if
intersects = false
// do the same for spots B and C
// if all spots are taken, return "none"
end function
But with my code, if Booking 1 is between 8AM and 5PM and takes spot A, Booking 2 takes spot B between 10AM and 8PM, and booking 3 takes spot C between 6PM and 10PM (once booking 1 is done), a booking 4 that SHOULD work between 8AM and 10PM cannot be made because all spots are taken.
I hope this was relatively clear.
Thanks for any help! The language I'm using is VB.NET but I'd be able to translate from C, C++, C#, Java, etc.