Skip to content

DateUtil.parseW3CDTF() returns wrong result for milliseconds with >3 digits #51

Open
@darronschall

Description

@darronschall

Originally filed by peatmoss84 on 2008-05-31T13:48:57

What steps will reproduce the problem?

  1. Parse this DateUtil.parseW3CDTF("2008-05-31T09:39:48.1870000-04:00")

What is the expected output? What do you see instead?
You get back Sat May 31 10:10:58 GMT-0400 2008.

What version of the product are you using? On what operating system?
Version .90 on Windows.

Please provide any additional information below.
The W3C spec allows for an "unlimited" number of fractional digits. The
method implementation simply parses the fractional portion of the seconds
field into a Number. In the example above, the milliseconds Number is
1870000. When passed to the Date() ctor, you get an additional 31.1667
minutes.

I think the fix is to interpret the seconds field as a number, then use
Math.floor() to extract the seconds and subtract from the original value
to get the milliseconds. Something like this:

    var seconds:Number = 0;
    var milliseconds:Number = 0;
    if (timeArr.length > 0)
    {
      var fullSeconds:Number = Number(timeArr.shift());
      seconds = Math.floor(fullSeconds);
      milliseconds = fullSeconds - seconds;   
    }

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions