> Programming Languages > Ruby
Various Topics Home | Disclaimer | Report Adult Posts

Various Topics on Ruby



Ruby - "Parse Date bug?" in Programming Languages


Old 01-22-2004   #1
..illau.. ..rca..
 
Default Parse Date bug?

Parse Date returns illegal values in a date. Ex:

[gus@comp Ruby]$ ruby -v
ruby 1.8.1 (2003-12-25) [i586-linux-gnu]
[gus@comp Ruby]$ ruby -rparsedate -e 'p ParseDate.parsedate("Monday
2003")'
[nil, 20, 3, nil, nil, nil, nil, 1]
[gus@comp Ruby]$ ruby -rparsedate -e 'p ParseDate.parsedate("Monday
march 2003")'
[nil, 3, 2003, nil, nil, nil, nil, 1]
[gus@comp Ruby]$ ruby -rparsedate -e 'p ParseDate.parsedate("Monday 1st
march 2003")'
[2003, 3, 1, nil, nil, nil, nil, 1]

In the first example, the month is 20 and in the second example, the day
in the month is 2003! Ouch.

The fact that parsedate has a hard time to parse the stupid date I gave
is fine. But I rather get a nil back than an impossible value.

Guilaume.


 
Old 01-23-2004   #2
..kihi.. ..tsumo..
 
Default Re: Parse Date bug?

Hi,

In message "Parse Date bug?"
on 04/01/23, Guillaume Marcais <guslist@free.fr> writes:

|Parse Date returns illegal values in a date. Ex:

ParseDate is easily fooled by incomplete input.

p ParseDate.parsedate("Monday 2003")
[nil, 20, 3, nil, nil, nil, nil, 1]

This case it reads Monday 20th month 3rd day.

matz.


 
Old 01-24-2004   #3
..v.. ..stn..
 
Default Re: Parse Date bug?

Yukihiro Matsumoto wrote:
> >Parse Date returns illegal values in a date. Ex:

> ParseDate is easily fooled by incomplete input.


I think the point is that it's understandable that it may be fooled.
However, once it has attempted to create the answer, it should at least
ensure that the month is valid (jan-dec, not month "20") and that the
number of days is allowed within that month in that year.

I myself am a fan of the way Javascript handles invalid dates. For example:

someDate = new Date("9/31/2003");
someDate.toString();
=> "Wed Oct 01 2003 00:00:00 GMT-0600 (MDT)"

Basically, seconds, minutes, hours, days, and months which are larger
than a legal value are modded to the valid range, and then increment the
next larger unit.

--
(-, /\ \/ / /\/
 
Old 01-24-2004   #4
.... .. ....
 
Default Re: Parse Date bug?

On Sat, Jan 24, 2004 at 06:28:38PM +0000, Gavin Kistner wrote:
> I myself am a fan of the way Javascript handles invalid dates. For example:


I like the fact that Date provides both an interface that
raises an exception if a value is out of range, and one (albeit
a trickier one) that handles such numbers transparently:

irb(main):001:0> require 'date'
=> true
irb(main):002:0> Date.new(2003,9,31)
ArgumentError: invalid date
from /usr/lib/ruby/1.8/date.rb:591:in `new'
from (irb):2
irb(main):003:0> puts Date.jd(Date.civil_to_jd(2003,9,31))
2003-10-01
=> nil

Because sometimes you want to know that a date is invalid, instead of
getting November 30, 1 BC because someone entered all zeros.

-Mark

 
Old 01-25-2004   #5
..edrid..
 
Default Re: Parse Date bug?

On Sun, Jan 25, 2004 at 04:20:21AM +0900, Austin Ziegler wrote:
> On Sun, 25 Jan 2004 03:29:56 +0900, Gavin Kistner wrote:
> > Yukihiro Matsumoto wrote:
> >>> Parse Date returns illegal values in a date. Ex:
> >> ParseDate is easily fooled by incomplete input.

> > I think the point is that it's understandable that it may be fooled.
> > However, once it has attempted to create the answer, it should at least
> > ensure that the month is valid (jan-dec, not month "20") and that the
> > number of days is allowed within that month in that year.

>
> > I myself am a fan of the way Javascript handles invalid dates. For
> > example:

>
> > someDate = new Date("9/31/2003");
> > someDate.toString();
> > => "Wed Oct 01 2003 00:00:00 GMT-0600 (MDT)"

>
> > Basically, seconds, minutes, hours, days, and months which are larger
> > than a legal value are modded to the valid range, and then increment the
> > next larger unit.

>
> Yuck. IMO, standard date cl***es should expect valid dates to be p***ed.
> This is something that I'd expect from something like "FuzzyDate", which has
> its value. But if someone gives me an invalid date, I want an error thrown!


Sounds like a time for

Date.new

and

Date.new_with_guess

Ari
>



 

Thread Tools
Display Modes





Powered by vBulletin®
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0