Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #6363: disable_default_date_format.diff

File disable_default_date_format.diff, 1.4 kB (added by olbrich, 2 years ago)

patch to remove date default formatting option

  • test/core_ext/date_ext_test.rb

    old new  
    1414  def test_to_date 
    1515    assert_equal Date.new(2005, 2, 21), Date.new(2005, 2, 21).to_date 
    1616  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 
    1724end 
  • lib/active_support/core_ext/date/conversions.rb

    old new  
    1313          klass.send(:alias_method, :to_s, :to_formatted_s) 
    1414        end 
    1515         
    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 
    1819        end 
    1920 
    2021        # To be able to keep Dates and Times interchangeable on conversions