Changeset 16855 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Oct 6, 2006, 11:16:38 AM (19 years ago)
Author:
kmccullo
Message:

Reviewed by Brady.

DST and TimeZones were wrong in some cases, specifically on some of the dates where DST changes.

  • kjs/DateMath.cpp: (KJS::equivalentYearForDST): (KJS::getUTCOffset): (KJS::getDSTOffsetSimple): (KJS::getDSTOffset): (KJS::dateToMseconds): (KJS::msToTM):
  • kjs/DateMath.h:
  • kjs/date_object.cpp: (KJS::gmtoffset):
Location:
trunk/JavaScriptCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r16808 r16855  
     12006-10-06  Kevin McCullough  <[email protected]>
     2
     3        Reviewed by Brady.
     4
     5        DST and TimeZones were wrong in some cases, specifically on some of the dates where DST changes.
     6
     7        * kjs/DateMath.cpp:
     8        (KJS::equivalentYearForDST):
     9        (KJS::getUTCOffset):
     10        (KJS::getDSTOffsetSimple):
     11        (KJS::getDSTOffset):
     12        (KJS::dateToMseconds):
     13        (KJS::msToTM):
     14        * kjs/DateMath.h:
     15        * kjs/date_object.cpp:
     16        (KJS::gmtoffset):
     17
    1182006-10-05  Darin Adler  <[email protected]>
    219
  • trunk/JavaScriptCore/kjs/DateMath.cpp

    r16798 r16855  
    304304
    305305    day = (int) daysFrom1970ToYear(year) + 4;
    306     day = day % 7;
     306    day %= 7;
    307307
    308308    if (day < 0)
     
    330330        ltime.tm_isdst = 0;
    331331
    332         /* get the difference between this time zone and GMT */
     332        // get the difference between this time zone and GMT
    333333        ltime.tm_mday = 2;
    334334        ltime.tm_year = 70;
     
    356356    if(localTimeSeconds > maxUnixTime)
    357357        localTimeSeconds = maxUnixTime;
    358     else if(localTimeSeconds < 0) /*go ahead a day to make localtime work (does not work with 0) */
    359         localTimeSeconds = secondsPerDay;
    360 
     358    else if(localTimeSeconds < 0) // Go ahead a day to make localtime work (does not work with 0)
     359        localTimeSeconds += secondsPerDay;
     360
     361    struct tm prtm;
    361362    double offsetTime = (localTimeSeconds * usecPerMsec) + getUTCOffset() ;
    362363
    363     struct tm prtm;
     364    prtm.tm_hour  =  msToHours(offsetTime);
    364365    prtm.tm_min   =  msToMinutes(offsetTime);
    365     prtm.tm_hour  =  msToHours(offsetTime);
    366366
    367367    // FIXME: time_t has a potential problem in 2038
     
    399399    }
    400400
    401     /* put our ms in an LL, and map it to usec for prtime */
    402401    return getDSTOffsetSimple(ms / usecPerMsec);
    403 }
    404 
    405 static inline double localTimeToUTC(double ms)
    406 {
    407     ms -= getUTCOffset();
    408     ms -= getDSTOffset(ms);
    409     return ms;
    410 }
    411 
    412 static inline double UTCToLocalTime(double ms)
    413 {
    414     ms += getUTCOffset();
    415     ms += getDSTOffset(ms);
    416     return ms;
    417402}
    418403
     
    423408    double result = (day * msPerDay) + msec_time;
    424409
    425     if(!inputIsUTC)
    426         result = localTimeToUTC(result);
     410    if(!inputIsUTC) { // convert to UTC
     411        result -= getUTCOffset();
     412        result -= getDSTOffset(result);
     413    }
    427414
    428415    return result;
     
    431418void msToTM(double ms, bool outputIsUTC, struct tm& tm)
    432419{
    433     //input is UTC
    434     if(!outputIsUTC)
    435         ms = UTCToLocalTime(ms);
     420    // input is UTC
     421    double dstOff = 0.0;
     422   
     423    if(!outputIsUTC) {  // convert to local time
     424        dstOff = getDSTOffset(ms);
     425        ms += dstOff + getUTCOffset();
     426    }
    436427
    437428    tm.tm_sec   =  msToSeconds(ms);
     
    443434    tm.tm_mon   =  msToMonth(ms);
    444435    tm.tm_year  =  msToYear(ms) - 1900;
    445     tm.tm_isdst =  isDST(ms);
    446 
    447     //everyone else seems to have these fields
     436    tm.tm_isdst =  dstOff != 0.0;
     437
     438    // All other OS' seems to have these fields
    448439#if !PLATFORM(WIN_OS)
    449440    struct tm xtm;
     
    456447}
    457448
    458 bool isDST(const double& ms)
    459 {
    460     return getDSTOffset(ms) != 0;
    461 }
    462 
    463 }   //namespace KJS
    464 
     449}   // namespace KJS
     450
  • trunk/JavaScriptCore/kjs/DateMath.h

    r16780 r16855  
    6262void msToTM(double, bool outputIsUTC, struct tm& );
    6363double dateToMseconds(tm*, double, bool inputIsUTC);
    64 bool isDST(const double&);
    6564double getUTCOffset();
    6665
  • trunk/JavaScriptCore/kjs/date_object.cpp

    r16798 r16855  
    7070#if PLATFORM(WIN_OS)
    7171    // Time is supposed to be in the current timezone.
    72     static int utcOffset = static_cast<int>(getUTCOffset()/1000.0);
    73     return utcOffset;
     72    return -(_timezone / 60 - (t.tm_isdst != 0 ? 60 : 0 )) * 60;
    7473#else
    7574    return t.tm_gmtoff;
Note: See TracChangeset for help on using the changeset viewer.