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

Changeset 8710

Show
Ignore:
Timestamp:
01/23/08 20:49:53 (8 months ago)
Author:
gbuesing
Message:

TimeZone#now returns an ActiveSupport::TimeWithZone

Files:

Legend:

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

    r8708 r8710  
    11*SVN* 
     2 
     3* TimeZone#now returns an ActiveSupport::TimeWithZone [Geoff Buesing] 
    24 
    35* Time #in_current_time_zone and #change_time_zone_to_current return self when Time.zone is nil [Geoff Buesing] 
  • trunk/activesupport/lib/active_support/values/time_zone.rb

    r8697 r8710  
    178178    require_library_or_gem "tzinfo" unless Object.const_defined?(:TZInfo) 
    179179     
    180     # Compute and return the current time, in the time zone represented by 
    181     # +self+. 
     180    # Returns an ActiveSupport::TimeWithZone instance representing the current time 
     181    # in the time zone represented by +self+. Example: 
     182    # 
     183    #   Time.zone = 'Hawaii'  # => "Hawaii" 
     184    #   Time.zone.now         # => Wed, 23 Jan 2008 20:24:27 HST -10:00 
    182185    def now 
    183       tzinfo.now 
     186      tzinfo.now.change_time_zone(self) 
    184187    end 
    185188 
    186189    # Return the current date in this time zone. 
    187190    def today 
    188       now.to_date 
    189     end 
    190  
    191     # Adjust the given time to the time zone represented by +self+. 
     191      tzinfo.now.to_date 
     192    end 
     193 
     194    # Adjust the given time to the simultaneous time in the time zone represented by +self+. Returns a  
     195    # Time.utc() instance -- if you want an ActiveSupport::TimeWithZone instance, use Time#in_time_zone() instead. 
    192196    def utc_to_local(time) 
    193197      tzinfo.utc_to_local(time) 
    194198    end 
    195  
     199     
     200    # Adjust the given time to the simultaneous time in UTC. Returns a Time.utc() instance. 
    196201    def local_to_utc(time, dst=true) 
    197202      tzinfo.local_to_utc(time, dst) 
  • trunk/activesupport/test/time_zone_test.rb

    r8697 r8710  
    5656      def test_now 
    5757        TZInfo::DataTimezone.any_instance.stubs(:now).returns(Time.utc(2000)) 
    58         assert_equal Time.utc(2000), TimeZone['Eastern Time (US & Canada)'].now 
     58        zone = TimeZone['Eastern Time (US & Canada)'] 
     59        assert_instance_of ActiveSupport::TimeWithZone, zone.now 
     60        assert_equal Time.utc(2000), zone.now.time 
     61        assert_equal zone, zone.now.time_zone 
    5962      end 
    6063