Extending Date/Time Formats in Rails 3
08/12/2011 15:28
Permalink
One of the many under-the-hood changes in Rails 3.x involves how date and time formats are extended. This is still done in an initializer, but the Rails classes have changed.
Here’s how it was done in Rails 2.x (for example):
# Rails 2.x # /config/initializers/date_formats.rb ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!( :teg_compact => "%m/%d/%Y %H:%M", :teg_long => "%d %B %Y - %H:%M", :teg_date => "%m/%d/%Y", :teg_label => "%d%B%Y-%H%M" )
And here’s how it’s done in Rails 3.x:
# Rails 3.x # /config/initializers/date_formats.rb Time::DATE_FORMATS.merge!( :teg_compact => "%m/%d/%Y %H:%M", :teg_long => "%d %B %Y - %H:%M", :teg_date => "%m/%d/%Y", :teg_label => "%d%B%Y-%H%M" )