Closed Bug 439295 Opened 16 years ago Closed 13 years ago

ISO8601DateUtils fails to parse sample date "20030530T11:18:50-08:00"

Categories

(Core :: General, defect)

defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: myk, Unassigned)

Details

ISO8601DateUtils::parse contains a "workaround for server sending dates such as: 20030530T11:18:50-08:00 instead of: 2003-05-30T11:18:50-08:00", but it fails to parse the sample date, returning "Invalid Date" when the following JavaScript is evaluated in the Error Console:

Components.utils.import("resource://gre/modules/ISO8601DateUtils.jsm"); ISO8601DateUtils.parse("20030530T11:18:50-08:00")

The problem is that the method only applies the workaround if the string contains no occurrences of a minus sign (-), but the sample string contains a minus sign.  Perhaps this doesn't currently result in errors because the consumers of this code only pass such strings in the UTC timezone, whose representation doesn't contain a minus sign (f.e. "20030530T11:18:50Z").

One fix for this problem would be to apply the workaround if the string either contains no occurrences of a minus sign or contains an occurrence whose index is greater than the index of the occurrence of the letter T, a required character that separates the date portion of the string from the time portion, i.e.:

if (dateString.indexOf("-") == -1 || dateString.indexOf("-") > dateString.indexOf("T")) {
  // apply workaround
}

Note that the enhancement to ISO8601DateUtils in bug 429492 appears to also fix this bug.
Guess I shouldn't have been quite so proud I discovered that bug while killing it, since it took me three more years than it took you :)

ISO8601DateUtils is dead, long live jsdate.cpp's date_parseISOString.
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.