Skip to content

Instantly share code, notes, and snippets.

@oogali
Created February 9, 2012 04:30
Show Gist options
  • Save oogali/1777306 to your computer and use it in GitHub Desktop.
Save oogali/1777306 to your computer and use it in GitHub Desktop.
Display a duration as a readable string
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