Reputation: 4047
I'm passing a string to a Time.parse
but seeing very interesting behavior, see excerpt from console:
2.1.2 :011 > Time.parse("10/10/2014 7 am")
=> 2014-10-10 07:00:00 -0700
2.1.2 :010 > Time.parse("10/17/2014 7 am")
ArgumentError: argument out of range
What's the difference???
I'm always going to be parsing times that users input in the format of "MM/DD/YYYY H am/pm", so it's crucial that this doesn't break.
Upvotes: 1
Views: 1410
Reputation: 1454
Chronic gem is a useful tool for this and you can set the endian_presedence to do what you want.
Upvotes: 0
Reputation: 4047
Time.parse
takes a format of d/m/y, and I couldn't find a way in the docs to change this to m/d/y, so instead, I just changed the input format.
Upvotes: 2