On Sun, Nov 1, 2009 at 6:13 PM, Reid Thompson <reid.thompson / ateb.com> wrote:
> Jacob Gorban wrote:
>>
>> Seebs wrote:
>>>
>>> On 2009-11-01, Jacob Gorban <jacob.gorban / gmail.com> wrote:
>>>>
>>>> For some reason ruby 1.8.6 return invalid date exception when parsing a
>>>> date of Oct 31 (yesterday) in the format above. Oct 30 and most other
>>>> dates parses fine and  ¨Âõî æéîåÔéíåùåáò ïò ôéíåúïîå äïî§íáôôåò>>>
>>> It's suspiciously close to a range where you would be in a daylight
>>> savings crossover in at least one timezone, but unless that's it, I
>>> can't suggest anything.
>>>
>>> -s
>>
>> I don't know why this should matter. It's bug still.
>>
>> I've now figured out that an explicit
>> DateTime.strptime('17:26:33 Oct 31, 2009 PST', '%T %b %d, %Y %Z')
>> will work fine. But after running for several months with a code that ran
>> just fine I felt very unconfortable with this bug over a specific date.
>
> I don't think it's a bug -- I think it's being used wrong.
>
> Date.parse expects a date string, not a date time string.
> It also expects it to be formatted in a way that it understands.
> See the Docs.  ¨Âóå ôèåøáíðìçéöåáâïöéæ ùïíõóô ùïôèéó óôòéîç
> format.
>
> irb(main):008:0> puts Date.parse('Oct 31, 2009')
> 2009-10-31
> => nil
> irb(main):009:0> puts Date.parse('Oct 31 2009')
> 2009-10-31
> => nil
> irb(main):010:0> puts Date.parse('2009 Oct 31')
> 2009-10-31
> => nil
>
>
> Same with DateTime
> irb(main):005:0> puts DateTime.parse('17:26:33 Oct 30 2009')
> 2009-11-30T20:09:33+00:00
> => nil
> irb(main):006:0> puts DateTime.parse('17:26:33 2009 Oct 30')
> 2009-10-30T17:26:33+00:00
> => nil

I'm a bit curious why the first DateTime example seems to have
interpreted the date as NOVEMBER 30.

Also, Ruby 1.9's Date/DateTime parsing is much more picky about what
it understands.  For example it used to go to some lengths to use
heuristics to allow either US or international month day ordering, but
no longer.


-- 
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale