Time.parse seems to fail

Hi,

it’s seems to me the function Time.parse has an error:

ok - Time.parse(“12/01/2008”) => 2008-12-01

Error - Time.parse(“01.12.2008”) => 2008-01-12

My brain does not seem to be working well today, I cannot actually see what you are getting at. What would you expect the second one to give and why?

Colin

> Hi,

> it's seems to me the function Time.parse has an error:

> ok - Time.parse("12/01/2008") => 2008-12-01
> Error - Time.parse("01.12.2008") => 2008-01-12

My brain does not seem to be working well today, I cannot actually see what
you are getting at. What would you expect the second one to give and why?

These things are ofter locale dependant. My european brain expects day
month year, but apparently in the US month ,day, year is more common.
If you are expecting dates in a particular format strptime is useful,
if not some sort of calendary widget is often a better idea.

Fred

Frederick Cheung wrote:

Frederick Cheung wrote:
> If you are expecting dates in a particular format strptime is useful,
> if not some sort of calendary widget is often a better idea.

> Fred

Well yes, I already do so (calendar_select_date), but I get in the
controller-function as params the dd.mm.yyyy format. So
update_attributes convert the date automaticly, but it do it wrong
(mm.dd.yyyy), therefor I "repair" the Date.parse-Function.

if you're guarenteed that the format you get in the controller is
going to be dd.mm.yyyy then strptime is probably the easiest way
(although just tearing the string up with a regexp wouldn't be hard
either)

Fred