bijilsandroid / as3corelib

Automatically exported from code.google.com/p/as3corelib
0 stars 0 forks source link

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

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
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;   
        }

Original issue reported on code.google.com by peatmos...@gmail.com on 31 May 2008 at 1:48

GoogleCodeExporter commented 8 years ago

Original comment by mikechambers on 2 Jul 2008 at 5:52