server/sinatra_helpers.rb
#
# Format the given number of seconds into something more friendly.
#
Format the given number of seconds into something more friendly.
Format the given number of seconds into something more friendly .
def seconds_to_ago( a )
    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' 
    when 120..3540 then
      (a/60).to_i.to_s+' minutes ago'
    when 3541..7100 then
      'an hour ago' 
    when 7101..82800 then
      ((a+99)/3600).to_i.to_s+' hours ago'
    when 82801..172000 then
      'a day ago' 
    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
def seconds_to_ago ( a ) 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' when 120 .. 3540 then ( a / 60 ) . to_i . to_s + ' minutes ago' when 3541 .. 7100 then 'an hour ago' when 7101 .. 82800 then ( ( a + 99 ) / 3600 ) . to_i . to_s + ' hours ago' when 82801 .. 172000 then 'a day ago' 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
Format the given number of seconds into something more friendly.
Format the given number of seconds into something more friendly .
#120 = 2 minutes # 3600 = 1 hour # 86400 = 1 day
a
<not_specific>