class Time

Public Instance Methods

elapsed() click to toggle source

How many seconds have elapsed since this time?

# File lib/epitools/core_ext/time.rb, line 50
def elapsed
  Time.now - self
end
in_words() click to toggle source

Relative time, in words. (eg: “1 second ago”, “2 weeks from now”, etc.)

# File lib/epitools/core_ext/time.rb, line 6
def in_words
  delta   = (Time.now-self).to_i
  a       = delta.abs

  amount  = case a
    when 0
      'just now'
    when 1
      '1 second'
    when 2..59
      "second".amount(a)
    when 1.minute...1.hour
      "minute".amount(a/1.minute)
    when 1.hour...1.day
      "hour".amount(a/1.hour)
    when 1.day...7.days
      "day".amount(a/1.day)
    when 1.week...1.month
      "week".amount(a/1.week)
    when 1.month...12.months
      "month".amount(a/1.month)
    else
      "year".amount(a/1.year)
  end

  if delta < 0
    amount += " from now"
  elsif delta > 0
    amount += " ago"
  end

  amount
end
quarter() click to toggle source

Which “quarter” of the year does this date fall into?

# File lib/epitools/core_ext/time.rb, line 43
def quarter
  (month / 3.0).ceil
end