aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2016-11-27 08:17:50 +0900
committerRyuta Kamizono <kamipo@gmail.com>2016-11-27 08:22:38 +0900
commit6700f8572615b70ba4ff5e6739a32211fbabed0c (patch)
treef4630697e9a1c0ac3bfe8122220a3f6ddfe8cd0e /activemodel/lib/active_model
parent5921043f9e51dfe0750c13f1ca58d3c912e729c7 (diff)
downloadrails-6700f8572615b70ba4ff5e6739a32211fbabed0c.tar.gz
rails-6700f8572615b70ba4ff5e6739a32211fbabed0c.tar.bz2
rails-6700f8572615b70ba4ff5e6739a32211fbabed0c.zip
Fix `apply_seconds_precision` not to be affected by `mathn`
Currently `apply_seconds_precision` cannnot round usec when after `require 'mathn'`. ``` irb(main):001:0> 1234 / 1000 * 1000 => 1000 irb(main):002:0> 1234 - 1234 % 1000 => 1000 irb(main):003:0> require 'mathn' => true irb(main):004:0> 1234 / 1000 * 1000 => 1234 irb(main):005:0> 1234 - 1234 % 1000 => 1000 ```
Diffstat (limited to 'activemodel/lib/active_model')
-rw-r--r--activemodel/lib/active_model/type/helpers/time_value.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/activemodel/lib/active_model/type/helpers/time_value.rb b/activemodel/lib/active_model/type/helpers/time_value.rb
index ad78fd49ec..721f9543ed 100644
--- a/activemodel/lib/active_model/type/helpers/time_value.rb
+++ b/activemodel/lib/active_model/type/helpers/time_value.rb
@@ -34,7 +34,7 @@ module ActiveModel
return value unless precision && value.respond_to?(:usec)
number_of_insignificant_digits = 6 - precision
round_power = 10**number_of_insignificant_digits
- value.change(usec: value.usec / round_power * round_power)
+ value.change(usec: value.usec - value.usec % round_power)
end
def type_cast_for_schema(value)