diff options
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/CHANGELOG | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/time/calculations.rb | 2 | ||||
-rw-r--r-- | activesupport/test/core_ext/time_ext_test.rb | 4 |
3 files changed, 7 insertions, 1 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 8553a8c0af..787fa26e44 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *Rails 3.0 (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] diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index 703b89ffd0..98906bc5c0 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -259,7 +259,7 @@ class Time # 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 alias_method :minus_without_coercion, :- alias_method :-, :minus_with_coercion diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb index f6003bc083..08c079e113 100644 --- a/activesupport/test/core_ext/time_ext_test.rb +++ b/activesupport/test/core_ext/time_ext_test.rb @@ -722,6 +722,10 @@ class TimeExtCalculationsTest < Test::Unit::TestCase 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 |