1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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
This commit is contained in:
Jeremy Kemper 2007-10-05 09:43:24 +00:00
parent 335c15005d
commit 58a5eef53e
5 changed files with 8 additions and 6 deletions

View file

@ -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]

View file

@ -1,5 +1,5 @@
class Date
def to_json(options = nil) #:nodoc:
%("#{strftime("%m/%d/%Y")}")
%("#{strftime("%Y/%m/%d")}")
end
end

View file

@ -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

View file

@ -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

View file

@ -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