diff options
author | Levin Alexander <mail@levinalex.net> | 2009-06-25 22:47:27 +0200 |
---|---|---|
committer | Yehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com> | 2009-07-02 11:22:25 -0700 |
commit | ab2d6abb55b45543656e2a0238857d3ba8379257 (patch) | |
tree | 311bcd746c4f0b58b90e96c63d75f544485dc01f /activesupport/lib/active_support/duration.rb | |
parent | cf5b2b250f9d7014c06f91527f9bd1bbfa7f3bd6 (diff) | |
download | rails-ab2d6abb55b45543656e2a0238857d3ba8379257.tar.gz rails-ab2d6abb55b45543656e2a0238857d3ba8379257.tar.bz2 rails-ab2d6abb55b45543656e2a0238857d3ba8379257.zip |
make #inspect if zero length duration return '0 seconds' instead of empty string [#2838 state:resolved]
Signed-off-by: Yehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>
Diffstat (limited to 'activesupport/lib/active_support/duration.rb')
-rw-r--r-- | activesupport/lib/active_support/duration.rb | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/duration.rb b/activesupport/lib/active_support/duration.rb index a33586f77f..713ae1b671 100644 --- a/activesupport/lib/active_support/duration.rb +++ b/activesupport/lib/active_support/duration.rb @@ -68,10 +68,12 @@ module ActiveSupport def inspect #:nodoc: consolidated = parts.inject(::Hash.new(0)) { |h,part| h[part.first] += part.last; h } - [:years, :months, :days, :minutes, :seconds].map do |length| + parts = [:years, :months, :days, :minutes, :seconds].map do |length| n = consolidated[length] "#{n} #{n == 1 ? length.to_s.singularize : length.to_s}" if n.nonzero? - end.compact.to_sentence(:locale => :en) + end.compact + parts = ["0 seconds"] if parts.empty? + parts.to_sentence(:locale => :en) end protected |