Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8732

Show
Ignore:
Timestamp:
01/26/08 00:34:44 (8 months ago)
Author:
gbuesing
Message:

TimeWithZone#- added, so that #- can handle a Time or TimeWithZone argument correctly

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/CHANGELOG

    r8731 r8732  
    11*SVN* 
     2 
     3* TimeWithZone#- added, so that #- can handle a Time or TimeWithZone argument correctly [Geoff Buesing] 
    24 
    35* with_timezone test helper renamed with_env_tz, to distinguish between setting ENV['TZ'] and setting Time.zone in tests [Geoff Buesing] 
  • trunk/activesupport/lib/active_support/time_with_zone.rb

    r8720 r8732  
    107107      utc <=> other 
    108108    end 
     109     
     110    # Need to override #- to intercept situation where a Time or Time With Zone object is passed in 
     111    # Otherwise, just pass on to method missing 
     112    def -(other) 
     113      other.acts_like?(:time) ? utc - other : method_missing(:-, other) 
     114    end 
    109115   
    110116    # A TimeProxy acts like a Time, so just return self 
  • trunk/activesupport/test/core_ext/time_with_zone_test.rb

    r8730 r8732  
    125125    def test_minus_with_time 
    126126      assert_equal  86_400.0,  ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2), TimeZone['UTC'] ) - Time.utc(2000, 1, 1) 
     127      assert_equal  86_400.0,  ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2), TimeZone['Hawaii'] ) - Time.utc(2000, 1, 1) 
    127128    end 
    128129