Ticket #6363: disable_default_date_format.diff
| File disable_default_date_format.diff, 1.4 kB (added by olbrich, 2 years ago) |
|---|
-
test/core_ext/date_ext_test.rb
old new 14 14 def test_to_date 15 15 assert_equal Date.new(2005, 2, 21), Date.new(2005, 2, 21).to_date 16 16 end 17 18 def test_to_s_with_changed_default 19 ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.update( :default => '%m-%d-%Y' ) 20 ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.update( nil => '%m-%d-%Y' ) 21 assert_equal '10-08-2006', Date.new(2006,10,8).to_s(:default) 22 assert_equal '2006-10-08', Date.new(2006,10,8).to_s 23 end 17 24 end -
lib/active_support/core_ext/date/conversions.rb
old new 13 13 klass.send(:alias_method, :to_s, :to_formatted_s) 14 14 end 15 15 16 def to_formatted_s(format = :default) 17 DATE_FORMATS[format] ? strftime(DATE_FORMATS[format]).strip : to_default_s 16 def to_formatted_s(format = nil) 17 return to_default_s unless format 18 strftime(DATE_FORMATS[format]).strip rescue to_default_s 18 19 end 19 20 20 21 # To be able to keep Dates and Times interchangeable on conversions