diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-01-01 01:03:16 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-01 01:03:16 +0900 |
commit | 540c60ff4723670bf106c2ae46e3a6723cbf42a4 (patch) | |
tree | 48c1621337d848201054f1b5d647d9fe76f1e43e /activesupport/lib | |
parent | 316d87e412e1c6bc9c7a590b866befbb6bab167f (diff) | |
parent | 041b2052e6d5d715474e34f3625f88f586941bfd (diff) | |
download | rails-540c60ff4723670bf106c2ae46e3a6723cbf42a4.tar.gz rails-540c60ff4723670bf106c2ae46e3a6723cbf42a4.tar.bz2 rails-540c60ff4723670bf106c2ae46e3a6723cbf42a4.zip |
Merge pull request #31310 from kinnrot/duration-modulo
Duration created with no parts will have a default seconds part eqaul to 0
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/duration.rb | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/duration.rb b/activesupport/lib/active_support/duration.rb index 1af3411a8a..fe1058762b 100644 --- a/activesupport/lib/active_support/duration.rb +++ b/activesupport/lib/active_support/duration.rb @@ -194,7 +194,6 @@ module ActiveSupport end parts[:seconds] = remainder - parts.reject! { |k, v| v.zero? } new(value, parts) end @@ -211,6 +210,7 @@ module ActiveSupport def initialize(value, parts) #:nodoc: @value, @parts = value, parts.to_h @parts.default = 0 + @parts.reject! { |k, v| v.zero? } end def coerce(other) #:nodoc: @@ -370,6 +370,8 @@ module ActiveSupport alias :before :ago def inspect #:nodoc: + return "0 seconds" if parts.empty? + parts. reduce(::Hash.new(0)) { |h, (l, r)| h[l] += r; h }. sort_by { |unit, _ | PARTS.index(unit) }. |