Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue where duration where always rounded up to a second: #34135

Merged
merged 1 commit into from Oct 15, 2018

Conversation

@Edouard-chin
Copy link
Member

@Edouard-chin Edouard-chin commented Oct 9, 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.

      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

cc/ @pixeltrix

@rails-bot
Copy link

@rails-bot rails-bot commented Oct 9, 2018

r? @kamipo

(@rails-bot has picked a reviewer for you, use r? to override)

Copy link
Contributor

@albertoalmagro albertoalmagro left a comment

Nice fix @Edouard-chin ! Thanks 👏

@pixeltrix
Copy link
Member

@pixeltrix pixeltrix commented Oct 10, 2018

@Edouard-chin can you add a CHANGELOG entry please

@pixeltrix pixeltrix assigned pixeltrix and unassigned kamipo Oct 10, 2018
@Edouard-chin Edouard-chin force-pushed the ec-rounded-duration branch from bcd595a to 55b12e7 Oct 10, 2018
@Edouard-chin
Copy link
Member Author

@Edouard-chin Edouard-chin commented Oct 10, 2018

Oops sorry, indeed that's not a bugfix but a behaviour change. Added the CHANGELOG entry

@Edouard-chin
Copy link
Member Author

@Edouard-chin Edouard-chin commented Oct 10, 2018

Some flaky test in the railties component

- 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
@Edouard-chin Edouard-chin force-pushed the ec-rounded-duration branch from 55b12e7 to c85e3f6 Oct 12, 2018
@pixeltrix pixeltrix merged commit 777cc1d into rails:master Oct 15, 2018
2 checks passed
@pixeltrix
Copy link
Member

@pixeltrix pixeltrix commented Oct 15, 2018

@Edouard-chin thanks! 👍

suketa added a commit to suketa/rails_sandbox that referenced this issue Jun 29, 2019
Fix issue where duration where always rounded up to a second
rails/rails#34135
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants