title: How to combine overlapping time ranges (time ranges union)
body: <p>I have an array with several time ranges inside:</p>
  
  <pre><code>[Tue, 24 May 2011 08:00:00 CEST +02:00..Tue, 24 May 2011 13:00:00 CEST +02:00,
   Tue, 24 May 2011 16:30:00 CEST +02:00..Tue, 24 May 2011 18:00:00 CEST +02:00,
   Tue, 24 May 2011 08:00:00 CEST +02:00..Tue, 24 May 2011 09:00:00 CEST +02:00,
   Tue, 24 May 2011 15:30:00 CEST +02:00..Tue, 24 May 2011 18:00:00 CEST +02:00]
  </code></pre>
  
  <p>I want to get the same array with the <strong>overlapping</strong> time ranges combined, so the output for this case will be:</p>
  
  <pre><code>[Tue, 24 May 2011 08:00:00 CEST +02:00..Tue, 24 May 2011 13:00:00 CEST +02:00,
   Tue, 24 May 2011 15:30:00 CEST +02:00..Tue, 24 May 2011 18:00:00 CEST +02:00]
  </code></pre>
  
  <p>So it creates a new time range when to time ranges overlap, and so on. If they don´t overlap the will be keep separated. Another example:</p>
  
  <p>Input:</p>
  
  <pre><code>[Tue, 24 May 2011 08:00:00 CEST +02:00..Tue, 24 May 2011 13:00:00 CEST +02:00,
   Tue, 24 May 2011 16:00:00 CEST +02:00..Tue, 24 May 2011 18:00:00 CEST +02:00]
  </code></pre>
  
  <p>Output (will be the same because they don´t overlap):</p>
  
  <pre><code>[Tue, 24 May 2011 08:00:00 CEST +02:00..Tue, 24 May 2011 13:00:00 CEST +02:00,
   Tue, 24 May 2011 16:00:00 CEST +02:00..Tue, 24 May 2011 18:00:00 CEST +02:00]
  </code></pre>
  
  <p>I was thinking in some recursive approach, but I need some guidance here...</p>