Title: [104266] trunk
Revision
104266
Author
[email protected]
Date
2012-01-05 20:48:14 -0800 (Thu, 05 Jan 2012)

Log Message

date.toISOString produces incorrect results for dates with ms prior to 1970
https://bugs.webkit.org/show_bug.cgi?id=75684

Reviewed by Sam Weinig.

Source/_javascript_Core: 

* runtime/DatePrototype.cpp:
(JSC::dateProtoFuncToISOString):

LayoutTests: 

* fast/js/date-toisostring-expected.txt:
* fast/js/script-tests/date-toisostring.js:
    - Added test case

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (104265 => 104266)


--- trunk/LayoutTests/ChangeLog	2012-01-06 04:01:23 UTC (rev 104265)
+++ trunk/LayoutTests/ChangeLog	2012-01-06 04:48:14 UTC (rev 104266)
@@ -1,3 +1,14 @@
+2012-01-05  Gavin Barraclough  <[email protected]>
+
+        date.toISOString produces incorrect results for dates with ms prior to 1970
+        https://bugs.webkit.org/show_bug.cgi?id=75684
+
+        Reviewed by Sam Weinig.
+
+        * fast/js/date-toisostring-expected.txt:
+        * fast/js/script-tests/date-toisostring.js:
+            - Added test case
+
 2012-01-05  Ojan Vafai  <[email protected]>
 
         More chromium expected results after r104208.

Modified: trunk/LayoutTests/fast/js/date-toisostring-expected.txt (104265 => 104266)


--- trunk/LayoutTests/fast/js/date-toisostring-expected.txt	2012-01-06 04:01:23 UTC (rev 104265)
+++ trunk/LayoutTests/fast/js/date-toisostring-expected.txt	2012-01-06 04:48:14 UTC (rev 104266)
@@ -5,6 +5,7 @@
 
 PASS Date.toISOString.call({}) threw exception TypeError: 'undefined' is not an object (evaluating 'Date.toISOString.call').
 PASS Date.toISOString.call(0) threw exception TypeError: 'undefined' is not an object (evaluating 'Date.toISOString.call').
+PASS new Date(-400).toISOString() is '1969-12-31T23:59:59.600Z'
 PASS new Date(0).toISOString() is '1970-01-01T00:00:00.000Z'
 PASS new Date('1 January 1500 UTC').toISOString() is '1500-01-01T00:00:00.000Z'
 PASS new Date('1 January 2000 UTC').toISOString() is '2000-01-01T00:00:00.000Z'

Modified: trunk/LayoutTests/fast/js/script-tests/date-toisostring.js (104265 => 104266)


--- trunk/LayoutTests/fast/js/script-tests/date-toisostring.js	2012-01-06 04:01:23 UTC (rev 104265)
+++ trunk/LayoutTests/fast/js/script-tests/date-toisostring.js	2012-01-06 04:48:14 UTC (rev 104266)
@@ -13,6 +13,7 @@
 shouldThrow("Date.toISOString.call({})");
 shouldThrow("Date.toISOString.call(0)");
 
+shouldBe("new Date(-400).toISOString()", "'1969-12-31T23:59:59.600Z'");
 shouldBe("new Date(0).toISOString()", "'1970-01-01T00:00:00.000Z'");
 shouldBe("new Date('1 January 1500 UTC').toISOString()", "'1500-01-01T00:00:00.000Z'");
 shouldBe("new Date('1 January 2000 UTC').toISOString()", "'2000-01-01T00:00:00.000Z'");

Modified: trunk/Source/_javascript_Core/ChangeLog (104265 => 104266)


--- trunk/Source/_javascript_Core/ChangeLog	2012-01-06 04:01:23 UTC (rev 104265)
+++ trunk/Source/_javascript_Core/ChangeLog	2012-01-06 04:48:14 UTC (rev 104266)
@@ -1,5 +1,15 @@
 2012-01-05  Gavin Barraclough  <[email protected]>
 
+        date.toISOString produces incorrect results for dates with ms prior to 1970
+        https://bugs.webkit.org/show_bug.cgi?id=75684
+
+        Reviewed by Sam Weinig.
+
+        * runtime/DatePrototype.cpp:
+        (JSC::dateProtoFuncToISOString):
+
+2012-01-05  Gavin Barraclough  <[email protected]>
+
         Array.prototype.lastIndexOf ignores undefined fromIndex.
         https://bugs.webkit.org/show_bug.cgi?id=75678
 

Modified: trunk/Source/_javascript_Core/runtime/DatePrototype.cpp (104265 => 104266)


--- trunk/Source/_javascript_Core/runtime/DatePrototype.cpp	2012-01-06 04:01:23 UTC (rev 104265)
+++ trunk/Source/_javascript_Core/runtime/DatePrototype.cpp	2012-01-06 04:48:14 UTC (rev 104266)
@@ -508,10 +508,13 @@
     // 6 for formatting and one for null termination = 28. We add one extra character to allow us to force null termination.
     char buffer[29];
     // If the year is outside the bounds of 0 and 9999 inclusive we want to use the extended year format (ES 15.9.1.15.1).
+    int ms = static_cast<int>(fmod(thisDateObj->internalNumber(), msPerSecond));
+    if (ms < 0)
+        ms += msPerSecond;
     if (gregorianDateTime->year > 8099 || gregorianDateTime->year < -1900)
-        snprintf(buffer, sizeof(buffer) - 1, "%+07d-%02d-%02dT%02d:%02d:%02d.%03dZ", 1900 + gregorianDateTime->year, gregorianDateTime->month + 1, gregorianDateTime->monthDay, gregorianDateTime->hour, gregorianDateTime->minute, gregorianDateTime->second, static_cast<int>(fmod(thisDateObj->internalNumber(), 1000)));
+        snprintf(buffer, sizeof(buffer) - 1, "%+07d-%02d-%02dT%02d:%02d:%02d.%03dZ", 1900 + gregorianDateTime->year, gregorianDateTime->month + 1, gregorianDateTime->monthDay, gregorianDateTime->hour, gregorianDateTime->minute, gregorianDateTime->second, ms);
     else
-        snprintf(buffer, sizeof(buffer) - 1, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", 1900 + gregorianDateTime->year, gregorianDateTime->month + 1, gregorianDateTime->monthDay, gregorianDateTime->hour, gregorianDateTime->minute, gregorianDateTime->second, static_cast<int>(fmod(thisDateObj->internalNumber(), 1000)));
+        snprintf(buffer, sizeof(buffer) - 1, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", 1900 + gregorianDateTime->year, gregorianDateTime->month + 1, gregorianDateTime->monthDay, gregorianDateTime->hour, gregorianDateTime->minute, gregorianDateTime->second, ms);
     buffer[sizeof(buffer) - 1] = 0;
     return JSValue::encode(jsNontrivialString(exec, buffer));
 }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to