Changeset 20203 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
Mar 14, 2007, 7:21:47 PM (18 years ago)
Author:
kmccullo
Message:

JavaScriptCore:

Reviewed by Geoff.

  • rdar://problem/5045720
  • DST changes in US affect JavaScript date calculations (12975) This fix was to ensure we properly test for the new changes to DST in the US. Also this fixes when we apply DST, now we correctly map most past years to current DST rules. We still have a small issue with years before 1900 or after 2100. rdar://problem/5055038
  • kjs/DateMath.cpp: Fix DST to match spec better. (KJS::getCurrentUTCTime): (KJS::mimimumYearForDST): (KJS::maximumYearForDST): (KJS::equivalentYearForDST): (KJS::getDSTOffset):
  • kjs/DateMath.h: Consolodated common funtionality.
  • kjs/date_object.cpp: Consolodated common functionality. (KJS::formatLocaleDate): (KJS::DateObjectImp::construct):
  • tests/mozilla/ecma/jsref.js: Added functions for finding the correct days when DST starts and ends.
  • tests/mozilla/ecma/shell.js: Added back in the old DST functions for ease of merging with mozilla if needed.
  • tests/mozilla/ecma_2/jsref.js: Added functions for finding the correct days when DST starts and ends.
  • tests/mozilla/ecma_3/Date/shell.js: Added functions for finding the correct days when DST starts and ends.
  • tests/mozilla/expected.html: Updated to show all date tests passing.

LayoutTests:

Reviewed by Geoff.

  • rdar://problem/5045720
  • DST changes in US affect JavaScript date calculations (12975) Changed layout tests to properly check for the new changes to DST in the US. Also these now test that equivalent years return the same results for DST.
  • fast/js/date-DST-time-cusps-expected.txt:
  • fast/js/date-big-setdate-expected.txt:
  • fast/js/resources/date-DST-time-cusps.js:
  • fast/js/resources/date-big-setdate.js:
Location:
trunk/JavaScriptCore/kjs
Files:
2 edited

Legend:

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

    r19945 r20203  
    4545#include <math.h>
    4646#include <stdint.h>
     47#include <value.h>
     48
     49#include <wtf/Assertions.h>
    4750
    4851#if PLATFORM(DARWIN)
     
    268271}
    269272
     273double getCurrentUTCTime()
     274{
     275#if PLATFORM(WIN_OS)
     276#if COMPILER(BORLAND)
     277    struct timeb timebuffer;
     278    ftime(&timebuffer);
     279#else
     280    struct _timeb timebuffer;
     281    _ftime(&timebuffer);
     282#endif
     283    double utc = timebuffer.time * msPerSecond + timebuffer.millitm;
     284#else
     285    struct timeval tv;
     286    gettimeofday(&tv, 0);
     287    double utc = floor(tv.tv_sec * msPerSecond + tv.tv_usec / 1000);
     288#endif
     289    return utc;
     290}
     291
     292// There is a hard limit at 2038 that we currently do not have a workaround
     293// for (rdar://problem/5052975).
     294static inline int maximumYearForDST()
     295{
     296    return 2037;
     297}
     298
     299// It is ok if the cached year is not the current year (e.g. Dec 31st)
     300// so long as the rules for DST did not change between the two years, if it does
     301// the app would need to be restarted.
     302static int mimimumYearForDST()
     303{
     304    // Because of the 2038 issue (see maximumYearForDST) if the current year is
     305    // greater than the max year minus 27 (2010), we want to use the max year
     306    // minus 27 instead, to ensure there is a range of 28 years that all years
     307    // can map to.
     308    static int minYear = std::min(msToYear(getCurrentUTCTime()), maximumYearForDST()-27) ;
     309    return minYear;
     310}
     311
    270312/*
    271  * Find a year for which any given date will fall on the same weekday.
    272  *
    273  * This function should be used with caution when used other than
    274  * for determining DST; it hasn't been proven not to produce an
    275  * incorrect year for times near year boundaries.
     313 * Find an equivalent year for the one given, where equivalence is deterined by
     314 * the two years having the same leapness and the first day of the year, falling
     315 * on the same day of the week.
     316 *
     317 * This function returns a year between this current year and 2037, however this
     318 * function will potentially return incorrect results if the current year is after
     319 * 2010, (rdar://problem/5052975), if the year passed in is before 1900 or after
     320 * 2100, (rdar://problem/5055038).
    276321 */
    277322int equivalentYearForDST(int year)
    278323{
    279     int difference = 2000 - year;   // Arbitrary year around which most dates equivalence is correct
    280     int quotient = difference / 28; // Integer division, no remainder.
    281     int product = quotient * 28;
    282     return year + product;
     324    static int minYear = mimimumYearForDST();
     325    static int maxYear = maximumYearForDST();
     326   
     327    int difference;
     328    if (year > maxYear)
     329        difference = minYear - year;
     330    else if (year < minYear)
     331        difference = maxYear - year;
     332    else
     333        return year;
     334
     335    int quotient = difference / 28;
     336    int product = (quotient) * 28;
     337
     338    year += product;
     339    ASSERT((year >= minYear && year <= maxYear) || (product - year == static_cast<int>(NaN)));
     340    return year;
    283341}
    284342
     
    377435    // determining DST. For this reason we shift away from years that localtime can handle but would
    378436    // return historically accurate information.
    379 
    380     // if before Jan 01, 2000 12:00:00 AM UTC or after Jan 01, 2038 12:00:00 AM UTC
    381     if (ms < 946684800000.0 || ms > 2145916800000.0) {
    382         int year = equivalentYearForDST(msToYear(ms));
    383         int day = dateToDayInYear(year, msToMonth(ms), msToDayInMonth(ms));
     437    int year = msToYear(ms);
     438    int equvalentYear = equivalentYearForDST(year);
     439    if (year != equvalentYear) {
     440        int day = dateToDayInYear(equvalentYear, msToMonth(ms), msToDayInMonth(ms));
    384441        ms = (day * msPerDay) + msToMilliseconds(ms);
    385442    }
  • trunk/JavaScriptCore/kjs/DateMath.h

    r19945 r20203  
    5454double getUTCOffset();
    5555int equivalentYearForDST(int year);
     56double getCurrentUTCTime();
    5657
    5758const char * const weekdayName[7] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
Note: See TracChangeset for help on using the changeset viewer.