aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgbuesing <gbuesing@gmail.com>2008-04-12 16:48:56 -0500
committergbuesing <gbuesing@gmail.com>2008-04-12 16:48:56 -0500
commit7e5aa6569bc041238aafa5a400758c0a7536da93 (patch)
treedc45337259d7f44f3b91fa9a7625242b35bf133e
parentcfd56882af597724e427b17cdf295ffdd241dc26 (diff)
downloadrails-7e5aa6569bc041238aafa5a400758c0a7536da93.tar.gz
rails-7e5aa6569bc041238aafa5a400758c0a7536da93.tar.bz2
rails-7e5aa6569bc041238aafa5a400758c0a7536da93.zip
TimeWithZone respects config.active_support.use_standard_json_time_format
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/time_with_zone.rb6
-rw-r--r--activesupport/test/core_ext/time_with_zone_test.rb7
3 files changed, 14 insertions, 1 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index d0d0433883..0627c89c53 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -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]
diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb
index b91480cd48..1c984f07d4 100644
--- a/activesupport/lib/active_support/time_with_zone.rb
+++ b/activesupport/lib/active_support/time_with_zone.rb
@@ -77,7 +77,11 @@ module ActiveSupport
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 = {})
diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb
index 5cebfae583..efab8a24c8 100644
--- a/activesupport/test/core_ext/time_with_zone_test.rb
+++ b/activesupport/test/core_ext/time_with_zone_test.rb
@@ -67,6 +67,13 @@ class TimeWithZoneTest < Test::Unit::TestCase
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