I have the following case: Two tasks, A and B, each with a given time window that specifies the earliest time the task can start, called earliestStart
and the latest time the task can end, called latestEnd
. In addition, the tasks have a given duration
, that is equal or less than latestEnd - earliestStart
for that specific task. E.g task A
has to be performed within 08:00-10:00
and the duration is 1 hour, while task B
has to be performed within 08:50-09:55
, and the duration is 1 hour. How can I check this easily in java, is this correct? (to prove that they are not overlapping):
taskA.earliestStart + taskA.duration < taskB.latestEnd - taskB.duration
|| taskB.earliestStart + taskB.duration < taskA.latestEnd - taskA.duration
Use
LocalTime
to represent a time-of-day without date and without time zone.Compare using
isBefore
,isAfter
, andequals
methods.