Class: Time

Inherits:
Object
  • Object
show all
Defined in:
lib/zmb/utils.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) since



127
128
129
# File 'lib/zmb/utils.rb', line 127

def since
  Time.now - self
end

- (Object) since_words



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/zmb/utils.rb', line 131

def since_words
  s = since
  m = Array.new
  s = s * -1 if future = (s < 0) # Is the time in the future?
  
  [
    ['year',   60 * 60 * 24 * 365],
    ['month',  60 * 60 * 24 * 30],
    ['week',   60 * 60 * 24 * 7],
    ['day',    60 * 60 * 24],
    ['hour',   60 * 60],
    ['minute', 60],
    ['second', 1],
  ].each do |word, t|
    amount = (s/t).floor
    s -= amount * t
    m << "#{amount} #{word.plural(amount)}" unless amount == 0
  end
  
  m << 'now' if m.size == 0
  
  m.list_join + (future ? ' left' : '')
end