Created
February 25, 2009 01:39
-
-
Save amiel/69934 to your computer and use it in GitHub Desktop.
give it a value in seconds, and it will return a sentence
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
def length_of_time_in_words(seconds) | |
seconds = seconds.to_i | |
%w[ year month week day hour minute second ].collect do |unit| | |
unit_in_seconds = 1.send(unit).to_i | |
n = seconds / unit_in_seconds | |
seconds -= n * unit_in_seconds | |
pluralize(n, unit) unless n.zero? | |
end.compact.to_sentence | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment