Changeset 51986 in webkit


Ignore:
Timestamp:
Dec 11, 2009 7:39:30 AM (14 years ago)
Author:
eric@webkit.org
Message:

2009-12-11 Kent Tamura <tkent@chromium.org>

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 <tkent@chromium.org>

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.
Location:
trunk
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r51978 r51986  
     12009-12-11  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Fix a problem that JSC::gregorianDateTimeToMS() returns a negative
     6        value for a huge year value.
     7        https://bugs.webkit.org/show_bug.cgi?id=32304
     8
     9        * wtf/DateMath.cpp:
     10        (WTF::dateToDaysFrom1970): Renamed from dateToDayInYear, and changed the return type to double.
     11        (WTF::calculateDSTOffset): Follow the dateToDaysFrom1970() change.
     12        (WTF::timeClip): Use maxECMAScriptTime.
     13        (JSC::gregorianDateTimeToMS): Follow the dateToDaysFrom1970() change.
     14
    1152009-12-10  Adam Barth  <abarth@webkit.org>
    216
  • 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;
  • trunk/LayoutTests/ChangeLog

    r51985 r51986  
     12009-12-11  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Fix a problem that JSC::gregorianDateTimeToMS() returns a negative
     6        value for a huge year value.
     7        https://bugs.webkit.org/show_bug.cgi?id=32304
     8
     9        * fast/js/date-daysfrom1970-overflow-expected.txt: Added.
     10        * fast/js/date-daysfrom1970-overflow.html: Added.
     11        * fast/js/script-tests/date-daysfrom1970-overflow.js: Added.
     12
    1132009-12-11  Benjamin Poulain  <benjamin.poulain@nokia.com>
    214
Note: See TracChangeset for help on using the changeset viewer.