We defining our own date formats in our rails environment.rb - in order to format dates consistently across our app with 'some_date.to_formatted_s(:my_format)'. This is done by opening up the existing ActiveSupport class, and merging in your formats:
ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.merge!(
:in_words => "%A, %d %B %Y", # Add format - Monday, 01 January 2007
:short => '%d/%m/%Y' # Override :short to ozzy style dates
)
However, do NOT go overriding the :default format!
This one ALSO seems to be used for converting dates into SQL string-formatted dates.
MySql ended up receiving a blank string, and stored '0000-00-00' for all my dates... ...but no errors.
Not nice.

0 comments:
Post a Comment