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: TimeWithzone bug #40448

Merged
merged 1 commit into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ def at_with_coercion(*args)
# Time.at can be called with a time or numerical value
time_or_number = args.first

if time_or_number.is_a?(ActiveSupport::TimeWithZone) || time_or_number.is_a?(DateTime)
if time_or_number.is_a?(ActiveSupport::TimeWithZone)
at_without_coercion(time_or_number.to_r).getlocal
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the alternative implementation I'm pushing for in #40137. #40413 is a duplicate of #38831, although demonstrated slightly differently.

I'd like to wait a bit and see if #40137 gets merged, since it was opened first and the author clearly invested a lot of time into it already.

elsif time_or_number.is_a?(DateTime)
at_without_coercion(time_or_number.to_f).getlocal
else
at_without_coercion(time_or_number)
Expand Down
9 changes: 9 additions & 0 deletions activesupport/test/core_ext/time_with_zone_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,15 @@ def test_use_zone_raises_on_invalid_timezone
assert_equal ActiveSupport::TimeZone["Alaska"], Time.zone
end

def test_end_of_period_timezone_equality_with_DateTime
Time.use_zone "UTC" do
without_time_zone = "2019-01-01 00:00:00Z".to_time.end_of_month
zoned = without_time_zone.in_time_zone

assert_equal(Time.zone.at(without_time_zone), Time.zone.at(zoned))
end
end

def test_time_zone_getter_and_setter
Time.zone = ActiveSupport::TimeZone["Alaska"]
assert_equal ActiveSupport::TimeZone["Alaska"], Time.zone
Expand Down