Parse only seem to understand US date format

I’ve tried Time.parse() and DateTime.parse() but they interpret the date
as US format. Is there any way to tell it to interpret as dd/mm/yyyy?

Try my plugin:

http://svn.viney.net.nz/things/rails/plugins/validates_date_time

-Jonathan.

Jonathan V. wrote:

Try my plugin:

http://svn.viney.net.nz/things/rails/plugins/validates_date_time

-Jonathan.

Thanks, I’ll give it a go. Just have to figure out how to use plug-ins
(newbie here)

Have a look at the Rails wiki and the readme

http://svn.viney.net.nz/things/rails/plugins/validates_date_time/README

-Jonathan.

Mark Horgan wrote:

I’ve tried Time.parse() and DateTime.parse() but they interpret the date
as US format. Is there any way to tell it to interpret as dd/mm/yyyy?

You can easily override ParseDate to handle other formats, I did that
for euro format dd.mm.yyyy.

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

hope this helps you.
Bojan M.


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