Created
June 6, 2013 14:35
-
-
Save seyhunak/5721974 to your computer and use it in GitHub Desktop.
Ruby minutes_in_words converter
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) | |
timestamp = Time.at(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("%b %e %Y %R %p")}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment