albertopq / jquery_datepicker

Rails 3 plugin that allows you to select dates from a calendar
91 stars 60 forks source link

Handle non-US Date formats #19

Open cure opened 12 years ago

cure commented 12 years ago

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 commented 12 years ago

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 commented 12 years ago

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 commented 12 years ago

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 commented 12 years ago

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