aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/values
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2014-10-20 09:12:35 +0100
committerAndrew White <andyw@pixeltrix.co.uk>2015-04-22 12:12:39 -0400
commit3aa26cfb1903c770c5b561be5e64b97388ee84c7 (patch)
treef7d4cb81f4374fb2be6916c2d6d31e359cb2efae /activesupport/lib/active_support/values
parent5302d244eb2f81cba1bb0f1f6c8319464c467706 (diff)
downloadrails-3aa26cfb1903c770c5b561be5e64b97388ee84c7.tar.gz
rails-3aa26cfb1903c770c5b561be5e64b97388ee84c7.tar.bz2
rails-3aa26cfb1903c770c5b561be5e64b97388ee84c7.zip
Improve ActiveSupport::TimeWithZone conversion to YAML
Previously when converting AS::TimeWithZone to YAML it would be output as a UTC timestamp. Whilst this preserves the time information accurately it loses the timezone information. This commit changes that so that it is saved along with the time information. It also provides nicer encoding of AS::TimeZone instances themselves which previously embedded all of the data from the TZInfo records. Fixes #9183.
Diffstat (limited to 'activesupport/lib/active_support/values')
-rw-r--r--activesupport/lib/active_support/values/time_zone.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb
index 2b59c7a33d..2699a064d7 100644
--- a/activesupport/lib/active_support/values/time_zone.rb
+++ b/activesupport/lib/active_support/values/time_zone.rb
@@ -428,6 +428,15 @@ module ActiveSupport
tzinfo.periods_for_local(time)
end
+ def init_with(coder) #:nodoc:
+ initialize(coder['name'])
+ end
+
+ def encode_with(coder) #:nodoc:
+ coder.tag ="!ruby/object:#{self.class}"
+ coder.map = { 'name' => tzinfo.name }
+ end
+
private
def parts_to_time(parts, now)
return if parts.empty?