def time_ago_in_words(once_upon_a)
      dt = Time.now.to_f - once_upon_a.to_f

      words = nil

      TIME_INTERVALS.each do |pair|
        mag, term = pair.first, pair.last
        if dt >= mag
          units = Integer(dt / mag)
          words = "%d %s%s" % [units, term, units > 1 ? 's' : '']
          break
        end
      end

      if words
        words
      else
        once_upon_a.strftime("%Y-%m-%d")
      end
    end
def time_ago_in_words(once_upon_a)
      dt = Time.now.to_f - once_upon_a.to_f

      words = nil

      TIME_INTERVALS.each do |pair|
        mag, term = pair.first, pair.last
        if dt >= mag
          units = Integer(dt / mag)
          words = "%d %s%s" % [units, term, units > 1 ? 's' : '']
          break
        end
      end

      if words
        words
      else
        once_upon_a.strftime("%Y-%m-%d")
      end
    end
Workalike for ActiveSupport date-helper method. Given a Time in the past, return
 a natural-language English string that describes the duration separating that time from
 the present. The duration is very approximate, and will be rounded down to the nearest
 appropriate interval (e.g. 2.5 hours becomes 2 hours).

 @example about three days ago
    time_ago_in_words(Time.now - 86400*3.1) # => "3 days"

 @param [Time] once_upon_a the long-ago time to compare to Time.now
 @return [String] an English time duration