Created
February 9, 2012 04:30
-
-
Save oogali/1777306 to your computer and use it in GitHub Desktop.
Display a duration as a readable string
This file contains hidden or 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
require 'action_view' | |
include ActionView::Helpers::DateHelper | |
def readable(seconds) | |
case seconds | |
when 86400*3..86400*7 | |
(Time.now - seconds).strftime('%A').downcase | |
when 86400*7..86400*14 | |
'just over a week ago' | |
when 86400*14..86400*28 | |
"#{(seconds / 604800).to_i} weeks ago" | |
else | |
time_ago_in_words(Time.now - seconds) + ' ago' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment