Changeset 8730
- Timestamp:
- 01/25/08 23:55:07 (8 months ago)
- Files:
-
- trunk/activesupport/CHANGELOG (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/time/calculations.rb (modified) (2 diffs)
- trunk/activesupport/test/core_ext/time_ext_test.rb (modified) (1 diff)
- trunk/activesupport/test/core_ext/time_with_zone_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/CHANGELOG
r8720 r8730 1 1 *SVN* 2 3 * Time#- coerces TimeWithZone argument to a Time instance so that difference in seconds can be calculated. Closes #10914 [Geoff Buesing, yyyc514] 2 4 3 5 * Adding UTC zone to TimeZone; TimeWithZone no longer has to fake UTC zone with nil [Geoff Buesing] trunk/activesupport/lib/active_support/core_ext/time/calculations.rb
r8715 r8730 13 13 alias_method :minus_without_duration, :- 14 14 alias_method :-, :minus_with_duration 15 16 alias_method :minus_without_coercion, :- 17 alias_method :-, :minus_with_coercion 15 18 16 19 alias_method :compare_without_coercion, :<=> … … 219 222 end 220 223 224 # Time#- can also be used to determine the number of seconds between two Time instances. 225 # We're layering on additional behavior so that ActiveSupport::TimeWithZone instances 226 # are coerced into values that Time#- will recognize 227 def minus_with_coercion(other) 228 other = other.comparable_time if other.respond_to?(:comparable_time) 229 minus_without_coercion(other) 230 end 231 221 232 # Layers additional behavior on Time#<=> so that DateTime and ActiveSupport::TimeWithZone instances 222 233 # can be chronologically compared with a Time trunk/activesupport/test/core_ext/time_ext_test.rb
r8720 r8730 455 455 assert_equal(-1, Time.utc(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 1), TimeZone['UTC'] )) 456 456 end 457 458 def test_minus_with_time_with_zone 459 assert_equal 86_400.0, Time.utc(2000, 1, 2) - ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1), TimeZone['UTC'] ) 460 end 457 461 458 462 protected trunk/activesupport/test/core_ext/time_with_zone_test.rb
r8720 r8730 121 121 def test_minus_with_duration 122 122 assert_equal Time.utc(1999, 12, 26, 19, 0 ,0), (@twz - 5.days).time 123 end 124 125 def test_minus_with_time 126 assert_equal 86_400.0, ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2), TimeZone['UTC'] ) - Time.utc(2000, 1, 1) 127 end 128 129 def test_minus_with_time_with_zone 130 twz1 = ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1), TimeZone['UTC'] ) 131 twz2 = ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2), TimeZone['UTC'] ) 132 assert_equal 86_400.0, twz2 - twz1 123 133 end 124 134