讲座碰撞布尔表达式算法

时间:2014-01-25 19:02:31

标签: boolean-logic boolean-expression boolean-operations

我正在尝试为计划应用程序编写一个讲座碰撞算法。每个讲座都有一个开始和结束日期。

currentListElement是我当前日程中的现有讲座,我想添加selectedLecture,并检查我当前讲座之间是否存在冲突。因此,如果发生冲突,此布尔表达式应返回true。

感谢您的帮助

(currentListElement['startDate'] < chosenLecture['startDate'] 
  || currentListElement['startDate'] >= chosenLecture['endDate']) 
 && (currentListElement['endDate'] <= chosenLecture['startDate'] 
  || currentListElement['endDate'] > chosenLecture['endDate'])

1 个答案:

答案 0 :(得分:2)

实际上有一点错误,试试这个:

(currentListElement['endDate'] < chosenLecture['startDate'] 
 || currentListElement['startDate'] > chosenLecture['endDate'])

在两种情况下没有碰撞:

  1. 讲座完全在当前讲座之前完成。要检查一下,只需确保它在当前开始之前结束。
  2. 讲座完全是在当前的讲座之后。要检查一下,只需确保它在当前结束后开始。