Created
August 5, 2010 15:10
-
-
Save guilleiguaran/509870 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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