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

Changeset 9106

Show
Ignore:
Timestamp:
03/28/08 02:10:36 (2 months ago)
Author:
gbuesing
Message:

TimeWithZone time conversions don't need to be wrapped in TimeOrDateTime, because TZInfo does this internally

Files:

Legend:

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

    r9105 r9106  
    11*SVN* 
     2 
     3* TimeWithZone time conversions don't need to be wrapped in TimeOrDateTime, because TZInfo does this internally [Geoff Buesing] 
    24 
    35* TimeWithZone#usec returns 0 instead of error when DateTime is wrapped [Geoff Buesing] 
  • trunk/activesupport/lib/active_support/time_with_zone.rb

    r9105 r9106  
    1313    # Returns a Time or DateTime instance that represents the time in time_zone 
    1414    def time 
    15       @time ||= utc_to_local 
     15      @time ||= period.to_local(@utc) 
    1616    end 
    1717 
    1818    # Returns a Time or DateTime instance that represents the time in UTC 
    1919    def utc 
    20       @utc ||= local_to_utc 
     20      @utc ||= period.to_utc(@time) 
    2121    end 
    2222    alias_method :comparable_time, :utc 
     
    241241        ::Time.utc_time(time.year, time.month, time.day, time.hour, time.min, time.sec, time.respond_to?(:usec) ? time.usec : 0) 
    242242      end 
    243      
    244       # Replicating logic from TZInfo::Timezone#utc_to_local because we want to cache the period in an instance variable for reuse 
    245       def utc_to_local 
    246         ::TZInfo::TimeOrDateTime.wrap(utc) {|utc| period.to_local(utc)} 
    247       end 
    248        
    249       # Replicating logic from TZInfo::Timezone#local_to_utc because we want to cache the period in an instance variable for reuse 
    250       def local_to_utc 
    251         ::TZInfo::TimeOrDateTime.wrap(time) {|time| period.to_utc(time)} 
    252       end 
    253243  end 
    254244end 
  • trunk/activesupport/test/core_ext/time_with_zone_test.rb

    r9105 r9106  
    373373      end 
    374374    end 
     375     
     376    def test_utc_to_local_conversion_with_far_future_datetime 
     377      silence_warnings do # silence warnings raised by tzinfo gem 
     378        assert_equal [0,0,19,31,12,2049], ActiveSupport::TimeWithZone.new(DateTime.civil(2050), @time_zone).to_a[0,6] 
     379      end 
     380    end 
     381 
     382    def test_local_to_utc_conversion_with_far_future_datetime 
     383      silence_warnings do # silence warnings raised by tzinfo gem 
     384        assert_equal DateTime.civil(2050).to_f, ActiveSupport::TimeWithZone.new(nil, @time_zone, DateTime.civil(2049,12,31,19)).to_f 
     385      end 
     386    end 
    375387  end 
    376388