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/date_object.cpp

    r17015 r17031  
    6666static double timeClip(double);
    6767
    68 inline int gmtoffset(const tm& t)
    69 {
    70     return static_cast<int>(t.tm_gmtoff);
     68inline int gmtoffset(const GregorianDateTime& t)
     69{
     70    return t.utcOffset;
    7171}
    7272
     
    157157#endif // PLATFORM(MAC)
    158158
    159 static UString formatDate(const tm &t)
     159static UString formatDate(const GregorianDateTime &t)
    160160{
    161161    char buffer[100];
    162162    snprintf(buffer, sizeof(buffer), "%s %s %02d %04d",
    163         weekdayName[(t.tm_wday + 6) % 7],
    164         monthName[t.tm_mon], t.tm_mday, t.tm_year + 1900);
     163        weekdayName[(t.weekDay + 6) % 7],
     164        monthName[t.month], t.monthDay, t.year + 1900);
    165165    return buffer;
    166166}
    167167
    168 static UString formatDateUTCVariant(const tm &t)
     168static UString formatDateUTCVariant(const GregorianDateTime &t)
    169169{
    170170    char buffer[100];
    171171    snprintf(buffer, sizeof(buffer), "%s, %02d %s %04d",
    172         weekdayName[(t.tm_wday + 6) % 7],
    173         t.tm_mday, monthName[t.tm_mon], t.tm_year + 1900);
     172        weekdayName[(t.weekDay + 6) % 7],
     173        t.monthDay, monthName[t.month], t.year + 1900);
    174174    return buffer;
    175175}
    176176
    177 static UString formatTime(const tm &t, bool utc)
     177static UString formatTime(const GregorianDateTime &t, bool utc)
    178178{
    179179    char buffer[100];
    180180    if (utc) {
    181         snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d GMT", t.tm_hour, t.tm_min, t.tm_sec);
     181        snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d GMT", t.hour, t.minute, t.second);
    182182    } else {
    183183        int offset = abs(gmtoffset(t));
    184184        char tzname[70];
    185         struct ::tm gtm = KJStmToTm(t);
     185        struct ::tm gtm = t.toTM();
    186186        strftime(tzname, sizeof(tzname), "%Z", &gtm);
    187187
    188188        if (tzname) {
    189189            snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d GMT%c%02d%02d (%s)",
    190                 t.tm_hour, t.tm_min, t.tm_sec,
     190                t.hour, t.minute, t.second,
    191191                gmtoffset(t) < 0 ? '-' : '+', offset / (60*60), (offset / 60) % 60, tzname);
    192192        } else {
    193193            snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d GMT%c%02d%02d",
    194                 t.tm_hour, t.tm_min, t.tm_sec,
     194                t.hour, t.minute, t.second,
    195195                gmtoffset(t) < 0 ? '-' : '+', offset / (60*60), (offset / 60) % 60);
    196196        }
     
    203203//
    204204// Format of member function: f([hour,] [min,] [sec,] [ms])
    205 static void fillStructuresUsingTimeArgs(ExecState *exec, const List &args, int maxArgs, double *ms, tm *t)
     205static void fillStructuresUsingTimeArgs(ExecState *exec, const List &args, int maxArgs, double *ms, GregorianDateTime *t)
    206206{
    207207    double milliseconds = 0;
     
    215215    // hours
    216216    if (maxArgs >= 4 && idx < numArgs) {
    217         t->tm_hour = 0;
     217        t->hour = 0;
    218218        milliseconds += args[idx++]->toInt32(exec) * msPerHour;
    219219    }
     
    221221    // minutes
    222222    if (maxArgs >= 3 && idx < numArgs) {
    223         t->tm_min = 0;
     223        t->minute = 0;
    224224        milliseconds += args[idx++]->toInt32(exec) * msPerMinute;
    225225    }
     
    227227    // seconds
    228228    if (maxArgs >= 2 && idx < numArgs) {
    229         t->tm_sec = 0;
     229        t->second = 0;
    230230        milliseconds += args[idx++]->toInt32(exec) * msPerSecond;
    231231    }
     
    245245//
    246246// Format of member function: f([years,] [months,] [days])
    247 static void fillStructuresUsingDateArgs(ExecState *exec, const List &args, int maxArgs, double *ms, tm *t)
     247static void fillStructuresUsingDateArgs(ExecState *exec, const List &args, int maxArgs, double *ms, GregorianDateTime *t)
    248248{
    249249    int idx = 0;
     
    256256    // years
    257257    if (maxArgs >= 3 && idx < numArgs)
    258         t->tm_year = args[idx++]->toInt32(exec) - 1900;
     258        t->year = args[idx++]->toInt32(exec) - 1900;
    259259 
    260260    // months
    261261    if (maxArgs >= 2 && idx < numArgs)
    262         t->tm_mon = args[idx++]->toInt32(exec);
     262        t->month = args[idx++]->toInt32(exec);
    263263 
    264264    // days
    265265    if (idx < numArgs) {
    266         t->tm_mday = 0;
     266        t->monthDay = 0;
    267267        *ms += args[idx]->toInt32(exec) * msPerDay;
    268268    }
     
    278278}
    279279
    280 bool DateInstance::getTime(tm &t, int &offset) const
     280bool DateInstance::getTime(GregorianDateTime &t, int &offset) const
    281281{
    282282    double milli = internalValue()->getNumber();
     
    284284        return false;
    285285   
    286     msToTM(milli, false, t);
     286    msToGregorianDateTime(milli, false, t);
    287287    offset = gmtoffset(t);
    288288    return true;
    289289}
    290290
    291 bool DateInstance::getUTCTime(tm &t) const
     291bool DateInstance::getUTCTime(GregorianDateTime &t) const
    292292{
    293293    double milli = internalValue()->getNumber();
     
    295295        return false;
    296296   
    297     msToTM(milli, true, t);
     297    msToGregorianDateTime(milli, true, t);
    298298    return true;
    299299}
     
    305305        return false;
    306306   
    307     tm t;
    308     msToTM(milli, false, t);
     307    GregorianDateTime t;
     308    msToGregorianDateTime(milli, false, t);
    309309    offset = gmtoffset(t);
    310310    return true;
     
    453453  double ms = milli - secs * msPerSecond;
    454454
    455   tm t;
    456   msToTM(milli, utc, t);
     455  GregorianDateTime t;
     456  msToGregorianDateTime(milli, utc, t);
    457457
    458458  switch (id) {
     
    505505    // IE returns the full year even in getYear.
    506506    if (exec->dynamicInterpreter()->compatMode() == Interpreter::IECompat)
    507       return jsNumber(1900 + t.tm_year);
    508     return jsNumber(t.tm_year);
     507      return jsNumber(1900 + t.year);
     508    return jsNumber(t.year);
    509509  case GetFullYear:
    510     return jsNumber(1900 + t.tm_year);
     510    return jsNumber(1900 + t.year);
    511511  case GetMonth:
    512     return jsNumber(t.tm_mon);
     512    return jsNumber(t.month);
    513513  case GetDate:
    514     return jsNumber(t.tm_mday);
     514    return jsNumber(t.monthDay);
    515515  case GetDay:
    516     return jsNumber(t.tm_wday);
     516    return jsNumber(t.weekDay);
    517517  case GetHours:
    518     return jsNumber(t.tm_hour);
     518    return jsNumber(t.hour);
    519519  case GetMinutes:
    520     return jsNumber(t.tm_min);
     520    return jsNumber(t.minute);
    521521  case GetSeconds:
    522     return jsNumber(t.tm_sec);
     522    return jsNumber(t.second);
    523523  case GetMilliSeconds:
    524524    return jsNumber(ms);
     
    552552    break;
    553553  case SetYear:
    554     t.tm_year = (args[0]->toInt32(exec) > 99 || args[0]->toInt32(exec) < 0) ? args[0]->toInt32(exec) - 1900 : args[0]->toInt32(exec);
     554    t.year = (args[0]->toInt32(exec) > 99 || args[0]->toInt32(exec) < 0) ? args[0]->toInt32(exec) - 1900 : args[0]->toInt32(exec);
    555555    break;
    556556  }
     
    559559      id == SetMinutes || id == SetHours || id == SetDate ||
    560560      id == SetMonth || id == SetFullYear ) {
    561     result = jsNumber(dateToMS(t, ms, utc));
     561    result = jsNumber(gregorianDateTimeToMS(t, ms, utc));
    562562    thisDateObj->setInternalValue(result);
    563563  }
     
    635635      value = NaN;
    636636    } else {
    637       tm t;
     637      GregorianDateTime t;
    638638      memset(&t, 0, sizeof(t));
    639639      int year = args[0]->toInt32(exec);
    640       t.tm_year = (year >= 0 && year <= 99) ? year : year - 1900;
    641       t.tm_mon = args[1]->toInt32(exec);
    642       t.tm_mday = (numArgs >= 3) ? args[2]->toInt32(exec) : 1;
    643       t.tm_hour = (numArgs >= 4) ? args[3]->toInt32(exec) : 0;
    644       t.tm_min = (numArgs >= 5) ? args[4]->toInt32(exec) : 0;
    645       t.tm_sec = (numArgs >= 6) ? args[5]->toInt32(exec) : 0;
    646       t.tm_isdst = -1;
     640      t.year = (year >= 0 && year <= 99) ? year : year - 1900;
     641      t.month = args[1]->toInt32(exec);
     642      t.monthDay = (numArgs >= 3) ? args[2]->toInt32(exec) : 1;
     643      t.hour = (numArgs >= 4) ? args[3]->toInt32(exec) : 0;
     644      t.minute = (numArgs >= 5) ? args[4]->toInt32(exec) : 0;
     645      t.second = (numArgs >= 6) ? args[5]->toInt32(exec) : 0;
     646      t.isDST = -1;
    647647      double ms = (numArgs >= 7) ? roundValue(exec, args[6]) : 0;
    648       value = dateToMS(t, ms, false);
     648      value = gregorianDateTimeToMS(t, ms, false);
    649649    }
    650650  }
     
    659659{
    660660    time_t t = time(0);
    661     tm ts = tmToKJStm(*localtime(&t));
     661    GregorianDateTime ts(*localtime(&t));
    662662    return jsString(formatDate(ts) + " " + formatTime(ts, false));
    663663}
     
    689689    }
    690690
    691     tm t;
     691    GregorianDateTime t;
    692692    memset(&t, 0, sizeof(t));
    693693    int year = args[0]->toInt32(exec);
    694     t.tm_year = (year >= 0 && year <= 99) ? year : year - 1900;
    695     t.tm_mon = args[1]->toInt32(exec);
    696     t.tm_mday = (n >= 3) ? args[2]->toInt32(exec) : 1;
    697     t.tm_hour = (n >= 4) ? args[3]->toInt32(exec) : 0;
    698     t.tm_min = (n >= 5) ? args[4]->toInt32(exec) : 0;
    699     t.tm_sec = (n >= 6) ? args[5]->toInt32(exec) : 0;
     694    t.year = (year >= 0 && year <= 99) ? year : year - 1900;
     695    t.month = args[1]->toInt32(exec);
     696    t.monthDay = (n >= 3) ? args[2]->toInt32(exec) : 1;
     697    t.hour = (n >= 4) ? args[3]->toInt32(exec) : 0;
     698    t.minute = (n >= 5) ? args[4]->toInt32(exec) : 0;
     699    t.second = (n >= 6) ? args[5]->toInt32(exec) : 0;
    700700    double ms = (n >= 7) ? roundValue(exec, args[6]) : 0;
    701     return jsNumber(dateToMS(t, ms, true));
     701    return jsNumber(gregorianDateTimeToMS(t, ms, true));
    702702  }
    703703}
     
    10561056    // fall back to local timezone
    10571057    if (!haveTZ) {
    1058         tm t;
     1058        GregorianDateTime t;
    10591059        memset(&t, 0, sizeof(tm));
    1060         t.tm_mday = day;
    1061         t.tm_mon = month;
    1062         t.tm_year = year - 1900;
    1063         t.tm_isdst = -1;
    1064         t.tm_sec = second;
    1065         t.tm_min = minute;
    1066         t.tm_hour = hour;
    1067 
    1068         // Use our dateToMS() rather than mktime() as the latter can't handle the full year range.
    1069         return dateToMS(t, 0, false);
     1060        t.monthDay = day;
     1061        t.month = month;
     1062        t.year = year - 1900;
     1063        t.isDST = -1;
     1064        t.second = second;
     1065        t.minute = minute;
     1066        t.hour = hour;
     1067
     1068        // Use our gregorianDateTimeToMS() rather than mktime() as the latter can't handle the full year range.
     1069        return gregorianDateTimeToMS(t, 0, false);
    10701070    }
    10711071
Note: See TracChangeset for help on using the changeset viewer.