Skip to content

Commit

Permalink
Time#- with a DateTime argument behaves the same as with a Time argum…
Browse files Browse the repository at this point in the history
…ent, i.e. returns the difference between self and arg as a Float [#3476 status:resolved]
  • Loading branch information
gbuesing committed Jan 28, 2010
1 parent ce50c96 commit 3f7729a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*2.3.6 (pending)*

* Time#- with a DateTime argument behaves the same as with a Time argument, i.e. returns the difference between self and arg as a Float #3476 [Geoff Buesing]

* YAML serialization for OrderedHash. #3608 [Gregor Schmidt]

* Update bundled TZInfo to v0.3.16 [Geoff Buesing]
Expand Down
Expand Up @@ -283,7 +283,7 @@ def minus_with_duration(other) #:nodoc:
# are coerced into values that Time#- will recognize
def minus_with_coercion(other)
other = other.comparable_time if other.respond_to?(:comparable_time)
minus_without_coercion(other)
other.is_a?(::DateTime) ? to_f - other.to_f : minus_without_coercion(other)
end

# Layers additional behavior on Time#<=> so that DateTime and ActiveSupport::TimeWithZone instances
Expand Down
4 changes: 4 additions & 0 deletions activesupport/test/core_ext/time_ext_test.rb
Expand Up @@ -680,6 +680,10 @@ def test_compare_with_time_with_zone
def test_minus_with_time_with_zone
assert_equal 86_400.0, Time.utc(2000, 1, 2) - ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1), ActiveSupport::TimeZone['UTC'] )
end

def test_minus_with_datetime
assert_equal 86_400.0, Time.utc(2000, 1, 2) - DateTime.civil(2000, 1, 1)
end

def test_time_created_with_local_constructor_cannot_represent_times_during_hour_skipped_by_dst
with_env_tz 'US/Eastern' do
Expand Down

0 comments on commit 3f7729a

Please sign in to comment.