diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-10-05 09:43:24 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-10-05 09:43:24 +0000 |
commit | 58a5eef53eee7768d68cc034a1563914d21a68cb (patch) | |
tree | e2e6dc48d8d5359acb72629e8ed805609c370345 /activesupport | |
parent | 335c15005db47afe429d2ee27102dd646e3d43f6 (diff) | |
download | rails-58a5eef53eee7768d68cc034a1563914d21a68cb.tar.gz rails-58a5eef53eee7768d68cc034a1563914d21a68cb.tar.bz2 rails-58a5eef53eee7768d68cc034a1563914d21a68cb.zip |
Disambiguate Time, Date, and DateTime#to_json formatting. Closes #9750.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7746 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/CHANGELOG | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/json/encoders/date.rb | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/json/encoders/date_time.rb | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/json/encoders/time.rb | 2 | ||||
-rw-r--r-- | activesupport/test/json/encoding_test.rb | 6 |
5 files changed, 8 insertions, 6 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index e621ee2f44..95e5c6b25a 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Disambiguate Time, Date, and DateTime#to_json formatting. #9750 [Geoff Buesing, Chu Yeow] + * Hash#to_json takes :only or :except options to specific or omit certain hash keys. Enumerable#to_json passes through its options to each element. #9751 [Chu Yeow] * BufferedLogger#auto_flushing = N flushes the log every N messages. Buffers with an array instead of string. Disabling auto_flushing still flushes when the buffer hits a maximum size, as a failsafe against memory-gobbling. [Jeremy Kemper] diff --git a/activesupport/lib/active_support/json/encoders/date.rb b/activesupport/lib/active_support/json/encoders/date.rb index de59e1b338..853d9b868c 100644 --- a/activesupport/lib/active_support/json/encoders/date.rb +++ b/activesupport/lib/active_support/json/encoders/date.rb @@ -1,5 +1,5 @@ class Date def to_json(options = nil) #:nodoc: - %("#{strftime("%m/%d/%Y")}") + %("#{strftime("%Y/%m/%d")}") end end diff --git a/activesupport/lib/active_support/json/encoders/date_time.rb b/activesupport/lib/active_support/json/encoders/date_time.rb index 229cefc007..f0b0434412 100644 --- a/activesupport/lib/active_support/json/encoders/date_time.rb +++ b/activesupport/lib/active_support/json/encoders/date_time.rb @@ -1,5 +1,5 @@ class DateTime def to_json(options = nil) #:nodoc: - %("#{strftime("%m/%d/%Y %H:%M:%S %Z")}") + %("#{strftime("%Y/%m/%d %H:%M:%S %z")}") end end diff --git a/activesupport/lib/active_support/json/encoders/time.rb b/activesupport/lib/active_support/json/encoders/time.rb index b9b52be9ed..8eb9ff132e 100644 --- a/activesupport/lib/active_support/json/encoders/time.rb +++ b/activesupport/lib/active_support/json/encoders/time.rb @@ -1,5 +1,5 @@ class Time def to_json(options = nil) #:nodoc: - %("#{strftime("%m/%d/%Y %H:%M:%S %Z")}") + to_datetime.to_json(options) end end diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index dee5b928d3..c42832b371 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -29,9 +29,9 @@ class TestJSONEncoding < Test::Unit::TestCase [ ActiveSupport::JSON::Variable.new('alert("foo")'), 'alert("foo")']] RegexpTests = [[ /^a/, '/^a/' ], [/^\w{1,2}[a-z]+/ix, '/^\\w{1,2}[a-z]+/ix']] - DateTests = [[ Date.new(2005,1,1), %("01/01/2005") ]] - TimeTests = [[ Time.at(0), %("#{Time.at(0).strftime('%m/%d/%Y %H:%M:%S %Z')}") ]] - DateTimeTests = [[ DateTime.new(0), %("#{DateTime.new(0).strftime('%m/%d/%Y %H:%M:%S %Z')}") ]] + DateTests = [[ Date.new(2005,2,1), %("2005/02/01") ]] + TimeTests = [[ Time.utc(2005,2,1,15,15,10), %("2005/02/01 15:15:10 +0000") ]] + DateTimeTests = [[ DateTime.civil(2005,2,1,15,15,10), %("2005/02/01 15:15:10 +0000") ]] constants.grep(/Tests$/).each do |class_tests| define_method("test_#{class_tests[0..-6].downcase}") do |