ParseDate in local format...

J

Josselin

when a user choose a date from my datepicker calendar, an european
local startdate is displayed in the text field : 30/7/2006, fine !

As I must add 10 days to this starting date to 'ajax-modify' the ending date,
I wrote the following method :

def startdateChanged
v = ParseDate::parsedate(@params["startdate"]) #=>
[2006, 30, 7, nil, nil, nil, nil, nil]
t = Time.local(v.compact*",") #=> Sun Jan 01
00:00:00 CET 2006 which is wrong
@enddate = (t+(84600*10)).strftime("%d/%m/%Y")
render:)partial => "enddate")
end

the Time.local() is expected [2006, 7, 30, nil, nil, nil, nil, nil]

is there any way to parse the date according to a 'locale' (fr_FR in
this case)

thanks

joss
 
B

Bojan Mihelac

Josselin said:
when a user choose a date from my datepicker calendar, an european local
startdate is displayed in the text field : 30/7/2006, fine !

As I must add 10 days to this starting date to 'ajax-modify' the
ending date,
I wrote the following method :

def startdateChanged
v = ParseDate::parsedate(@params["startdate"]) #=>
[2006, 30, 7, nil, nil, nil, nil, nil]
t = Time.local(v.compact*",") #=> Sun Jan 01
00:00:00 CET 2006 which is wrong
@enddate = (t+(84600*10)).strftime("%d/%m/%Y")
render:)partial => "enddate")
end

the Time.local() is expected [2006, 7, 30, nil, nil, nil, nil, nil]

is there any way to parse the date according to a 'locale' (fr_FR in
this case)

thanks

joss
Here is how I do it to parse mm.dd.yyyy. dates:

require ('parsedate')
module ParseDate
class << self
alias_method :eek:ld_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
 
J

Josselin

Here is how I do it to parse mm.dd.yyyy. dates:

require ('parsedate')
module ParseDate
class << self
alias_method :eek:ld_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

thanks a lot...
as always .....one vision of the world = one vision of the time = one
vision of the date
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top