Skip to content
This repository
Browse code

Use xmlschema when serializing TimeWithZones to xml [#2223 state:reso…

…lved]

When using Hash#to_xml, any TimeWithZone objects now use xmlschema (iso8601), rather than a simple TimeWithZone#to_s.

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information...
commit 923067810480c93817dbae3d8295a18aa2a2ec3a 1 parent d771e7d
authored March 12, 2009 lifo committed March 12, 2009
5  activesupport/lib/active_support/core_ext/hash/conversions.rb
@@ -24,11 +24,12 @@ def content_type
24 24
           "Bignum"     => "integer",
25 25
           "BigDecimal" => "decimal",
26 26
           "Float"      => "float",
  27
+          "TrueClass"  => "boolean",
  28
+          "FalseClass" => "boolean",
27 29
           "Date"       => "date",
28 30
           "DateTime"   => "datetime",
29 31
           "Time"       => "datetime",
30  
-          "TrueClass"  => "boolean",
31  
-          "FalseClass" => "boolean"
  32
+          "ActiveSupport::TimeWithZone" => "datetime"
32 33
         } unless defined?(XML_TYPE_NAMES)
33 34
 
34 35
         XML_FORMATTING = {
9  activesupport/test/core_ext/hash_ext_test.rb
@@ -497,6 +497,15 @@ def test_three_levels_with_array
497 497
     assert xml.include?(%(<addresses type="array"><address><streets type="array"><street><name>))
498 498
   end
499 499
 
  500
+  def test_timezoned_attributes
  501
+    xml = {
  502
+      :created_at => Time.utc(1999,2,2),
  503
+      :local_created_at => Time.utc(1999,2,2).in_time_zone('Eastern Time (US & Canada)')
  504
+    }.to_xml(@xml_options)
  505
+    assert_match %r{<created-at type=\"datetime\">1999-02-02T00:00:00Z</created-at>}, xml
  506
+    assert_match %r{<local-created-at type=\"datetime\">1999-02-01T19:00:00-05:00</local-created-at>}, xml
  507
+  end
  508
+
500 509
   def test_single_record_from_xml
501 510
     topic_xml = <<-EOT
502 511
       <topic>

0 notes on commit 9230678

Please sign in to comment.
Something went wrong with that request. Please try again.