Changeset 165667 in webkit


Ignore:
Timestamp:
Mar 14, 2014 6:11:16 PM (10 years ago)
Author:
commit-queue@webkit.org
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 <sun.shin@lge.com> 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):

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r165656 r165667  
     12014-03-14  Byungseon Shin  <sun.shin@lge.com>
     2
     3        Incorrect Date returned between March 1, 2034 and February 28, 2100.
     4        https://bugs.webkit.org/show_bug.cgi?id=130123
     5
     6        Reviewed by Mark Lam.
     7
     8        Fix logic by using predefined Date APIs.
     9
     10        * js/date-constructor-expected.txt:
     11        * js/script-tests/date-constructor.js:
     12        (testDate):
     13
    1142014-03-14  James Craig  <jcraig@apple.com>
    215
  • trunk/LayoutTests/js/date-constructor-expected.txt

    r164373 r165667  
    3636PASS testStr is "1234567"
    3737PASS testStr is "1234567"
     38PASS leapTestResult is true
    3839PASS successfullyParsed is true
    3940
  • trunk/LayoutTests/js/script-tests/date-constructor.js

    r164373 r165667  
    6969Date.UTC(year, month, date, hours, minutes, seconds, ms);
    7070shouldBe('testStr', '\"1234567\"');
     71
     72// Regression test for Bug 130123 (https://bugs.webkit.org/show_bug.cgi?id=130123)
     73var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
     74
     75function testDate(year, month, date) {
     76    var success = true;
     77    var dateString = monthNames[month] + " " + date + ", " + year;
     78    var dateObj = new Date(dateString);
     79
     80    if (dateObj.getFullYear() != year) {
     81        shouldBe("new Date(" + dateString + ").getFullYear()", year);
     82        success = false;
     83    } if (dateObj.getMonth() != month) {
     84        shouldBe("new Date(" + dateString + ").getMonth()", month);
     85        success = false;
     86    } if (dateObj.getDate() != date) {
     87        shouldBe("new Date(" + dateString + ").getDate()", date);
     88        success = false;
     89    }
     90    return success;
     91}
     92
     93var leapTestResult = true;
     94var year = 100;
     95var month = 0;
     96var date = 1;
     97
     98while (year < 10000) {
     99    leapTestResult = leapTestResult && testDate(year, month, date);
     100    year += 1;
     101    month = (month + 7) % 12;
     102    date = (date + 13) % 28 + 1;
     103}
     104
     105shouldBeTrue("leapTestResult");
  • trunk/Source/WTF/ChangeLog

    r165607 r165667  
     12014-03-14  Byungseon Shin  <sun.shin@lge.com>
     2
     3        Incorrect Date returned between March 1, 2034 and February 28, 2100.
     4        https://bugs.webkit.org/show_bug.cgi?id=130123
     5
     6        Reviewed by Mark Lam.
     7
     8        Fix logic by using predefined Date APIs.
     9
     10        * wtf/DateMath.cpp:
     11        (WTF::ymdhmsToSeconds):
     12
    1132014-03-12  Sergio Villar Senin  <svillar@igalia.com>
    214
  • trunk/Source/WTF/wtf/DateMath.cpp

    r161601 r165667  
    518518static inline double ymdhmsToSeconds(int year, long mon, long day, long hour, long minute, double second)
    519519{
    520     double days = (day - 32075)
    521         + floor(1461 * (year + 4800.0 + (mon - 14) / 12) / 4)
    522         + 367 * (mon - 2 - (mon - 14) / 12 * 12) / 12
    523         - floor(3 * ((year + 4900.0 + (mon - 14) / 12) / 100) / 4)
    524         - 2440588;
    525     return ((days * hoursPerDay + hour) * minutesPerHour + minute) * secondsPerMinute + second;
     520    int mday = firstDayOfMonth[isLeapYear(year)][mon - 1];
     521    double ydays = daysFrom1970ToYear(year);
     522
     523    return (second + minute * secondsPerMinute + hour * secondsPerHour + (mday + day - 1 + ydays) * secondsPerDay);
    526524}
    527525
Note: See TracChangeset for help on using the changeset viewer.