Fix issue where duration where always rounded up to a second:#34135
Merged
pixeltrix merged 1 commit intorails:masterfrom Oct 15, 2018
Merged
Fix issue where duration where always rounded up to a second:#34135pixeltrix merged 1 commit intorails:masterfrom
pixeltrix merged 1 commit intorails:masterfrom
Conversation
|
r? @kamipo (@rails-bot has picked a reviewer for you, use r? to override) |
a61cfcd to
bcd595a
Compare
albertoalmagro
approved these changes
Oct 9, 2018
Contributor
albertoalmagro
left a comment
There was a problem hiding this comment.
Nice fix @Edouard-chin ! Thanks 👏
Contributor
|
@Edouard-chin can you add a CHANGELOG entry please |
bcd595a to
55b12e7
Compare
Member
Author
|
Oops sorry, indeed that's not a bugfix but a behaviour change. Added the CHANGELOG entry |
Member
Author
|
Some flaky test in the railties component |
gmcgibbon
approved these changes
Oct 12, 2018
- 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 rails#34008
55b12e7 to
c85e3f6
Compare
Contributor
|
@Edouard-chin thanks! 👍 |
suketa
added a commit
to suketa/rails_sandbox
that referenced
this pull request
Jun 29, 2019
Fix issue where duration where always rounded up to a second rails/rails#34135
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
This behavior was intentionally added a very long time ago, the
reason was because Ruby 1.8 was using
Integer#gcdin theconstructor of Rational which didn't accept a float value.
That's no longer the case and doing
Rational(0.45, 86400)wouldnow perfectly work fine.
Fixes Incorrect behavior when adding DateTime and float ActiveSupport::Duration #34008
cc/ @pixeltrix