Ticket #10058: tz_time_fix.diff
| File tz_time_fix.diff, 1.8 kB (added by toolmantim, 10 months ago) |
|---|
-
test/active_record_methods_test.rb
old new 27 27 end 28 28 29 29 def test_should_access_utc_time_as_local_with_getter_method 30 @record. due_on = Time.utc(2006, 1, 1)30 @record.instance_variable_set(:@due_on, Time.utc(2006, 1, 1)) 31 31 assert_equal @record.due_on, TzTime.local(2005, 12, 31, 18) 32 32 end 33 33 34 34 def test_should_fix_timezones 35 35 @record.due_on = Time.utc(2006, 1, 1) 36 @record.send :fix_timezone37 36 assert_equal @record.due_on, TzTime.local(2006, 1, 1) 38 37 end 38 39 def test_should_only_fix_timezones_that_have_been_written 40 @record.instance_variable_set(:@due_on, Time.utc(2006, 1, 1)) 41 assert_equal TzTime.utc(2006, 1, 1), @record.due_on 42 end 39 43 end 40 44 end -
lib/tz_time_helpers/active_record_methods.rb
old new 18 18 time 19 19 end 20 20 end 21 end 22 23 protected 24 def fix_timezone 25 tz_time_attributes.each do |attribute| 26 time = read_attribute(attribute) 27 fixed = (time.acts_like?(:time) || time.acts_like?(:date)) ? TzTime.at(time) : nil 28 write_attribute(attribute, fixed) 29 end 21 define_method "#{attribute}=" do |local_time| 22 fixed = (local_time.acts_like?(:time) || local_time.acts_like?(:date)) ? TzTime.at(local_time) : nil 23 write_attribute(attribute, fixed) 30 24 end 25 end 31 26 end 32 before_validation :fix_timezone33 27 end 34 28 end 35 29 end