diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 5c0e06240319e3c239a3d70c29066e50c9108b29..df9474bb3f92bf8ab93e8913418b01c06691f723 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,8 @@ *SVN* +* :db format for Date#to_s [Jeremy Kemper] + Date.new(2007, 1, 27).to_s(:db) # => '2007-01-27' + * Added :instance_writer option to #mattr_writer/accessor, #cattr_writer/accessor, and #class_inheritable_writer to skip the creation of the instance writer. [Rick] * Added Hash#to_query to turn a hash of values into a form-encoded query string [Nicholas Seckar] diff --git a/activesupport/lib/active_support/core_ext/date/conversions.rb b/activesupport/lib/active_support/core_ext/date/conversions.rb index 4b9388dacd6ea020f1672f7d7b7b298d6d2b0c48..8f48ccacdea6d99d5e50da183ea6667d8cddcc8f 100644 --- a/activesupport/lib/active_support/core_ext/date/conversions.rb +++ b/activesupport/lib/active_support/core_ext/date/conversions.rb @@ -5,7 +5,8 @@ module Date #:nodoc: module Conversions DATE_FORMATS = { :short => "%e %b", - :long => "%B %e, %Y" + :long => "%B %e, %Y", + :db => "%Y-%m-%d" } def self.included(klass) #:nodoc: diff --git a/activesupport/test/core_ext/date_ext_test.rb b/activesupport/test/core_ext/date_ext_test.rb index 56161954a067a8e7a13a528a04df9a499d32aec1..055b3659fd4c865472c24c2a3bdc3f244403f8d2 100644 --- a/activesupport/test/core_ext/date_ext_test.rb +++ b/activesupport/test/core_ext/date_ext_test.rb @@ -4,6 +4,7 @@ class DateExtCalculationsTest < Test::Unit::TestCase def test_to_s assert_equal "21 Feb", Date.new(2005, 2, 21).to_s(:short) assert_equal "February 21, 2005", Date.new(2005, 2, 21).to_s(:long) + assert_equal "2005-02-21", Date.new(2005, 2, 21).to_s(:db) end def test_to_time