Skip to content

Instantly share code, notes, and snippets.

@linojon
Created August 10, 2011 17:43
Show Gist options
  • Save linojon/1137581 to your computer and use it in GitHub Desktop.
Save linojon/1137581 to your computer and use it in GitHub Desktop.
# Is this a bug in rails? time conversion to xml and json ends in Z not %Z ?
irb(main):018:0> t = Time.zone.now
=> Wed, 10 Aug 2011 17:38:45 UTC +00:00
irb(main):019:0> t.to_json
=> "\"2011-08-10T17:38:45Z\""
irb(main):020:0> t.xmlschema
=> "2011-08-10T17:38:45Z"
irb(main):021:0> t.strftime("%Y-%m-%dT%H:%M:%S%Z")
=> "2011-08-10T17:38:45UTC"
irb(main):024:0> t.strftime("%Y-%m-%dT%H:%M:%SZ")
=> "2011-08-10T17:38:45Z"
BUT...
http://api.rubyonrails.org/classes/DateTime.html#method-i-xmlschema
Converts datetime to an appropriate format for use in XML
[ show source ]
# File activesupport/lib/active_support/core_ext/date_time/conversions.rb, line 83
def xmlschema
strftime("%Y-%m-%dT%H:%M:%S%Z")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment