Skip to content

Commit

Permalink
TimeWithZone respects config.active_support.use_standard_json_time_fo…
Browse files Browse the repository at this point in the history
…rmat
  • Loading branch information
gbuesing committed Apr 12, 2008
1 parent cfd5688 commit 7e5aa65
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions activesupport/CHANGELOG
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
6 changes: 5 additions & 1 deletion activesupport/lib/active_support/time_with_zone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {})
Expand Down
7 changes: 7 additions & 0 deletions activesupport/test/core_ext/time_with_zone_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7e5aa65

Please sign in to comment.