Changeset 17520 in webkit


Ignore:
Timestamp:
Nov 1, 2006 12:34:23 PM (17 years ago)
Author:
kmccullo
Message:

Reviewed by Brady.

  • Fixes many JavaScriptCore tests in other timezones. The root problem is that on mac localtime() returns historically accurate information for DST, but the JavaScript spec explicitly states to not take into account historical information but rather to interpolate from valid years.
  • kjs/DateMath.cpp: (KJS::equivalentYearForDST): (KJS::getDSTOffsetSimple): (KJS::getDSTOffset):
Location:
trunk/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r17507 r17520  
     12006-11-01  Kevin McCullough  <KMcCullough@apple.com>
     2
     3        Reviewed by Brady.
     4
     5        - Fixes many JavaScriptCore tests in other timezones.  The root problem is that on mac localtime() returns historically accurate information for DST, but the JavaScript spec explicitly states to not take into account historical information but rather to interpolate from valid years.
     6
     7        * kjs/DateMath.cpp:
     8        (KJS::equivalentYearForDST):
     9        (KJS::getDSTOffsetSimple):
     10        (KJS::getDSTOffset):
     11
    1122006-10-31  Geoffrey Garen  <ggaren@apple.com>
    213
  • trunk/JavaScriptCore/kjs/DateMath.cpp

    r17333 r17520  
    6666    {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}
    6767};
    68 
    69 
    70 /*
    71  * Years and leap years on which Jan 1 is a Sunday, Monday, etc.
    72  *
    73  * yearStartingWith[0][i] is an example non-leap year where
    74  * Jan 1 appears on Sunday (i == 0), Monday (i == 1), etc.
    75  *
    76  * yearStartingWith[1][i] is an example leap year where
    77  * Jan 1 appears on Sunday (i == 0), Monday (i == 1), etc.
    78  */
    79 static int yearStartingWith[2][7] = {
    80     {1978, 1973, 1974, 1975, 1981, 1971, 1977},
    81     {1984, 1996, 1980, 1992, 1976, 1988, 1972}
    82 };
    83 
    8468
    8569static inline int daysInYear(int year)
     
    299283int equivalentYearForDST(int year)
    300284{
    301     int day;
    302 
    303     day = (int) daysFrom1970ToYear(year) + 4;
    304     day %= 7;
    305 
    306     if (day < 0)
    307         day += 7;
    308 
    309     return yearStartingWith[isLeapYear(year)][day];
     285    int difference = 2000 - year;   // Arbitrary year around which most dates equivalence is correct
     286    int quotient = difference / 28; // Integer division, no remainder.
     287    int product = quotient * 28;
     288    return year + product;
    310289}
    311290
     
    346325        localTimeSeconds += secondsPerDay;
    347326
     327    //input is UTC so we have to shift back to local time to determine DST thus the + getUTCOffset()
    348328    double offsetTime = (localTimeSeconds * msPerSecond) + getUTCOffset() ;
    349329
     
    374354static double getDSTOffset(double ms)
    375355{
    376     /*
    377      * If earlier than 1970 or after 2038, potentially beyond the ken of
    378      * many OSes, map it to an equivalent year before asking.
    379      */
    380     if (ms < 0.0 || ms > 2145916800000.0) {
     356    // On mac the call to localtime (see getDSTOffsetSimple) will return historically accurate
     357    // DST information (e.g. New Zealand did not have DST from 1946 to 1974) however the JavaScript
     358    // standard explicitly dictates that historical information should not be considered when
     359    // determining DST.  For this reason we shift years that localtime can handle but would
     360    // return historically accurate information.
     361   
     362    //if before 2000 or after 2038
     363    if (ms < 946684800000.0 || ms > 2145916800000.0) {
    381364        int year;
    382365        int day;
Note: See TracChangeset for help on using the changeset viewer.