European date format

hi, overhere users go nuts if they have to enter the date in iso format,
so i have to make my applications in such a way that not only dates are
displayed in the “dd-mm-yyy” format but also can be entered in that way.

somewhere i found this code to put in the environment script:

ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.update(
:default => ‘%d/%m/%Y @ %H:%M: %p’ )
ActiveSupport::CoreExtensions::date::Conversions::DATE_FORMATS.update(
:default => ‘%d/%m/%Y’ )

this works great for displaying dates, the only problem is i can’t input
a new date anymore:

i tried:

  • the date_select control => doesn’t work anymore
  • text_field with input ‘dd-mm-yyyy’ =>doesn’t work
  • text_field with input ‘yyyy-mm-dd’ =>doesn’t work either ???

How should i handle this? there must be a lot of developers facing
simular problems i guess

thanx remco

Remco Hh wrote:

simular problems i guess

thanx remco

Hi Remco, you can replace parsedate method so it would allow european
format, for example:

require (‘parsedate’)
module ParseDate
class << self
alias_method :old_parsedate, :parsedate unless
method_defined?(:old_parsedate)
end

def self.parsedate(str)
match = /(\d{1,2}).(\d{1,2}).(\d{2,4}).?/.match(str)
return ParseDate.old_parsedate(str) unless match
[match[3].to_i, match[2].to_i, match[1].to_i, nil, nil, nil, nil,
nil]
end
end


Bojan M.
Informatika Mihelac, Bojan M. s.p. | www.informatikamihelac.com
-> tools, scripts, tricks from our code lab: http://source.mihelac.org

Remco Hh escribió:

simular problems i guess

thanx remco

For display the dates I use a helper:

module ApplicationHelper
def eu_date(date)
return date.strftime("%d/%m/%Y") unless date.nil?
nil
end
end


LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y móviles desde 1 céntimo por minuto.
http://es.voice.yahoo.com

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs