Changeset 8710
- Timestamp:
- 01/23/08 20:49:53 (8 months ago)
- Files:
-
- trunk/activesupport/CHANGELOG (modified) (1 diff)
- trunk/activesupport/lib/active_support/values/time_zone.rb (modified) (1 diff)
- trunk/activesupport/test/time_zone_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/CHANGELOG
r8708 r8710 1 1 *SVN* 2 3 * TimeZone#now returns an ActiveSupport::TimeWithZone [Geoff Buesing] 2 4 3 5 * 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 178 178 require_library_or_gem "tzinfo" unless Object.const_defined?(:TZInfo) 179 179 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 182 185 def now 183 tzinfo.now 186 tzinfo.now.change_time_zone(self) 184 187 end 185 188 186 189 # Return the current date in this time zone. 187 190 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. 192 196 def utc_to_local(time) 193 197 tzinfo.utc_to_local(time) 194 198 end 195 199 200 # Adjust the given time to the simultaneous time in UTC. Returns a Time.utc() instance. 196 201 def local_to_utc(time, dst=true) 197 202 tzinfo.local_to_utc(time, dst) trunk/activesupport/test/time_zone_test.rb
r8697 r8710 56 56 def test_now 57 57 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 59 62 end 60 63