Title: [165667] trunk
Revision
165667
Author
[email protected]
Date
2014-03-14 18:11:16 -0700 (Fri, 14 Mar 2014)

Log Message

Incorrect Date returned between March 1, 2034 and February 28, 2100.
https://bugs.webkit.org/show_bug.cgi?id=130123

Patch by Byungseon Shin <[email protected]> on 2014-03-14
Reviewed by Mark Lam.

Fix logic by using predefined Date APIs.

Source/WTF:

* wtf/DateMath.cpp:
(WTF::ymdhmsToSeconds):

LayoutTests:

* js/date-constructor-expected.txt:
* js/script-tests/date-constructor.js:
(testDate):

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (165666 => 165667)


--- trunk/LayoutTests/ChangeLog	2014-03-15 01:03:02 UTC (rev 165666)
+++ trunk/LayoutTests/ChangeLog	2014-03-15 01:11:16 UTC (rev 165667)
@@ -1,3 +1,16 @@
+2014-03-14  Byungseon Shin  <[email protected]>
+
+        Incorrect Date returned between March 1, 2034 and February 28, 2100.
+        https://bugs.webkit.org/show_bug.cgi?id=130123
+
+        Reviewed by Mark Lam.
+
+        Fix logic by using predefined Date APIs.
+
+        * js/date-constructor-expected.txt:
+        * js/script-tests/date-constructor.js:
+        (testDate):
+
 2014-03-14  James Craig  <[email protected]>
 
         AX: AccessibilityObject::invalidStatus() is incorrect when aria-invalid="undefined" or whitespace

Modified: trunk/LayoutTests/js/date-constructor-expected.txt (165666 => 165667)


--- trunk/LayoutTests/js/date-constructor-expected.txt	2014-03-15 01:03:02 UTC (rev 165666)
+++ trunk/LayoutTests/js/date-constructor-expected.txt	2014-03-15 01:11:16 UTC (rev 165667)
@@ -35,6 +35,7 @@
 PASS new Date(6501480442020679337816440, 81696082856817131586190070, 1, 1, 1, 1, 1).getTime() is Number.NaN
 PASS testStr is "1234567"
 PASS testStr is "1234567"
+PASS leapTestResult is true
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/js/script-tests/date-constructor.js (165666 => 165667)


--- trunk/LayoutTests/js/script-tests/date-constructor.js	2014-03-15 01:03:02 UTC (rev 165666)
+++ trunk/LayoutTests/js/script-tests/date-constructor.js	2014-03-15 01:11:16 UTC (rev 165667)
@@ -68,3 +68,38 @@
 testStr = "";
 Date.UTC(year, month, date, hours, minutes, seconds, ms);
 shouldBe('testStr', '\"1234567\"');
+
+// Regression test for Bug 130123 (https://bugs.webkit.org/show_bug.cgi?id=130123)
+var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
+
+function testDate(year, month, date) {
+    var success = true;
+    var dateString = monthNames[month] + " " + date + ", " + year;
+    var dateObj = new Date(dateString);
+
+    if (dateObj.getFullYear() != year) {
+        shouldBe("new Date(" + dateString + ").getFullYear()", year);
+        success = false;
+    } if (dateObj.getMonth() != month) {
+        shouldBe("new Date(" + dateString + ").getMonth()", month);
+        success = false;
+    } if (dateObj.getDate() != date) {
+        shouldBe("new Date(" + dateString + ").getDate()", date);
+        success = false;
+    }
+    return success;
+}
+
+var leapTestResult = true;
+var year = 100;
+var month = 0;
+var date = 1;
+
+while (year < 10000) {
+    leapTestResult = leapTestResult && testDate(year, month, date);
+    year += 1;
+    month = (month + 7) % 12;
+    date = (date + 13) % 28 + 1;
+}
+
+shouldBeTrue("leapTestResult");

Modified: trunk/Source/WTF/ChangeLog (165666 => 165667)


--- trunk/Source/WTF/ChangeLog	2014-03-15 01:03:02 UTC (rev 165666)
+++ trunk/Source/WTF/ChangeLog	2014-03-15 01:11:16 UTC (rev 165667)
@@ -1,3 +1,15 @@
+2014-03-14  Byungseon Shin  <[email protected]>
+
+        Incorrect Date returned between March 1, 2034 and February 28, 2100.
+        https://bugs.webkit.org/show_bug.cgi?id=130123
+
+        Reviewed by Mark Lam.
+
+        Fix logic by using predefined Date APIs.
+
+        * wtf/DateMath.cpp:
+        (WTF::ymdhmsToSeconds):
+
 2014-03-12  Sergio Villar Senin  <[email protected]>
 
         Rename DEFINE_STATIC_LOCAL to DEPRECATED_DEFINE_STATIC_LOCAL

Modified: trunk/Source/WTF/wtf/DateMath.cpp (165666 => 165667)


--- trunk/Source/WTF/wtf/DateMath.cpp	2014-03-15 01:03:02 UTC (rev 165666)
+++ trunk/Source/WTF/wtf/DateMath.cpp	2014-03-15 01:11:16 UTC (rev 165667)
@@ -517,12 +517,10 @@
 
 static inline double ymdhmsToSeconds(int year, long mon, long day, long hour, long minute, double second)
 {
-    double days = (day - 32075)
-        + floor(1461 * (year + 4800.0 + (mon - 14) / 12) / 4)
-        + 367 * (mon - 2 - (mon - 14) / 12 * 12) / 12
-        - floor(3 * ((year + 4900.0 + (mon - 14) / 12) / 100) / 4)
-        - 2440588;
-    return ((days * hoursPerDay + hour) * minutesPerHour + minute) * secondsPerMinute + second;
+    int mday = firstDayOfMonth[isLeapYear(year)][mon - 1];
+    double ydays = daysFrom1970ToYear(year);
+
+    return (second + minute * secondsPerMinute + hour * secondsPerHour + (mday + day - 1 + ydays) * secondsPerDay);
 }
 
 // We follow the recommendation of RFC 2822 to consider all
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to