title: Group DateTime by an arbitrary time interval
body: <p>I have an IEnumerable of an item class defined like this:</p>
  
  <pre><code>public class Item {
      public DateTime Date { get; private set; }
      public decimal? Value { get; private set; }
  
      public Item(DateTime date, decimal? value) {
       Date = date;
       Value = value;
      }
  }
  </code></pre>
  
  <p>These items are in a specific time interval (5 minutes for exemple). I need to group them by the date, but changing the interval. For example, if the items are in the following order: </p>
  
  <pre><code>2010-08-24 00:05
  2010-08-24 00:10
  2010-08-24 00:15
  2010-08-24 00:20
  2010-08-24 00:25
  2010-08-24 00:30
  </code></pre>
  
  <p>and I want to group them into a 15 minutes interval, the result should look like this:</p>
  
  <pre><code>2010-08-24 00:15
  2010-08-24 00:30
  </code></pre>
  
  <p>The interval is provided by another class, but I can get the milliseconds that represent that interval (for example, Interval.FromMinutes(5).GetMilliseconds() should return 300000). The question is how can I write a grouping function that allows me to do something like this : <code>data = items.GroupBy(t =&gt; GroupingFunction(t.DateTime, interval))</code> and obtain that result?</p>
  
  <p><strong>Update:</strong> the interval will not be necessarily in minutes. It could be in hours, minutes or even days. </p>