lib/active_support/duration.rb in activesupport-7.0.0.rc3 vs lib/active_support/duration.rb in activesupport-7.0.0

- old
+ new

@@ -189,25 +189,26 @@ unless value.is_a?(::Numeric) raise TypeError, "can't build an #{self.name} from a #{value.class.name}" end parts = {} - remainder = value.round(9) + remainder_sign = value <=> 0 + remainder = value.round(9).abs variable = false PARTS.each do |part| unless part == :seconds part_in_seconds = PARTS_IN_SECONDS[part] - parts[part] = remainder.div(part_in_seconds) + parts[part] = remainder.div(part_in_seconds) * remainder_sign remainder %= part_in_seconds unless parts[part].zero? variable ||= VARIABLE_PARTS.include?(part) end end end unless value == 0 - parts[:seconds] = remainder + parts[:seconds] = remainder * remainder_sign new(value, parts, variable) end private