Skip to content

Commit

Permalink
Merge pull request #40448 from BKSpurgeon/fix-timezone-rounding-bug
Browse files Browse the repository at this point in the history
Fix: timezone bug - rounding problem
  • Loading branch information
eugeneius committed Oct 30, 2020
1 parent 67e4702 commit f0cdd75
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
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
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
7 changes: 7 additions & 0 deletions activesupport/test/core_ext/time_with_zone_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,13 @@ def test_use_zone_raises_on_invalid_timezone
assert_equal ActiveSupport::TimeZone["Alaska"], Time.zone
end

def test_time_at_precision
Time.use_zone "UTC" do
time = "2019-01-01 00:00:00Z".to_time.end_of_month
assert_equal Time.at(time), Time.at(time.in_time_zone)
end
end

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

0 comments on commit f0cdd75

Please sign in to comment.