-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Calling Time.zone.at on a TimeWithZone can have different behavior than calling Time.zone.at on a Time #40413
Comments
(I added the print statements to help clarify the problem. They're not necessary for the spec to fail.) |
@BKSpurgeon Yep, all of that looks correct to me. I realize this seems like a strange test case to bring up, but we ran into a real-world scenario that's triggered by this. Our tests were passing for The test case I posted above was my attempt to simplify this problem so it was reproducible. |
This is where the rounding off seems to occur: at_without_coercion(time_or_number.to_f).getlocal
# time_or_number.to_f => 1548939600.0 # which is not what we want, per se.
def at_with_coercion(*args)
# details skipped
if time_or_number.is_a?(ActiveSupport::TimeWithZone) || time_or_number.is_a?(DateTime)
at_without_coercion(time_or_number.to_f).getlocal # with TimeWithZone, things get rounded up here
else
at_without_coercion(time_or_number) # when dealing with a Time object we hit this branch, and everything is fine
end
end I don't think this is or should be the intended behaviour - that extra Rational should be preserved as much as possible. Perhaps a new object should be passed into |
Fixed by #40448. |
@eugeneius Awesome! Thank you so much. 🙂 |
Steps to reproduce
We ran across this tricky bug in our application. The behavior for a time at the end of a month changes based upon whether it's a
Time
or aTimeWithZone
.Expected behavior
The two times returned from
Time.zone.at
should be identical.Actual behavior
Somewhere along the way, the
TimeWithZone
is getting rounded up.System configuration
Rails version: 6.0.3
Ruby version: 2.7.1p83
The text was updated successfully, but these errors were encountered: