aseps3472 / gdata-javascript-client

Automatically exported from code.google.com/p/gdata-javascript-client
0 stars 0 forks source link

DateTime.fromIso8601 not accepting many ISO8601 formats #12

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
fromIso8601 fails for various valid formats, even from the related 
documentation.

For example:
http://www.w3.org/TR/NOTE-datetime

1997-07-16T19:20:30+01:00

>>> google.gdata.DateTime.fromIso8601("1997-07-16T19:20:30+01:00");
Object { date=Invalid Date, more...}
>>> google.gdata.DateTime.fromIso8601("1997-07-16 19:20:30+01:00");
Object { date=Wed Jul 16 1997 00:00:00 GMT+0100 (CET), more...}

Note that the formatting with the "T" is AFAICT the official 8601 formatting.

>>> google.gdata.DateTime.fromIso8601("1997-07-16T19:20:30");
Object { date=Invalid Date, more...}
>>> google.gdata.DateTime.fromIso8601("1997-07-16 19:20:30");
Object { date=Wed Jul 16 1997 00:00:00 GMT+0100 (CET), more...}

Atom uses the rfc3339 subset, but even this contains above formats.
http://tools.ietf.org/html/rfc3339
Examples from Section 5.8:

>>> google.gdata.DateTime.fromIso8601("1985-04-12T23:20:50.52Z");
Object { date=Fri Apr 12 1985 23:20:50 GMT+0100 (CET), more...}
>>> google.gdata.DateTime.fromIso8601("1996-12-19T16:39:57-08:00");
Object { date=Invalid Date, more...}
>>> google.gdata.DateTime.fromIso8601("1990-12-31T23:59:60Z");
Object { date=Invalid Date, more...}
>>> google.gdata.DateTime.fromIso8601("1990-12-31T15:59:60-08:00");
Object { date=Invalid Date, more...}
>>> google.gdata.DateTime.fromIso8601("1937-01-01T12:00:27.87+00:20");
Object { date=Fri Jan 01 1937 13:00:27 GMT+0100 (CET), more...}

In any of the failed formats, replacing the "T" with a space seems to work!

Browser: Firefox on Linux. Chrome/Linux.

Original issue reported on code.google.com by erich.sc...@gmail.com on 27 Jan 2010 at 7:21

GoogleCodeExporter commented 8 years ago
No, it doesn't parse them with the T replaced very well either - most of the 
time, it loses the hour information 
(see the first one) and time offsets.

Original comment by erich.sc...@gmail.com on 27 Jan 2010 at 7:28

GoogleCodeExporter commented 8 years ago
I ran into this problem today while working with google.gdata.DateTime objects 
with the Google Calendar JavaScript API. I was able to work around it by first 
creating JavaScript date objects, then passing these to the 
google.gdata.DateTime constructor.

Original comment by andreima...@gmail.com on 27 Dec 2010 at 8:59