diff options
author | Andrew White <pixeltrix@users.noreply.github.com> | 2015-04-22 13:39:02 -0400 |
---|---|---|
committer | Andrew White <pixeltrix@users.noreply.github.com> | 2015-04-22 13:39:02 -0400 |
commit | 3ab66a0ce4c181be7fbf4c23c37a147b1331d6a3 (patch) | |
tree | 3d018da9020361258f15bf9cbf1340c13f2d885f /activesupport/lib | |
parent | 68a033ea5fac99f96a63de583552764a93c7d88c (diff) | |
parent | 3aa26cfb1903c770c5b561be5e64b97388ee84c7 (diff) | |
download | rails-3ab66a0ce4c181be7fbf4c23c37a147b1331d6a3.tar.gz rails-3ab66a0ce4c181be7fbf4c23c37a147b1331d6a3.tar.bz2 rails-3ab66a0ce4c181be7fbf4c23c37a147b1331d6a3.zip |
Merge pull request #17333 from rails/encode-twz-tzinfo-in-yaml
Improve ActiveSupport::TimeWithZone conversion to YAML
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/time_with_zone.rb | 13 | ||||
-rw-r--r-- | activesupport/lib/active_support/values/time_zone.rb | 9 |
2 files changed, 16 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index c28de4e21c..b0d7f3299f 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -169,12 +169,13 @@ module ActiveSupport end end - def encode_with(coder) - if coder.respond_to?(:represent_object) - coder.represent_object(nil, utc) - else - coder.represent_scalar(nil, utc.strftime("%Y-%m-%d %H:%M:%S.%9NZ")) - end + def init_with(coder) #:nodoc: + initialize(coder['utc'], coder['zone'], coder['time']) + end + + def encode_with(coder) #:nodoc: + coder.tag = '!ruby/object:ActiveSupport::TimeWithZone' + coder.map = { 'utc' => utc, 'zone' => time_zone, 'time' => time } end # Returns a string of the object's date and time in the format used by 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? |