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 run fine. Time, year or timezone don't matter. >> 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. Use the example given above if you must you this string 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