title: Ruby: Create range of dates
body: <p>I'm looking for an elegant way to make a range of datetimes, e.g.:</p>
  
  <pre><code>def DateRange(start_time, end_time, period)
    ...
  end
  
  &gt;&gt; results = DateRange(DateTime.new(2013,10,10,12), DateTime.new(2013,10,10,14), :hourly)
  &gt;&gt; puts results
  2013-10-10:12:00:00
  2013-10-10:13:00:00
  2013-10-10:14:00:00
  </code></pre>
  
  <p>The step should be configurable, e.g. hourly, daily, monthly.</p>
  
  <p>I'd like <code>times</code> to be inclusive, i.e. include <code>end_time</code>.</p>
  
  <p>Additional requirements are:</p>
  
  <ul>
  <li>Original timezone should be preserved, i.e. if it's different from the local timezone, it should still be maintained.</li>
  <li>Should use proper advance methods, e.g. Rails <code>:advance</code>, to handle things like variable number of days in months.</li>
  <li>Ideally performance will be good, but that's not a primary requirement.</li>
  </ul>
  
  <p>Is there an elegant solution?</p>