lib/active_support/duration.rb in activesupport-5.2.0.beta2 vs lib/active_support/duration.rb in activesupport-5.2.0.rc1

- old
+ new

@@ -192,11 +192,10 @@ remainder = (remainder % part_in_seconds).round(9) end end parts[:seconds] = remainder - parts.reject! { |k, v| v.zero? } new(value, parts) end private @@ -209,10 +208,11 @@ end 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: if Scalar === other [other, self] @@ -368,9 +368,11 @@ end alias :until :ago 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) }. map { |unit, val| "#{val} #{val == 1 ? unit.to_s.chop : unit.to_s}" }. to_sentence(locale: ::I18n.default_locale)