Skip to content

Commit

Permalink
TimeWithZone#- gives correct result with wrapped DateTime, and with D…
Browse files Browse the repository at this point in the history
…ateTime argument
  • Loading branch information
gbuesing committed Jan 4, 2009
1 parent f00e86d commit d2a1c27
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*2.3.0 [Edge]* *2.3.0 [Edge]*


* TimeWithZone#- gives correct result with wrapped DateTime, and with DateTime argument [Geoff Buesing]

* Updated i18n gem to version 0.1.1 #1635 [Yaroslav Markin] * Updated i18n gem to version 0.1.1 #1635 [Yaroslav Markin]


* Add :allow_nil option to delegate. #1127 [Sergio Gil] * Add :allow_nil option to delegate. #1127 [Sergio Gil]
Expand Down
2 changes: 1 addition & 1 deletion activesupport/lib/active_support/time_with_zone.rb
Expand Up @@ -199,7 +199,7 @@ def -(other)
# If we're subtracting a Duration of variable length (i.e., years, months, days), move backwards from #time, # If we're subtracting a Duration of variable length (i.e., years, months, days), move backwards from #time,
# otherwise move backwards #utc, for accuracy when moving across DST boundaries # otherwise move backwards #utc, for accuracy when moving across DST boundaries
if other.acts_like?(:time) if other.acts_like?(:time)
utc - other utc.to_f - other.to_f
elsif duration_of_variable_length?(other) elsif duration_of_variable_length?(other)
method_missing(:-, other) method_missing(:-, other)
else else
Expand Down
9 changes: 9 additions & 0 deletions activesupport/test/core_ext/time_with_zone_test.rb
Expand Up @@ -256,6 +256,15 @@ def test_minus_with_time_with_zone
twz2 = ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2), ActiveSupport::TimeZone['UTC'] ) twz2 = ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2), ActiveSupport::TimeZone['UTC'] )
assert_equal 86_400.0, twz2 - twz1 assert_equal 86_400.0, twz2 - twz1
end end

def test_minus_with_datetime
assert_equal 86_400.0, ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2), ActiveSupport::TimeZone['UTC'] ) - DateTime.civil(2000, 1, 1)
end

def test_minus_with_wrapped_datetime
assert_equal 86_400.0, ActiveSupport::TimeWithZone.new( DateTime.civil(2000, 1, 2), ActiveSupport::TimeZone['UTC'] ) - Time.utc(2000, 1, 1)
assert_equal 86_400.0, ActiveSupport::TimeWithZone.new( DateTime.civil(2000, 1, 2), ActiveSupport::TimeZone['UTC'] ) - DateTime.civil(2000, 1, 1)
end


def test_plus_and_minus_enforce_spring_dst_rules def test_plus_and_minus_enforce_spring_dst_rules
silence_warnings do # silence warnings raised by tzinfo gem silence_warnings do # silence warnings raised by tzinfo gem
Expand Down

0 comments on commit d2a1c27

Please sign in to comment.