aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorLuca Guidi <guidi.luca@gmail.com>2008-08-27 11:25:20 +0200
committergbuesing <gbuesing@gmail.com>2008-08-27 08:57:36 -0500
commitce65a05c5b027175c3c541055081f82c8bfc36bf (patch)
tree007ffc3c93c7f7a0ed8f273f7980539397b2145e /activesupport/lib
parentb7cd4ded9350fff5edee2298dc04a55e6b285233 (diff)
downloadrails-ce65a05c5b027175c3c541055081f82c8bfc36bf.tar.gz
rails-ce65a05c5b027175c3c541055081f82c8bfc36bf.tar.bz2
rails-ce65a05c5b027175c3c541055081f82c8bfc36bf.zip
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]
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/core_ext/time.rb23
1 files changed, 22 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/time.rb b/activesupport/lib/active_support/core_ext/time.rb
index ea50511a96..2006cf4946 100644
--- a/activesupport/lib/active_support/core_ext/time.rb
+++ b/activesupport/lib/active_support/core_ext/time.rb
@@ -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 < '1.9'
+ class << 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'