On Mon, 2009-11-02 at 08:23 +0900, Rick DeNatale wrote: > > 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 > > 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. > > Because it doesn't understand the order of the portions of the input string $ irb irb(main):016:0> puts DateTime.parse('Oct 30 2009 17:26:33') 2009-10-30T17:26:33+00:00 => nil versus irb(main):001:0> puts DateTime.parse('17:26:33 Oct 30 2009') 2009-11-30T20:09:33+00:00 => nil irb(main):002:0> puts DateTime.parse('17:26:33 Oct 30 2009') 2009-11-30T20:09:33+00:00 => nil irb(main):003:0> puts DateTime.parse('17:26:33 Nov 30 2009') 2009-11-30T20:09:33+00:00 => nil irb(main):004:0> puts DateTime.parse('17:26:33 Dec 30 2009') 2009-11-30T20:09:33+00:00 => nil irb(main):005:0> puts DateTime.parse('17:26:33 Jan 30 2009') 2009-11-30T20:09:33+00:00 => nil irb(main):006:0> puts DateTime.parse('17:26:33 Jan 10 2009') 2009-11-10T20:09:33+00:00 => nil irb(main):007:0> puts DateTime.parse('Jan 30 2009') 2009-01-30T00:00:00+00:00 => nil irb(main):008:0> puts DateTime.parse('17:26 Jan 10 2009') 2009-11-10T20:09:00+00:00 => nil irb(main):009:0> puts DateTime.parse('17 Jan 10 2009') 0010-01-17T00:00:00+00:00 => nil irb(main):010:0> puts DateTime.parse('10 Jan 10 2009') 0010-01-10T00:00:00+00:00 => nil irb(main):011:0> puts DateTime.parse('1 Jan 10 2009') 0010-01-01T00:00:00+00:00 => nil irb(main):012:0> puts DateTime.parse('1 12 10 2009') 2009-11-12T10:00:00+00:00 => nil irb(main):013:0> puts DateTime.parse('12 10 2009') 2009-11-12T10:00:00+00:00 => nil irb(main):014:0> puts DateTime.parse('12 10 2009 0') 2009-11-12T10:00:00+00:00 => nil