title: How to generate a human readable time range using ruby on rails
body: <p>I'm trying to find the best way to generate the following output</p>
  
  <pre><code>&lt;name&gt; job took 30 seconds
  &lt;name&gt; job took 1 minute and 20 seconds
  &lt;name&gt; job took 30 minutes and 1 second
  &lt;name&gt; job took 3 hours and 2 minutes
  </code></pre>
  
  <p>I started this code</p>
  
  <pre><code>def time_range_details
    time = (self.created_at..self.updated_at).count
    sync_time = case time 
      when 0..60 then "#{time} secs"       
      else "#{time/60} minunte(s) and #{time-min*60} seconds"
    end
  end
  </code></pre>
  
  <p>Is there a more efficient way of doing this.  It seems like a lot of redundant code for something super simple. </p>
  
  <p>Another use for this is:</p>
  
  <pre><code>&lt;title&gt; was posted 20 seconds ago
  &lt;title&gt; was posted 2 hours ago
  </code></pre>
  
  <p>The code for this is similar, but instead i use Time.now:</p>
  
  <pre><code>def time_since_posted
    time = (self.created_at..Time.now).count
    ...
    ...
  end
  </code></pre>