Module: TimeAgoInWords
- Included in:
- Time
- Defined in:
- lib/time_ago_in_words/methods.rb,
lib/time_ago_in_words/version.rb
Constant Summary collapse
- VERSION =
"0.1.1"
Instance Method Summary collapse
-
#ago_in_words ⇒ String
Convert elapsed seconds from Time.now to the current Time instance into an English human readable text like ‘4 hours and 1 minute ago’ It is not well suited for dates older than 1 year.
Instance Method Details
#ago_in_words ⇒ String
Note:
Inspired from stackoverflow.com/a/4136485/511069
Convert elapsed seconds from Time.now to the current Time instance
into an English human readable text like '4 hours and 1 minute ago'
It is not well suited for dates older than 1 year
22 23 24 25 26 27 28 29 30 |
# File 'lib/time_ago_in_words/methods.rb', line 22 def ago_in_words return 'a very very long time ago' if self.year < 1800 secs = Time.now - self return 'just now' if secs > -1 && secs < 1 return '' if secs <= -1 pair = ago_in_words_pair(secs) ary = ago_in_words_singularize(pair) ary.size == 0 ? '' : ary.join(' and ') << ' ago' end |