diff options
author | Geoff Buesing <gbuesing@gmail.com> | 2008-03-03 03:49:37 +0000 |
---|---|---|
committer | Geoff Buesing <gbuesing@gmail.com> | 2008-03-03 03:49:37 +0000 |
commit | 10d9d0b6fe023df1be0d87ca95bb739bb7eb30ba (patch) | |
tree | 96fc1067957c805d60ea411f2f8af9fa070e8690 | |
parent | 42d1172c2d8739ea1f4fd28ab85f97883e79190b (diff) | |
download | rails-10d9d0b6fe023df1be0d87ca95bb739bb7eb30ba.tar.gz rails-10d9d0b6fe023df1be0d87ca95bb739bb7eb30ba.tar.bz2 rails-10d9d0b6fe023df1be0d87ca95bb739bb7eb30ba.zip |
Adding TimeWithZone #marshal_dump and #marshal_load
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8975 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r-- | activesupport/CHANGELOG | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/time_with_zone.rb | 8 | ||||
-rw-r--r-- | activesupport/test/core_ext/time_with_zone_test.rb | 8 |
3 files changed, 18 insertions, 0 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index de13f03310..a4dfd5c11b 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Adding TimeWithZone #marshal_dump and #marshal_load [Geoff Buesing] + * Add OrderedHash#to_hash [josh] * Adding Time#end_of_day, _quarter, _week, and _year. #9312 [Juanjo Bazan, Tarmo Tänav, BigTitus] diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index cd4ea8c532..c6fa118b55 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -188,6 +188,14 @@ module ActiveSupport def freeze self end + + def marshal_dump + [utc, time_zone.name, time] + end + + def marshal_load(variables) + initialize(variables[0], ::TimeZone[variables[1]], variables[2]) + end # Ensure proxy class responds to all methods that underlying time instance responds to def respond_to?(sym) diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index c93d6157e7..c7b71f4ffe 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -209,6 +209,14 @@ uses_tzinfo 'TimeWithZoneTest' do assert_instance_of ActiveSupport::TimeWithZone, @twz.months_since(1) assert_equal Time.utc(2000, 1, 31, 19, 0 ,0), @twz.months_since(1).time end + + def test_marshal_dump_and_load + marshal_str = Marshal.dump(@twz) + mtime = Marshal.load(marshal_str) + assert_equal Time.utc(2000, 1, 1, 0), mtime.utc + assert_equal TimeZone['Eastern Time (US & Canada)'], mtime.time_zone + assert_equal Time.utc(1999, 12, 31, 19), mtime.time + end def test_method_missing_with_non_time_return_value assert_equal 1999, @twz.year |