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? -- Posted via http://www.ruby-forum.com/.
Try my plugin: http://svn.viney.net.nz/things/rails/plugins/validates_date_time -Jonathan. On 6/16/06, Mark Horgan <public@markhorgan.com> 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? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Mark Horgan
2006-Jun-15 22:50 UTC
[Rails] Re: parse only seem to understand US date format
Jonathan Viney 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) -- Posted via http://www.ruby-forum.com/.
Jonathan Viney
2006-Jun-16 01:24 UTC
[Rails] Re: parse only seem to understand US date format
Have a look at the Rails wiki and the readme http://svn.viney.net.nz/things/rails/plugins/validates_date_time/README -Jonathan. On 6/16/06, Mark Horgan <public@markhorgan.com> wrote:> Jonathan Viney 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) > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
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 Mihelac -- Bojan Mihelac Informatika Mihelac, Bojan Mihelac s.p. | www.informatikamihelac.com -> tools, scripts, tricks from our code lab: http://source.mihelac.org