> I need to chage the way dates are input and displayed in my app. This
> is for a european app so the dates need to work as DD/MM/YYYY not the
> America way.
>
> Now I don't mind keeping the datbase in the orginal Date format as I
> won't be accessing it directly however I guess I need to wrtite
> something in my model to change the way the dates are done?
I use the DATE format in the database. I convert the format on input
and output.
Input from a form:
def convert_european_date(date)
# Authorize ISO date
return date unless (/^\d{4}-\d{2}-\d{2}$/).match(date).nil?
# Convert european date
match = /(\d{1,2}).(\d{1,2}).(\d{2,4})/.match(date)
begin
Date.new(match[3].to_i, match[2].to_i, match[1].to_i)
rescue
return false
end
end
Display:
<%= due_date.to_s(:european) %>
In initializers/date_formats.rb:
ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.merge!
(:european => '%d/%m/%Y')
ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.merge!
(:american => '%m/%d/%Y')
Christian
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---