Created
April 7, 2011 19:18
-
-
Save spacecowb0y/908484 to your computer and use it in GitHub Desktop.
Time in Words - Ruby Helper
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 time_ago_in_words(timestamp) | |
minutes = (((Time.now - timestamp).abs)/60).round | |
return nil if minutes < 0 | |
case | |
when minutes < 1 then "less than a minute ago" | |
when minutes == 1 then "1 minute ago" | |
when minutes < 50 then "#{minutes} minutes ago" | |
when minutes < 90 then "1 hour ago" | |
when minutes < 1440 then "#{(minutes / 60).round} hours ago" | |
else | |
timestamp.strftime('%d %b %Y') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment