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

Behavior of days is different between Rails5.0 and 5.1 #30546

Closed
ponkotuy opened this issue Sep 8, 2017 · 8 comments
Closed

Behavior of days is different between Rails5.0 and 5.1 #30546

ponkotuy opened this issue Sep 8, 2017 · 8 comments
Assignees

Comments

@ponkotuy
Copy link

ponkotuy commented Sep 8, 2017

Steps to reproduce

Time.now.ago(1.days / 2)

Results::
Rails5.1.4/5.1.3/5.1.0 => now
Rails5.0.2 => half a day ago

Expected behavior

Rails5.0.2

System configuration

Ruby 2.4.1

@redtachyons
Copy link

Related to #29163 ?

@ponkotuy
Copy link
Author

ponkotuy commented Sep 8, 2017

I don't understand whether #29163 can solve this issue. But I think it is a close problem.

@ponkotuy
Copy link
Author

ponkotuy commented Sep 8, 2017

Rails5.1.0 and 5.1.4 are equal to Rails5.1.3

@sgrif
Copy link
Contributor

sgrif commented Sep 21, 2017

This seems like the expected behavior to me.
screen shot 2017-09-21 at 5 32 54 pm

@sgrif sgrif closed this as completed Sep 21, 2017
@matthewd
Copy link
Member

Seems surprising to me: 1.to_f / 2 isn't 0.0, despite having "started" from an integer.

@pixeltrix ?

@matthewd matthewd reopened this Sep 22, 2017
khall added a commit to khall/rails that referenced this issue Oct 2, 2017
Previously durations could be divided and would return partial durations,
but in Rails 5.1 dividing a duration such as

    1.day / 2

would return a duration of 0 instead of 0.5 days. This change restores
that functionality by forcing the divisor to a float, which allows for
the partial duration to be returned. Also updated Duration::Scalar to
behave the same way. Fixes rails#30546.
@ghiculescu
Copy link
Member

Is this still an issue in Rails 6.1?

@aried3r
Copy link
Contributor

aried3r commented Sep 8, 2021

@ghiculescu, just tried using Rails 6.1.4.1:

Loading development environment (Rails 6.1.4.1)
2.7.4 [1] » 1 / 2
=> 0
2.7.4 [2] » 1.day / 2
=> 43200 seconds
2.7.4 [3] » 1.0 / 2
=> 0.5
2.7.4 [4] » 1.0.day / 2
=> 0.5 days

@pixeltrix
Copy link
Contributor

pixeltrix commented Sep 9, 2021

This seems fine as well

>> Time.current.at_beginning_of_hour
=> Thu, 09 Sep 2021 15:00:00.000000000 BST +01:00
>> Time.current.at_beginning_of_hour.ago(1.day / 2)
=> Thu, 09 Sep 2021 03:00:00.000000000 BST +01:00

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants