title: Get contiguous date ranges
body: <p>Given a list of date ranges, I'd like to get a list of contiguous date ranges.</p>
  
  <p><a href="https://i.stack.imgur.com/WGTbR.png" rel="noreferrer"><img src="https://i.stack.imgur.com/WGTbR.png" alt="enter image description here"></a></p>
  
  <p>I'm not too sure of the terminology of what I'm looking for, but I've put together a skeleton:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Diagnostics;
  using System.Linq;
  using System.Text;
  
  namespace ContiguousTimeSpans
  {
      class Program
      {
          static void Main(string[] args)
          {
              List&lt;DateRange&gt; ranges = new List&lt;DateRange&gt;();
              ranges.Add(new DateRange(DateTime.Parse("01/12/2015 07:00:00"), DateTime.Parse("01/12/2015 10:00:00")));
              ranges.Add(new DateRange(DateTime.Parse("01/12/2015 06:00:00"), DateTime.Parse("01/12/2015 09:00:00")));
              ranges.Add(new DateRange(DateTime.Parse("01/12/2015 05:00:00"), DateTime.Parse("01/12/2015 08:00:00")));
              ranges.Add(new DateRange(DateTime.Parse("01/12/2015 18:00:00"), DateTime.Parse("01/12/2015 21:00:00")));
              ranges.Add(new DateRange(DateTime.Parse("01/12/2015 12:00:00"), DateTime.Parse("01/12/2015 14:00:00")));
              ranges.Add(new DateRange(DateTime.Parse("01/12/2015 20:00:00"), DateTime.Parse("01/12/2015 22:00:00")));
              ranges.Add(new DateRange(DateTime.Parse("01/12/2015 11:00:00"), DateTime.Parse("01/12/2015 23:00:00")));
  
              List&lt;DateRange&gt; contiguousBlocks = GetContiguousTimespans(ranges);
              Debug.Assert(contiguousBlocks.Count == 2);
  
              Debug.Assert(contiguousBlocks[0].Start.Hour == 5);
              Debug.Assert(contiguousBlocks[0].End.Hour == 10);
  
              Debug.Assert(contiguousBlocks[1].Start.Hour == 11);
              Debug.Assert(contiguousBlocks[1].End.Hour == 23);
  
              Console.ReadKey();
          }
  
          public static List&lt;DateRange&gt; GetContiguousTimespans(List&lt;DateRange&gt; ranges)
          {
              List&lt;DateRange&gt; result = new List&lt;DateRange&gt;();
              //???
              return result;
          }
      }
  
      public class DateRange
      {
          public DateTime Start { get; set; }
          public DateTime End { get; set; }
  
          public DateRange(DateTime start, DateTime end)
          {
              Start = start;
              End = end;
          }
      }
  }
  </code></pre>
  
  <p>Is there a way to deduce the contiguous ranges?</p>