Skip to content

Commit

Permalink
Merge pull request rails#52084 from jhawthorn/time_with_zone_always_time
Browse files Browse the repository at this point in the history
Remove dead code for DateTime-backed TimeWithZone
  • Loading branch information
jhawthorn authored Jul 11, 2024
2 parents 36b2dbf + 725ebc9 commit 4867559
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
5 changes: 2 additions & 3 deletions activesupport/lib/active_support/time_with_zone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def +(other)
if duration_of_variable_length?(other)
method_missing(:+, other)
else
result = utc.acts_like?(:date) ? utc.since(other) : utc + other rescue utc.since(other)
result = utc + other
result.in_time_zone(time_zone)
end
end
Expand Down Expand Up @@ -336,7 +336,7 @@ def -(other)
elsif duration_of_variable_length?(other)
method_missing(:-, other)
else
result = utc.acts_like?(:date) ? utc.ago(other) : utc - other rescue utc.ago(other)
result = utc - other
result.in_time_zone(time_zone)
end
end
Expand Down Expand Up @@ -537,7 +537,6 @@ def respond_to?(sym, include_priv = false)
# Ensure proxy class responds to all methods that underlying time instance
# responds to.
def respond_to_missing?(sym, include_priv)
return false if sym.to_sym == :acts_like_date?
time.respond_to?(sym, include_priv)
end

Expand Down
7 changes: 4 additions & 3 deletions activesupport/test/core_ext/time_with_zone_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,10 @@ def test_plus_with_integer_when_self_wraps_datetime
assert_equal DateTime.civil(1999, 12, 31, 19, 0, 5), (twz + 5).time
end

def test_plus_when_crossing_time_class_limit
twz = ActiveSupport::TimeWithZone.new(Time.utc(2038, 1, 19), @time_zone)
assert_equal [0, 0, 19, 19, 1, 2038], (twz + 86_400).to_a[0, 6]
def test_no_limit_on_times
twz = ActiveSupport::TimeWithZone.new(Time.utc(2000, 1, 1), @time_zone)
assert_equal [0, 0, 19, 31, 12, 11999], (twz + 10_000.years).to_a[0, 6]
assert_equal [0, 0, 19, 31, 12, -8001], (twz - 10_000.years).to_a[0, 6]
end

def test_plus_with_duration
Expand Down

0 comments on commit 4867559

Please sign in to comment.