I am trying to write a lecture collision algorithm for a schedule application. Each lecture has a start and end date.
currentListElement is the existing lecture in my current schedule, and I want to add chosenLecture, and check if there is a collision between my current lectures. Therefore, this boolean expression should return true if collision occurs.
Thank you for your help
(currentListElement['startDate'] < chosenLecture['startDate']
|| currentListElement['startDate'] >= chosenLecture['endDate'])
&& (currentListElement['endDate'] <= chosenLecture['startDate']
|| currentListElement['endDate'] > chosenLecture['endDate'])
Actually there is a little mistake, try this:
(currentListElement['endDate'] < chosenLecture['startDate']
|| currentListElement['startDate'] > chosenLecture['endDate'])
There is no collision in two cases: