Skip to content

Instantly share code, notes, and snippets.

@jazzytomato
Last active August 29, 2015 14:27
Show Gist options
  • Save jazzytomato/004a026a96113f1ae570 to your computer and use it in GitHub Desktop.
Save jazzytomato/004a026a96113f1ae570 to your computer and use it in GitHub Desktop.
def readable secs
return "0 minute" if secs < 60
secs /= 60
[[60, :minute], [24, :hour], [Float::INFINITY, :day]].map{ |count, name|
if secs > 0
secs, n = secs.divmod(count)
pluralize(n.to_i, name.to_s) if n > 0
end
}.compact.reverse.join(' ')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment