# ParseDate in local format

**URL:** <https://www.ruby-forum.com/t/parsedate-in-local-format/99799>\
**Category:** Ruby\
**Created:** [July 25, 2006, 5:22pm UTC](https://www.ruby-forum.com/t/parsedate-in-local-format/99799 "2006-07-25T17:22:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josselin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de0a6/32.png) [@Josselin](https://www.ruby-forum.com/u/Josselin)\
**Post date:** [July 25, 2006, 5:22pm UTC](https://www.ruby-forum.com/t/parsedate-in-local-format/99799/1 "2006-07-25T17:22:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Josselin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de0a6/32.png) [@Josselin](https://www.ruby-forum.com/u/Josselin)\
**Post date:** [July 25, 2006, 6:29pm UTC](https://www.ruby-forum.com/t/parsedate-in-local-format/99799/2 "2006-07-25T18:29:50Z")

</div>

Josselin wrote:

> ```
> t = Time.local(v.compact*",") #=> Sun Jan 01 
> 
> ```
> 
> thanks
> 
> joss

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

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

---

<div class="post-metadata">

**Author:** ![Josselin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de0a6/32.png) [@Josselin](https://www.ruby-forum.com/u/Josselin)\
**Post date:** [July 26, 2006, 8:01am UTC](https://www.ruby-forum.com/t/parsedate-in-local-format/99799/3 "2006-07-26T08:01:27Z")

</div>

On 2006-07-25 18:26:52 +0200, Bojan M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) said:

> ```
> 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
