I have 2 lists that contain UTC dates. To determine if the lists contain overlapping dates I am doing the following:
list1.Where(
x =>
list2.Any(
y =>
x.StartDate < y.EndDate &&
y.StartDate < x.EndDate));
Is there a way to actually return the overlapping periods? These lists are unique within themselves in that list1 will not contain overlapping dates, and list2 will not contain overlapping dates within iteself.
For example, if I have the 2 lists containing the following start and end date times
list 1:
1/1 5AM - 1/1 10PM
1/2 4AM - 1/2 8AM
list 2:
1/1 10AM - 1/1 11AM
1/1 4PM - 1/1 5PM
1/2 5AM - 10PM
I would want to return:
1/1 10AM - 1/1 11AM
1/1 4PM - 1/1 5Pm
1/2 5AM - 1/2 8AM
The dates will never be NULL.
I'm thinking taking the MAX of the 2 starts and the MIN of the 2 ends would work, but not sure how that would look syntactically