title: Problem calculating overlapping date ranges
body: <p>I have a problem trying to work out the correct algorithm to calculate a set of date ranges.</p>
  
  <p>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.</p>
  
  <p>Basically to consolidate two date ranges:</p>
  
  <pre><code>if start1 &lt;= end2 and start2 &lt;= end1 //Indicates overlap
     if start2 &lt; start1 //put the smallest time in start1
        start1 = start2
     endif
     if end2 &gt; end1 //put the highest time in end1
        end1 = end2
     endif
  endif
  </code></pre>
  
  <p>This joins the two date times.</p>
  
  <p>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.</p>
  
  <p>My functional and recursive programming is a bit rusty and any help would be welcome.</p>