diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 1a1cb9c275c0c390f45c0d368158b70c6ce866ae..69c2c0166a4bf06a6191e9fc3194f00ef78fdb7a 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Date, Time, and DateTime#to_json. #8399 [wycats] + * Simplify API of assert_difference by passing in an expression that is evaluated before and after the passed in block. See documenation for examples of new API. [Marcel Molina Jr.] * Added assert_difference and assert_no_difference to test/unit assertions [Tobias Luetke] diff --git a/activesupport/lib/active_support/json/encoders/date.rb b/activesupport/lib/active_support/json/encoders/date.rb new file mode 100644 index 0000000000000000000000000000000000000000..ee1a472f3fad8b4af0ab364c28197c3ad2ede618 --- /dev/null +++ b/activesupport/lib/active_support/json/encoders/date.rb @@ -0,0 +1,5 @@ +class Date + def to_json #:nodoc: + %("#{strftime("%m/%d/%Y")}") + end +end diff --git a/activesupport/lib/active_support/json/encoders/date_time.rb b/activesupport/lib/active_support/json/encoders/date_time.rb new file mode 100644 index 0000000000000000000000000000000000000000..28cb18977d5a3d035f5374fac8c87bd723673b35 --- /dev/null +++ b/activesupport/lib/active_support/json/encoders/date_time.rb @@ -0,0 +1,5 @@ +class DateTime + def to_json #:nodoc: + %("#{strftime("%m/%d/%Y %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 new file mode 100644 index 0000000000000000000000000000000000000000..080e9392f1443d74c45f0af98c2dc78e90ade375 --- /dev/null +++ b/activesupport/lib/active_support/json/encoders/time.rb @@ -0,0 +1,5 @@ +class Time + def to_json #:nodoc: + %("#{strftime("%m/%d/%Y %H:%M:%S %Z")}") + end +end diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index 149d11ce0f317ef9d67b7ce0fecc241077612e06..dbb96cb38ce455358295ba4b73882d834783676a 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -29,6 +29,10 @@ def initialize(a, b) [ 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), %("12/31/1969 16:00:00 #{Time.at(0).zone}") ]] + DateTimeTests = [[ Time.at(0), %("12/31/1969 16:00:00 #{Time.at(0).zone}") ]] + constants.grep(/Tests$/).each do |class_tests| define_method("test_#{class_tests[0..-6].downcase}") do self.class.const_get(class_tests).each do |pair|