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
n.m.'s answer is all you will need but if you want to use the code you've already made then simply sort the ranges by the start time and walk through the list merging overlaps.