diff options
author | Edouard CHIN <edouard.chin@shopify.com> | 2018-10-09 13:36:56 -0400 |
---|---|---|
committer | Edouard CHIN <edouard.chin@shopify.com> | 2018-10-12 13:27:13 -0400 |
commit | c85e3f65f3409fc329732912908c3601d8e5fac9 (patch) | |
tree | 48622e894c56ce6423cb7aeabd4bb0e09aa69c1d /activesupport/lib/active_support/core_ext/date_time | |
parent | 99c87ad2474d5c5b6e52ceac34c3cf9f9cb57f9f (diff) | |
download | rails-c85e3f65f3409fc329732912908c3601d8e5fac9.tar.gz rails-c85e3f65f3409fc329732912908c3601d8e5fac9.tar.bz2 rails-c85e3f65f3409fc329732912908c3601d8e5fac9.zip |
Fix issue where duration where always rounded up to a second:
- Adding a Float as a duration to a datetime would result in the Float
being rounded. Doing something like would have no effect because the
0.45 seconds would be rounded to 0 second.
```ruby
time = DateTime.parse("2018-1-1")
time += 0.45.seconds
```
This behavior was intentionally added a very long time ago, the
reason was because Ruby 1.8 was using `Integer#gcd` in the
constructor of Rational which didn't accept a float value.
That's no longer the case and doing `Rational(0.45, 86400)` would
now perfectly work fine.
- Fixes #34008
Diffstat (limited to 'activesupport/lib/active_support/core_ext/date_time')
-rw-r--r-- | activesupport/lib/active_support/core_ext/date_time/calculations.rb | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/date_time/calculations.rb b/activesupport/lib/active_support/core_ext/date_time/calculations.rb index e61b23f842..bc670c3e76 100644 --- a/activesupport/lib/active_support/core_ext/date_time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date_time/calculations.rb @@ -110,7 +110,7 @@ class DateTime # instance time. Do not use this method in combination with x.months, use # months_since instead! def since(seconds) - self + Rational(seconds.round, 86400) + self + Rational(seconds, 86400) end alias :in :since |