oliviaramos / simile-widgets

Automatically exported from code.google.com/p/simile-widgets
0 stars 0 forks source link

Gregorian date parser returns invalid date, not null, for bad date strings #281

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
>>> Timeline.DateTime.parseGregorianDateTime('test')
Invalid Date
>>> Timeline.DateTime.parseGregorianDateTime('')
Invalid Date
>>> Timeline.DateTime.parseGregorianDateTime(false)
Invalid Date

It looks like the function is intended to return null in these instances,
as the ISO8601 parser does, but it returns an invalid Date object instead.

Problem is here:
http://code.google.com/p/simile-widgets/source/browse/ajax/trunk/src/webapp/api/
scripts/date-time.js#248

change from:

{{{
    try {
        return new Date(Date.parse(s));
    } catch (e) {
        return null;
    }
}}}

to:

{{{
    try {
        var d = new Date(Date.parse(s));
        if (!d.getFullYear()) d = null;
        return d;
    } catch (e) {
        return null;
    }
}}}

Original issue reported on code.google.com by nick.rab...@gmail.com on 21 May 2009 at 8:41

GoogleCodeExporter commented 8 years ago

Original comment by ryan...@csail.mit.edu on 23 Jun 2011 at 10:15