Changeset 9106
- Timestamp:
- 03/28/08 02:10:36 (2 months ago)
- Files:
-
- trunk/activesupport/CHANGELOG (modified) (1 diff)
- trunk/activesupport/lib/active_support/time_with_zone.rb (modified) (2 diffs)
- trunk/activesupport/test/core_ext/time_with_zone_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/CHANGELOG
r9105 r9106 1 1 *SVN* 2 3 * TimeWithZone time conversions don't need to be wrapped in TimeOrDateTime, because TZInfo does this internally [Geoff Buesing] 2 4 3 5 * TimeWithZone#usec returns 0 instead of error when DateTime is wrapped [Geoff Buesing] trunk/activesupport/lib/active_support/time_with_zone.rb
r9105 r9106 13 13 # Returns a Time or DateTime instance that represents the time in time_zone 14 14 def time 15 @time ||= utc_to_local15 @time ||= period.to_local(@utc) 16 16 end 17 17 18 18 # Returns a Time or DateTime instance that represents the time in UTC 19 19 def utc 20 @utc ||= local_to_utc20 @utc ||= period.to_utc(@time) 21 21 end 22 22 alias_method :comparable_time, :utc … … 241 241 ::Time.utc_time(time.year, time.month, time.day, time.hour, time.min, time.sec, time.respond_to?(:usec) ? time.usec : 0) 242 242 end 243 244 # Replicating logic from TZInfo::Timezone#utc_to_local because we want to cache the period in an instance variable for reuse245 def utc_to_local246 ::TZInfo::TimeOrDateTime.wrap(utc) {|utc| period.to_local(utc)}247 end248 249 # Replicating logic from TZInfo::Timezone#local_to_utc because we want to cache the period in an instance variable for reuse250 def local_to_utc251 ::TZInfo::TimeOrDateTime.wrap(time) {|time| period.to_utc(time)}252 end253 243 end 254 244 end trunk/activesupport/test/core_ext/time_with_zone_test.rb
r9105 r9106 373 373 end 374 374 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 375 387 end 376 388