<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,5 +1,7 @@
 *2.1.1 (next release)*
 
+* Fix Ruby's Time marshaling bug in pre-1.9 versions of Ruby: utc instances are now correctly unmarshaled with a utc zone instead of the system local zone [#900 state:resolved]:activesupport/CHANGELOG
+
 * TimeWithZone: when crossing DST boundary, treat Durations of days, months or years as variable-length, and all other values as absolute length. A time + 24.hours will advance exactly 24 hours, but a time + 1.day will advance 23-25 hours, depending on the day. Ensure consistent behavior across all advancing methods [Geoff Buesing]
 
 * Fix TimeWithZone unmarshaling: coerce unmarshaled Time instances to utc, because Ruby's marshaling of Time instances doesn't respect the zone [Geoff Buesing]</diff>
      <filename>activesupport/CHANGELOG</filename>
    </modified>
    <modified>
      <diff>@@ -1,11 +1,32 @@
 require 'date'
 require 'time'
 
-# Ruby 1.8-cvs and 1.9 define private Time#to_date
 class Time
+  # Ruby 1.8-cvs and 1.9 define private Time#to_date
   %w(to_date to_datetime).each do |method|
     public method if private_instance_methods.include?(method)
   end
+
+  # Pre-1.9 versions of Ruby have a bug with marshaling Time instances, where utc instances are
+  # unmarshaled in the local zone, instead of utc. We're layering behavior on the _dump and _load
+  # methods so that utc instances can be flagged on dump, and coerced back to utc on load.
+  if RUBY_VERSION &lt; '1.9'
+    class &lt;&lt; self
+      alias_method :_original_load, :_load
+      def _load(marshaled_time)
+        time = _original_load(marshaled_time)
+        utc = time.send(:remove_instance_variable, '@marshal_with_utc_coercion')
+        utc ? time.utc : time
+      end
+    end
+    
+    alias_method :_original_dump, :_dump
+    def _dump(*args)
+      obj = self.frozen? ? self.dup : self
+      obj.instance_variable_set('@marshal_with_utc_coercion', utc?)
+      obj._original_dump(*args)
+    end
+  end
 end
 
 require 'active_support/core_ext/time/behavior'</diff>
      <filename>activesupport/lib/active_support/core_ext/time.rb</filename>
    </modified>
    <modified>
      <diff>@@ -620,3 +620,37 @@ class TimeExtCalculationsTest &lt; Test::Unit::TestCase
       old_tz ? ENV['TZ'] = old_tz : ENV.delete('TZ')
     end
 end
+
+class TimeExtMarshalingTest &lt; Test::Unit::TestCase
+  def test_marshaling_with_utc_instance
+    t = Time.utc(2000)
+    marshaled = Marshal.dump t
+    unmarshaled = Marshal.load marshaled
+    assert_equal t, unmarshaled
+    assert_equal t.zone, unmarshaled.zone
+  end
+  
+  def test_marshaling_with_local_instance  
+    t = Time.local(2000)
+    marshaled = Marshal.dump t
+    unmarshaled = Marshal.load marshaled
+    assert_equal t, unmarshaled
+    assert_equal t.zone, unmarshaled.zone
+  end
+    
+  def test_marshaling_with_frozen_utc_instance  
+    t = Time.utc(2000).freeze
+    marshaled = Marshal.dump t
+    unmarshaled = Marshal.load marshaled
+    assert_equal t, unmarshaled
+    assert_equal t.zone, unmarshaled.zone
+  end
+  
+  def test_marshaling_with_frozen_local_instance  
+    t = Time.local(2000).freeze
+    marshaled = Marshal.dump t
+    unmarshaled = Marshal.load marshaled
+    assert_equal t, unmarshaled
+    assert_equal t.zone, unmarshaled.zone
+  end
+end</diff>
      <filename>activesupport/test/core_ext/time_ext_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>e710902f26a2eed7adb22082067df449b9641d00</id>
    </parent>
  </parents>
  <author>
    <name>Luca Guidi</name>
    <email>guidi.luca@gmail.com</email>
  </author>
  <url>http://github.com/rails/rails/commit/4d71e99d1fc1f57900288e008d7528c339138cf0</url>
  <id>4d71e99d1fc1f57900288e008d7528c339138cf0</id>
  <committed-date>2008-08-27T07:12:24-07:00</committed-date>
  <authored-date>2008-08-27T02:25:20-07:00</authored-date>
  <message>Fix Ruby's Time marshaling bug in pre-1.9 versions of Ruby: utc instances are now correctly unmarshaled with a utc zone instead of the system local zone [#900 state:resolved]</message>
  <tree>2e29eb4eec3bae3dae3971dbc3c67e8488f01146</tree>
  <committer>
    <name>gbuesing</name>
    <email>gbuesing@gmail.com</email>
  </committer>
</commit>
