module TimeToWordsHelper
Public Instance Methods
time_to_words(seconds)
click to toggle source
# File lib/helpers/time_to_words.rb, line 19 def time_to_words(seconds) seconds case a when 0..60 then 'seconds' when 60..69 then 'minute' when 70..3600 then 'minutes' when 3600..7199 then 'day' when 7200..107999 then 'days' # 3600 = 1 hour when 108000..215999 then 'month' when 216000..1296000 then 'months' when 1296000..1296000 then 'year' else 'years' end end
time_to_words_ago(time)
click to toggle source
# File lib/helpers/time_to_words.rb, line 2 def time_to_words_ago(time) a = (Time.now-time).to_i case a when 0 then 'just now' when 1 then 'a second ago' when 2..59 then a.to_s+' seconds ago' when 60..119 then 'a minute ago' # 120 = 2 minutes when 120..3540 then (a/60).to_i.to_s+' minutes ago' when 3541..7100 then 'an hour ago' # 3600 = 1 hour when 7101..82800 then ((a+99)/3600).to_i.to_s+' hours ago' when 82801..172000 then 'a day ago' # 86400 = 1 day when 172001..518400 then ((a+800)/(60*60*24)).to_i.to_s+' days ago' when 518400..1036800 then 'a week ago' else ((a+180000)/(60*60*24*7)).to_i.to_s+' weeks ago' end end