Skip to content

Handle non-US Date formats#19

Open
cure wants to merge 1 commit intoalbertopq:masterfrom
cure:master
Open

Handle non-US Date formats#19
cure wants to merge 1 commit intoalbertopq:masterfrom
cure:master

Conversation

@cure
Copy link

@cure cure commented Apr 30, 2012

Stop using Date.parse. it does not support d/m/Y format on Ruby 1.8.x, and it does not support m/d/Y format on Ruby 1.9.

Cf.

https://bugs.ruby-lang.org/issues/634

albertopq added a commit that referenced this pull request May 1, 2012
@albertopq
Copy link
Owner

Hi @cure!

First of all, thanks for your contribution!
I tried to add some tests with the format you said isn't supported, and they are passing in both 1.8 and 1.9... at the other hand, I ran the tests on your fork, and strptime fails with 'dd M yy' format ('%d %b %Y' in ruby).

Could you check it out again and help me to find which specific format is failing to you?

Thanks!

@cure
Copy link
Author

cure commented May 5, 2012

Hi @albertopq, thanks for looking into this.

The tests will only fail when the date you feed in (in d/m/Y format) does not also work as m/d/Y. So, 3/1/2012 will work (because it is valid in both formats - though the translation will of course be wrong in one case), but 31/1/2012 will fail.

Specifically, d/m/Y is failing for me with Date.parse (but only if d is > 12, of course). I have my rails app set to d/m/Y by adding these to an initializer:

Time::DATE_FORMATS[:default] = '%d/%m/%Y %H:%M:%S'
Date::DATE_FORMATS[:default] = '%d/%m/%Y'

Thanks,
Ward.

@DSalko
Copy link

DSalko commented Jun 22, 2012

Hi.

I have the same issue I think. Rails 1.9.3 and default format is %m/%d/%Y
Datepicker works, but when I try to update model using update_attributes - the field left blank. Anyone else have the same problem? I found out that Date.parse causes Invalid Date and that's the reason of the problem.

Thanks!

@mzaragoza
Copy link

i have 2 dates on my page

= f.datepicker 'start_date', {:class => 'datepicker medium-label-1 input small-margin-right', :title=>t(:dates)}
= f.datepicker 'end_date', {:class => 'datepicker medium-label-1 input small-margin-right', :title=>t(:dates)}

the first one passes as it has some data but the second one says that there is no data. '

and when i do get it to pass the format is wrong. how do i change the format of the field

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants