Ignore:
Timestamp:
Dec 11, 2009, 7:39:30 AM (15 years ago)
Author:
[email protected]
Message:

2009-12-11 Kent Tamura <[email protected]>

Reviewed by Darin Adler.

Fix a problem that JSC::gregorianDateTimeToMS() returns a negative
value for a huge year value.
https://bugs.webkit.org/show_bug.cgi?id=32304

  • wtf/DateMath.cpp: (WTF::dateToDaysFrom1970): Renamed from dateToDayInYear, and changed the return type to double. (WTF::calculateDSTOffset): Follow the dateToDaysFrom1970() change. (WTF::timeClip): Use maxECMAScriptTime. (JSC::gregorianDateTimeToMS): Follow the dateToDaysFrom1970() change.

2009-12-11 Kent Tamura <[email protected]>

Reviewed by Darin Adler.

Fix a problem that JSC::gregorianDateTimeToMS() returns a negative
value for a huge year value.
https://bugs.webkit.org/show_bug.cgi?id=32304

  • fast/js/date-daysfrom1970-overflow-expected.txt: Added.
  • fast/js/date-daysfrom1970-overflow.html: Added.
  • fast/js/script-tests/date-daysfrom1970-overflow.js: Added.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/DateMath.cpp

    r51955 r51986  
    121121
    122122static const double maxUnixTime = 2145859200.0; // 12/31/2037
     123// ECMAScript asks not to support for a date of which total
     124// millisecond value is larger than the following value.
     125// See 15.9.1.14 of ECMA-262 5th edition.
     126static const double maxECMAScriptTime = 8.64E15;
    123127
    124128// Day of year for the first day of each month, where index 0 is January, and day 0 is January 1.
     
    307311}
    308312
    309 static int dateToDayInYear(int year, int month, int day)
     313static double dateToDaysFrom1970(int year, int month, int day)
    310314{
    311315    year += month / 12;
     
    317321    }
    318322
    319     int yearday = static_cast<int>(floor(daysFrom1970ToYear(year)));
     323    double yearday = floor(daysFrom1970ToYear(year));
     324    ASSERT((year >= 1970 && yearday >= 0) || (year < 1970 && yearday < 0));
    320325    int monthday = monthToDayInYear(month, isLeapYear(year));
    321326
     
    453458        int dayInMonth = dayInMonthFromDayInYear(dayInYearLocal, leapYear);
    454459        int month = monthFromDayInYear(dayInYearLocal, leapYear);
    455         int day = dateToDayInYear(equivalentYear, month, dayInMonth);
     460        double day = dateToDaysFrom1970(equivalentYear, month, dayInMonth);
    456461        ms = (day * msPerDay) + msToMilliseconds(ms);
    457462    }
     
    842847    if (!isfinite(t))
    843848        return NaN;
    844     if (fabs(t) > 8.64E15)
     849    if (fabs(t) > maxECMAScriptTime)
    845850        return NaN;
    846851    return trunc(t);
     
    928933double gregorianDateTimeToMS(ExecState* exec, const GregorianDateTime& t, double milliSeconds, bool inputIsUTC)
    929934{
    930     int day = dateToDayInYear(t.year + 1900, t.month, t.monthDay);
     935    double day = dateToDaysFrom1970(t.year + 1900, t.month, t.monthDay);
    931936    double ms = timeToMS(t.hour, t.minute, t.second, milliSeconds);
    932937    double result = (day * WTF::msPerDay) + ms;
Note: See TracChangeset for help on using the changeset viewer.