Opened 13 years ago

Closed 13 years ago

#2338 closed defect (fixed)

Getting "Invalid Date" with dojo.date.setIso8601() with Firefox

Reported by: Adam Peller Owned by: Adam Peller
Priority: high Milestone: 0.9
Component: Date Version: 0.4.1
Keywords: Cc:
Blocked By: Blocking:

Description

Reported by Akira Sudoh (IBM)

When calling dojo.date.setIso8601(new Date, "20070116T141500+09") with Firefox, it returns "Invalid Date".

My investigation indicated that dojo.date code does not consider regular expression tokens being "undefined", which happens with Firefox, when there is no string to match to the token. (Internet Explorer sets null string to such tokens)

In this specific case, dojo.date.setIso8601 performs match a string "20070116T141500+09" to a regular expression "Z|(([-+])([0-9]{2})(:?([0-9]{2}))?)$". And it'll be tokenized as:

0: "20070116T141500+09" 1: "+09" 2: "+" 3: "09" 4: undefined 5: undefined

The token in question is the fifth one, which will be used to calculate timezone offset, using Number(). Number(undefined) returns NaN and that causes "Invalid Date".

I've attached sample HTML to reproduce this and the patch.

Attachments (3)

sample.html (257 bytes) - added by Adam Peller 13 years ago.
Test case from Akira
serialize.js.diff (478 bytes) - added by Adam Peller 13 years ago.
patch from Akira Sudoh (IBM)
isodate.patch (1.5 KB) - added by Adam Peller 13 years ago.
proposed patch to dojo.date.serialize

Download all attachments as: .zip

Change History (4)

Changed 13 years ago by Adam Peller

Attachment: sample.html added

Test case from Akira

Changed 13 years ago by Adam Peller

Attachment: serialize.js.diff added

patch from Akira Sudoh (IBM)

Changed 13 years ago by Adam Peller

Attachment: isodate.patch added

proposed patch to dojo.date.serialize

comment:1 Changed 13 years ago by Adam Peller

Resolution: fixed
Status: newclosed
(In [7042]) Fixes #2338. Use
instead of ?: -- works fine in Rhino now.
Note: See TracTickets for help on using tickets.