module Timeago
Public Class Methods
in_words(time)
click to toggle source
# File lib/time_ago.rb, line 3 def self.in_words(time) minutes = (((Time.now - time).abs)/60).round return nil if minutes < 0 case minutes when 0..1 then 'less than a minute' when 2..4 then 'less than 5 minutes' when 5..14 then 'less than 15 minutes' when 15..29 then "half an hour" when 30..59 then "#{minutes} minutes" when 60..119 then '1 hour' when 120..239 then '2 hours' when 240..479 then '4 hours' when 480..719 then '8 hours' when 720..1439 then '12 hours' when 1440..11519 then "#{(minutes/1440).floor} days" when 11520..43199 then "#{(minutes/11520).floor} weeks" when 43200..525599 then "#{(minutes/43200).floor} months" else "#{(minutes/525600).floor} years" end end
since(time)
click to toggle source
# File lib/time_ago.rb, line 25 def self.since(time) if str = in_words(time) "#{str} ago" end end