I have a problem trying to work out the correct algorithm to calculate a set of date ranges.
Basically I have a list of unordered date ranges (List containing arrays of start and end times) and I want to consolidate this list so it does not contains overlapping times.
Basically to consolidate two date ranges:
if start1 <= end2 and start2 <= end1 //Indicates overlap
if start2 < start1 //put the smallest time in start1
start1 = start2
endif
if end2 > end1 //put the highest time in end1
end1 = end2
endif
endif
This joins the two date times.
I hit a stumbling block when it comes to iterating through all the values so the end list only contains values which are not overlapping.
My functional and recursive programming is a bit rusty and any help would be welcome.