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

Broken division operation on Duration objects #29952

Closed
Sayanc93 opened this issue Jul 26, 2017 · 2 comments
Closed

Broken division operation on Duration objects #29952

Sayanc93 opened this issue Jul 26, 2017 · 2 comments

Comments

@Sayanc93
Copy link
Contributor

Division operation on Duration objects is broken in 5.2.0.alpha

4.minutes / 2.minutes
=> 0 minutes

4.minutes / 1.minute
=> 0 minutes

While, (4.minutes / 2.minute).value does yield 4 but returning 0 minutes is incorrect representation.
Also, notice that

time = 4.minutes / 1.minute
=> 4 minutes

time / 2.minutes
=> 0.minutes

time.value
=> 4

2.minutes.value
=> 120

Chaining of operations on Duration objects fails due to inconsistencies in value attribute.

The values should be consistent with the protocol set here to allow operation chaining on Duration objects i.e set values in seconds.

@fphilipe
Copy link
Contributor

I've experienced this behavior as well. It used to be that the time units would cancel out on division. Just checked and this changed starting in version 5.1.0.

The following used to be the case before 5.1.0:

irb(main):001:0> require 'active_support/all'
=> true
irb(main):002:0> 1.hour / 1.minute
=> 60

Since 5.1.0 this is the observed behavior:

irb(main):001:0> require 'active_support/all'
=> true
irb(main):002:0> 1.hour / 1.minute
=> 0 hours
irb(main):003:0> (1.hour / 1.minute).to_i
=> 60

@pixeltrix
Copy link
Contributor

Fixed by #29971

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

No branches or pull requests

3 participants