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

Changeset 8975

Show
Ignore:
Timestamp:
03/03/08 03:49:37 (1 year ago)
Author:
gbuesing
Message:

Adding TimeWithZone #marshal_dump and #marshal_load

Files:

Legend:

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

    r8974 r8975  
    11*SVN* 
     2 
     3* Adding TimeWithZone #marshal_dump and #marshal_load [Geoff Buesing] 
    24 
    35* Add OrderedHash#to_hash [josh] 
  • trunk/activesupport/lib/active_support/time_with_zone.rb

    r8886 r8975  
    188188    def freeze 
    189189      self 
     190    end 
     191 
     192    def marshal_dump 
     193      [utc, time_zone.name, time] 
     194    end 
     195     
     196    def marshal_load(variables) 
     197      initialize(variables[0], ::TimeZone[variables[1]], variables[2]) 
    190198    end 
    191199   
  • trunk/activesupport/test/core_ext/time_with_zone_test.rb

    r8886 r8975  
    209209      assert_instance_of ActiveSupport::TimeWithZone, @twz.months_since(1) 
    210210      assert_equal Time.utc(2000, 1, 31, 19, 0 ,0), @twz.months_since(1).time 
     211    end 
     212     
     213    def test_marshal_dump_and_load 
     214      marshal_str = Marshal.dump(@twz) 
     215      mtime = Marshal.load(marshal_str) 
     216      assert_equal Time.utc(2000, 1, 1, 0), mtime.utc 
     217      assert_equal TimeZone['Eastern Time (US & Canada)'], mtime.time_zone 
     218      assert_equal Time.utc(1999, 12, 31, 19), mtime.time 
    211219    end 
    212220