Skip to content

Instantly share code, notes, and snippets.

@guilleiguaran
Created August 5, 2010 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guilleiguaran/509870 to your computer and use it in GitHub Desktop.
Save guilleiguaran/509870 to your computer and use it in GitHub Desktop.
def minutes_in_words(timestamp)
minutes = (((Time.now - timestamp).abs)/60).round
return nil if minutes < 0
case minutes
when 0..1 then "less than 1 minute"
when 1..2 then "1 minute ago"
when 2..59 then "#{minutes} minutes ago"
when 60..1440 then "#{minutes/60} hours ago"
when 1440..2880 then "1 day ago"
when 2880..11519 then "#{minutes/60/24} days ago"
else "#{timestamp.strftime("%R %p %b%e %Y")}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment