Class: Time

Inherits:
Object
  • Object
show all
Defined in:
lib/time-lord.rb

Constant Summary

Second =
1
Minute =
Second  * 60
Hour =
Minute  * 60
Day =
Hour    * 24
Week =
Day     * 7
Fortnight =
Week    * 2
Month =
Week    * 4
Quarter =
Month   * 3
Year =
Month   * 12
Olympiad =
Year    * 4
Lustrum =
Year    * 5
Decade =
Year    * 10
Indiction =
Year    * 15
Jubilee =
Decade  * 5
Century =
Decade  * 10
Millennium =
Century * 10
Eon =
1.0/0

Instance Method Summary (collapse)

Instance Method Details

- (Object) ago_in_words Also known as: time_ago_in_words



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/time-lord.rb', line 22

def ago_in_words

  # Find the time difference between the time provided and the current time.
  difference = get_time_difference_from self

  # Catch less than 1 second differences.
  return "just now" if difference < 1

  name   = get_unit_name_from difference
  amount = get_unit_amount_from difference
  count  = get_unit_count_from difference, amount

  # Determine if unit name needs pluralization.
  name += "s" if count > 1

  # Return the remaining string.
  "#{count} #{name} ago"
end