Permalink
Browse files

TimeWithZone respects config.active_support.use_standard_json_time_fo…

…rmat
  • Loading branch information...
1 parent cfd5688 commit 7e5aa6569bc041238aafa5a400758c0a7536da93 @gbuesing gbuesing committed Apr 12, 2008
@@ -1,5 +1,7 @@
*SVN*
+* TimeWithZone respects config.active_support.use_standard_json_time_format [Geoff Buesing]
+
* Add config.active_support.escape_html_entities_in_json to allow disabling of html entity escaping. [rick]
* Improve documentation. [Xavier Noria]
@@ -77,7 +77,11 @@ def xmlschema
alias_method :iso8601, :xmlschema
def to_json(options = nil)
- %("#{time.strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)}")
+ if ActiveSupport.use_standard_json_time_format
+ utc.xmlschema.inspect
+ else
+ %("#{time.strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)}")
+ end
end
def to_yaml(options = {})
@@ -67,6 +67,13 @@ def test_to_json
assert_equal "\"1999/12/31 19:00:00 -0500\"", @twz.to_json
end
end
+
+ def test_to_json_with_use_standard_json_time_format_config_set_to_true
+ old, ActiveSupport.use_standard_json_time_format = ActiveSupport.use_standard_json_time_format, true
+ assert_equal "\"2000-01-01T00:00:00Z\"", @twz.to_json
+ ensure
+ ActiveSupport.use_standard_json_time_format = old
+ end
def test_strftime
silence_warnings do # silence warnings raised by tzinfo gem

0 comments on commit 7e5aa65

Please sign in to comment.