Split a period of time into multiple time periods
<p>If i have a time period, lets say <code>DateFrom</code> and <code>DateTo</code> and I have a list of Dates, These dates will be the split dates. For example:</p>

<pre><code>DateTime dateFrom = new DateTime(2012, 1, 1);
DateTime dateTo = new DateTime(2012, 12, 31);

List&lt;DateTime&gt; splitDates = new List&lt;DateTime&gt;
    {
        new DateTime(2012,2,1),
        new DateTime(2012,5,1),
        new DateTime(2012,7,1),
        new DateTime(2012,11,1),
    };

List&lt;Tuple&lt;DateTime, DateTime&gt;&gt; periods = SplitDatePeriod(dateFrom, dateTo, splitDates);
</code></pre>

<p>I want the result to be a list of periods, so for the previous example the result should be:</p>

<pre><code>(01/01/2012 - 01/02/2012)
(02/02/2012 - 01/05/2012)
(02/05/2012 - 01/07/2012)
(02/07/2012 - 01/11/2012)
(02/11/2012 - 31/12/2012)
</code></pre>

<p>I have already wrote a method to do that:</p>

<pre><code>List&lt;Tuple&lt;DateTime, DateTime&gt;&gt; SplitDatePeriod(DateTime dateFrom, DateTime dateTo, List&lt;DateTime&gt; splitDates)
{
    var resultDates = new List&lt;Tuple&lt;DateTime, DateTime&gt;&gt;();

    // sort split dates
    List&lt;DateTime&gt; _splitDates = splitDates.OrderBy(d =&gt; d.Date).ToList();

    DateTime _curDate = dateFrom.Date;
    for (int i = 0; i &lt;= _splitDates.Count; ++i)
    {
        DateTime d = (i &lt; _splitDates.Count) ? _splitDates[i] : dateTo;

        // skip dates out of range
        if (d.Date &lt; dateFrom.Date || d.Date &gt; dateTo.Date)
            continue;

        resultDates.Add(Tuple.Create(_curDate, d));

        _curDate = d.AddDays(1);
    }
    return resultDates;
}
</code></pre>

<p><strong>The Question</strong><br />
It looks so ugly, Is there more neat and shorter way of doing this? using Linq maybe?</p>
