Sha256: c1b4cfee2f5c1433a6d152445b61028400701e9b3ca85c0ad70ab9773e17b9de
Contents?: true
Size: 975 Bytes
Versions: 20
Compression:
Stored size: 975 Bytes
Contents
module Timeago 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 def self.since(time) if str = in_words(time) "#{str} ago" end end end
Version data entries
20 entries across 20 versions & 1 rubygems