title: get next/previous month from a Time object
body: <p>I have a Time object and would like to find the next/previous month. Adding subtracting days does not work as the days per month vary.</p>
  
  <pre><code>time = Time.parse('21-12-2008 10:51 UTC')
  next_month = time + 31 * 24 * 60 * 60
  </code></pre>
  
  <p>Incrementing the month also falls down as one would have to take care of the rolling</p>
  
  <pre><code>time = Time.parse('21-12-2008 10:51 UTC')
  next_month = Time.utc(time.year, time.month+1)
  
  time = Time.parse('01-12-2008 10:51 UTC')
  previous_month = Time.utc(time.year, time.month-1)
  </code></pre>
  
  <p>The only thing I found working was</p>
  
  <pre><code>time = Time.parse('21-12-2008 10:51 UTC')
  d = Date.new(time.year, time.month, time.day)
  d &gt;&gt;= 1
  next_month = Time.utc(d.year, d.month, d.day, time.hour, time.min, time.sec, time.usec)
  </code></pre>
  
  <p>Is there a more elegant way of doing this that I am not seeing?
  How would you do it?</p>