Ignore:
Timestamp:
Oct 13, 2006, 10:31:11 AM (19 years ago)
Author:
kmccullo
Message:

Reviewed by Adam, Geoff, Darin.

Fixed displaying the UTC offset and time zone string, as well as renamed the GregorianDateTime structure and clean up.

  • ChangeLog:
  • kjs/DateMath.cpp: (KJS::getUTCOffset): (KJS::getDSTOffsetSimple): (KJS::gregorianDateTimeToMS): (KJS::msToGregorianDateTime):
  • kjs/DateMath.h: (KJS::GregorianDateTime::GregorianDateTime): (KJS::GregorianDateTime::~GregorianDateTime): (KJS::GregorianDateTime::toTM):
  • kjs/date_object.cpp: (KJS::gmtoffset): (KJS::formatDate): (KJS::formatDateUTCVariant): (KJS::formatTime): (KJS::fillStructuresUsingTimeArgs): (KJS::fillStructuresUsingDateArgs): (KJS::DateInstance::getTime): (KJS::DateInstance::getUTCTime): (KJS::DateProtoFunc::callAsFunction): (KJS::DateObjectImp::construct): (KJS::DateObjectImp::callAsFunction): (KJS::DateObjectFuncImp::callAsFunction): (KJS::parseDate):
  • kjs/date_object.h:
File:
1 edited

Legend:

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

    r17015 r17031  
    320320    static bool utcOffsetInitialized = false;
    321321    if (!utcOffsetInitialized) {
    322         struct ::tm ltime;
    323 
    324         memset(&ltime, 0, sizeof(ltime));
     322        tm localt;
     323
     324        memset(&localt, 0, sizeof(localt));
    325325       
    326326        // get the difference between this time zone and GMT
    327         ltime.tm_mday = 2;
    328         ltime.tm_year = 70;
    329 
    330         utcOffset = mktime(&ltime) - (hoursPerDay * secondsPerHour);
     327        localt.tm_mday = 2;
     328        localt.tm_year = 70;
     329
     330        utcOffset = mktime(&localt) - (hoursPerDay * secondsPerHour);
    331331        utcOffset *= -msPerSecond;
    332332
     
    357357    time_t localTime = static_cast<time_t>(localTimeSeconds);
    358358
    359     struct ::tm tm;
     359    tm localTM;
    360360    #if PLATFORM(WIN_OS)
    361     localtime_s(&tm, &localTime);
     361    localtime_s(&localTM, &localTime);
    362362    #else
    363     localtime_r(&localTime, &tm);
     363    localtime_r(&localTime, &localTM);
    364364    #endif
    365365   
    366     double diff = ((tm.tm_hour - offsetHour) * secondsPerHour) + ((tm.tm_min - offsetMinute) * 60);
     366    double diff = ((localTM.tm_hour - offsetHour) * secondsPerHour) + ((localTM.tm_min - offsetMinute) * 60);
    367367
    368368    if(diff < 0)
     
    392392}
    393393
    394 double dateToMS(const tm& t, double milliSeconds, bool inputIsUTC)
    395 {
    396 
    397     int day = dateToDayInYear(t.tm_year + 1900, t.tm_mon, t.tm_mday);
    398     double ms = timeToMS(t.tm_hour, t.tm_min, t.tm_sec, milliSeconds);
     394double gregorianDateTimeToMS(const GregorianDateTime& t, double milliSeconds, bool inputIsUTC)
     395{
     396
     397    int day = dateToDayInYear(t.year + 1900, t.month, t.monthDay);
     398    double ms = timeToMS(t.hour, t.minute, t.second, milliSeconds);
    399399    double result = (day * msPerDay) + ms;
    400400
     
    407407}
    408408
    409 void msToTM(double ms, bool outputIsUTC, struct tm& tm)
     409void msToGregorianDateTime(double ms, bool outputIsUTC, struct GregorianDateTime& tm)
    410410{
    411411    // input is UTC
     
    417417    }
    418418
    419     tm.tm_sec   =  msToSeconds(ms);
    420     tm.tm_min   =  msToMinutes(ms);
    421     tm.tm_hour  =  msToHours(ms);
    422     tm.tm_wday  =  msToWeekDay(ms);
    423     tm.tm_mday  =  msToDayInMonth(ms);
    424     tm.tm_yday  =  dayInYear(ms, msToYear(ms));
    425     tm.tm_mon   =  msToMonth(ms);
    426     tm.tm_year  =  msToYear(ms) - 1900;
    427     tm.tm_isdst =  dstOff != 0.0;
    428 
    429     tm.tm_gmtoff = static_cast<long>((dstOff + getUTCOffset()) / usecPerMsec);
    430     tm.tm_zone = 0;
    431 }
    432 
    433 // converting between the two tm structures
    434 tm tmToKJStm(const struct ::tm& inTm)
    435 {
    436     struct tm ret;
    437     memset(&ret, 0, sizeof(ret));
    438 
    439     ret.tm_sec   =  inTm.tm_sec;
    440     ret.tm_min   =  inTm.tm_min;
    441     ret.tm_hour  =  inTm.tm_hour;
    442     ret.tm_wday  =  inTm.tm_wday;
    443     ret.tm_mday  =  inTm.tm_mday;
    444     ret.tm_yday  =  inTm.tm_yday;
    445     ret.tm_mon   =  inTm.tm_mon;
    446     ret.tm_year  =  inTm.tm_year;
    447     ret.tm_isdst =  inTm.tm_isdst;
    448 
    449 #if !PLATFORM(WIN_OS)
    450     ret.tm_gmtoff = inTm.tm_gmtoff;
    451     ret.tm_zone = inTm.tm_zone;
    452 #endif
    453 
    454     return ret;
    455 }
    456 
    457 ::tm KJStmToTm(const struct tm& inTm)
    458 {
    459     struct ::tm ret;
    460     memset(&ret, 0, sizeof(ret));
    461 
    462     ret.tm_sec   =  inTm.tm_sec;
    463     ret.tm_min   =  inTm.tm_min;
    464     ret.tm_hour  =  inTm.tm_hour;
    465     ret.tm_wday  =  inTm.tm_wday;
    466     ret.tm_mday  =  inTm.tm_mday;
    467     ret.tm_yday  =  inTm.tm_yday;
    468     ret.tm_mon   =  inTm.tm_mon;
    469     ret.tm_year  =  inTm.tm_year;
    470     ret.tm_isdst =  inTm.tm_isdst;
    471 
    472 #if !PLATFORM(WIN_OS)
    473     ret.tm_gmtoff = inTm.tm_gmtoff;
    474     ret.tm_zone = inTm.tm_zone;
    475 #endif
    476 
    477     return ret;
     419    tm.second   =  msToSeconds(ms);
     420    tm.minute   =  msToMinutes(ms);
     421    tm.hour     =  msToHours(ms);
     422    tm.weekDay  =  msToWeekDay(ms);
     423    tm.monthDay =  msToDayInMonth(ms);
     424    tm.yearDay  =  dayInYear(ms, msToYear(ms));
     425    tm.month    =  msToMonth(ms);
     426    tm.year     =  msToYear(ms) - 1900;
     427    tm.isDST =  dstOff != 0.0;
     428
     429    tm.utcOffset = static_cast<long>((dstOff + getUTCOffset()) / usecPerMsec);
     430    tm.timeZone = NULL;
    478431}
    479432
Note: See TracChangeset for help on using the changeset viewer.