If you're dealing with a full
DateTime
, it's easy: look for shifts which start before the new shift ends, and end after the new shift starts.
A.StartDateTime <= B.EndDateTime && A.EndDateTime >= B.StartDateTime
If you're only looking at the time of day, then it depends on whether or not you have overnight shifts.
If you don't, and the shift start time is always guaranteed to be before the shift end time, then you can use the same pattern:
A.StartTimeOfDay <= B.EndTimeOfDay && A.EndTimeOfDay >= B.StartTimeOfDay
Once you add in overnight shifts
(eg: 10PM – 6AM) then things start to get tricky:
Putting that all together will give you something like:
(
A.StartTimeOfDay > A.EndTimeOfDay
&&
B.StartTimeOfDay > B.EndTimeOfDay
)
||
(
A.StartTimeOfDay <= B.EndTimeOfDay
&&
A.EndTimeOfDay >= B.StartTimeOfDay
)
||
(
(
A.StartTimeOfDay > A.EndTimeOfDay
||
B.StartTimeOfDay > B.EndTimeOfDay
)
&&
(
A.StartTimeOfDay <= B.EndTimeOfDay
||
A.EndTimeOfDay >= B.StartTimeOfDay
)
)