Changeset 17031 in webkit for trunk/JavaScriptCore
- Timestamp:
- Oct 13, 2006, 10:31:11 AM (19 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r17017 r17031 1 2006-10-13 Kevin McCullough <[email protected]> 2 3 Reviewed by Adam, Geoff, Darin. 4 5 Fixed displaying the UTC offset and time zone string, as well as renamed the GregorianDateTime structure and clean up. 6 7 * ChangeLog: 8 * kjs/DateMath.cpp: 9 (KJS::getUTCOffset): 10 (KJS::getDSTOffsetSimple): 11 (KJS::gregorianDateTimeToMS): 12 (KJS::msToGregorianDateTime): 13 * kjs/DateMath.h: 14 (KJS::GregorianDateTime::GregorianDateTime): 15 (KJS::GregorianDateTime::~GregorianDateTime): 16 (KJS::GregorianDateTime::toTM): 17 * kjs/date_object.cpp: 18 (KJS::gmtoffset): 19 (KJS::formatDate): 20 (KJS::formatDateUTCVariant): 21 (KJS::formatTime): 22 (KJS::fillStructuresUsingTimeArgs): 23 (KJS::fillStructuresUsingDateArgs): 24 (KJS::DateInstance::getTime): 25 (KJS::DateInstance::getUTCTime): 26 (KJS::DateProtoFunc::callAsFunction): 27 (KJS::DateObjectImp::construct): 28 (KJS::DateObjectImp::callAsFunction): 29 (KJS::DateObjectFuncImp::callAsFunction): 30 (KJS::parseDate): 31 * kjs/date_object.h: 32 33 2006-10-13 Kevin McCullough <[email protected]> 34 35 Reviewed by Adam. 36 37 Gets JavaScripCore tests running on windows. 38 39 * Scripts/run-javascriptcore-tests: 40 * Scripts/webkitdirs.pm: 41 1 42 2006-10-12 Geoffrey Garen <[email protected]> 2 43 -
trunk/JavaScriptCore/kjs/DateMath.cpp
r17015 r17031 320 320 static bool utcOffsetInitialized = false; 321 321 if (!utcOffsetInitialized) { 322 struct ::tm ltime;323 324 memset(&l time, 0, sizeof(ltime));322 tm localt; 323 324 memset(&localt, 0, sizeof(localt)); 325 325 326 326 // get the difference between this time zone and GMT 327 l time.tm_mday = 2;328 l time.tm_year = 70;329 330 utcOffset = mktime(&l time) - (hoursPerDay * secondsPerHour);327 localt.tm_mday = 2; 328 localt.tm_year = 70; 329 330 utcOffset = mktime(&localt) - (hoursPerDay * secondsPerHour); 331 331 utcOffset *= -msPerSecond; 332 332 … … 357 357 time_t localTime = static_cast<time_t>(localTimeSeconds); 358 358 359 struct ::tm tm;359 tm localTM; 360 360 #if PLATFORM(WIN_OS) 361 localtime_s(& tm, &localTime);361 localtime_s(&localTM, &localTime); 362 362 #else 363 localtime_r(&localTime, & tm);363 localtime_r(&localTime, &localTM); 364 364 #endif 365 365 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); 367 367 368 368 if(diff < 0) … … 392 392 } 393 393 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);394 double 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); 399 399 double result = (day * msPerDay) + ms; 400 400 … … 407 407 } 408 408 409 void msTo TM(double ms, bool outputIsUTC, struct tm& tm)409 void msToGregorianDateTime(double ms, bool outputIsUTC, struct GregorianDateTime& tm) 410 410 { 411 411 // input is UTC … … 417 417 } 418 418 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; 478 431 } 479 432 -
trunk/JavaScriptCore/kjs/DateMath.h
r17010 r17031 48 48 // Intentionally overridding the default tm of the system 49 49 // Not all OS' have the same members of their tm's 50 struct tm { 51 int tm_sec; 52 int tm_min; 53 int tm_hour; 54 int tm_wday; 55 int tm_mday; 56 int tm_yday; 57 int tm_mon; 58 int tm_year; 59 int tm_isdst; 60 long tm_gmtoff; 61 char* tm_zone; 50 struct GregorianDateTime { 51 GregorianDateTime() 52 { 53 second = 0; 54 minute = 0; 55 hour = 0; 56 weekDay = 0; 57 monthDay = 0; 58 yearDay = 0; 59 month = 0; 60 year = 0; 61 isDST = 0; 62 utcOffset = 0; 63 timeZone = NULL; 64 } 65 66 ~GregorianDateTime() 67 { 68 if (timeZone) 69 delete timeZone; 70 } 71 72 GregorianDateTime(const tm& inTm) 73 : second(inTm.tm_sec) 74 , minute(inTm.tm_min) 75 , hour(inTm.tm_hour) 76 , weekDay(inTm.tm_wday) 77 , monthDay(inTm.tm_mday) 78 , yearDay(inTm.tm_yday) 79 , month(inTm.tm_mon) 80 , year(inTm.tm_year) 81 , isDST(inTm.tm_isdst) 82 { 83 #if !PLATFORM(WIN_OS) 84 utcOffset = static_cast<int>(inTm.tm_gmtoff); 85 86 int inZoneSize = strlen(inTm.tm_zone) + 1; 87 timeZone = new char[inZoneSize]; 88 strncpy(timeZone, inTm.tm_zone, inZoneSize); 89 #else 90 utcOffset = 0; 91 timeZone = NULL; 92 #endif 93 } 94 95 tm toTM() const 96 { 97 tm ret; 98 memset(&ret, 0, sizeof(ret)); 99 100 ret.tm_sec = second; 101 ret.tm_min = minute; 102 ret.tm_hour = hour; 103 ret.tm_wday = weekDay; 104 ret.tm_mday = monthDay; 105 ret.tm_yday = yearDay; 106 ret.tm_mon = month; 107 ret.tm_year = year; 108 ret.tm_isdst = isDST; 109 110 #if !PLATFORM(WIN_OS) 111 ret.tm_gmtoff = static_cast<long>(utcOffset); 112 ret.tm_zone = timeZone; 113 #endif 114 115 return ret; 116 } 117 118 int second; 119 int minute; 120 int hour; 121 int weekDay; 122 int monthDay; 123 int yearDay; 124 int month; 125 int year; 126 int isDST; 127 int utcOffset; 128 char* timeZone; 62 129 }; 63 130 … … 76 143 77 144 // Exported Functions // 78 void msTo TM(double, bool outputIsUTC, struct tm&);79 double dateToMS(const tm&, double, bool inputIsUTC);145 void msToGregorianDateTime(double, bool outputIsUTC, struct GregorianDateTime&); 146 double gregorianDateTimeToMS(const GregorianDateTime&, double, bool inputIsUTC); 80 147 double getUTCOffset(); 81 82 tm tmToKJStm(const struct ::tm&);83 ::tm KJStmToTm(const struct tm&);84 148 85 149 } //namespace KJS -
trunk/JavaScriptCore/kjs/date_object.cpp
r17015 r17031 66 66 static double timeClip(double); 67 67 68 inline int gmtoffset(const tm& t)69 { 70 return static_cast<int>(t.tm_gmtoff);68 inline int gmtoffset(const GregorianDateTime& t) 69 { 70 return t.utcOffset; 71 71 } 72 72 … … 157 157 #endif // PLATFORM(MAC) 158 158 159 static UString formatDate(const tm&t)159 static UString formatDate(const GregorianDateTime &t) 160 160 { 161 161 char buffer[100]; 162 162 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); 165 165 return buffer; 166 166 } 167 167 168 static UString formatDateUTCVariant(const tm&t)168 static UString formatDateUTCVariant(const GregorianDateTime &t) 169 169 { 170 170 char buffer[100]; 171 171 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); 174 174 return buffer; 175 175 } 176 176 177 static UString formatTime(const tm&t, bool utc)177 static UString formatTime(const GregorianDateTime &t, bool utc) 178 178 { 179 179 char buffer[100]; 180 180 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); 182 182 } else { 183 183 int offset = abs(gmtoffset(t)); 184 184 char tzname[70]; 185 struct ::tm gtm = KJStmToTm(t);185 struct ::tm gtm = t.toTM(); 186 186 strftime(tzname, sizeof(tzname), "%Z", >m); 187 187 188 188 if (tzname) { 189 189 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, 191 191 gmtoffset(t) < 0 ? '-' : '+', offset / (60*60), (offset / 60) % 60, tzname); 192 192 } else { 193 193 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, 195 195 gmtoffset(t) < 0 ? '-' : '+', offset / (60*60), (offset / 60) % 60); 196 196 } … … 203 203 // 204 204 // Format of member function: f([hour,] [min,] [sec,] [ms]) 205 static void fillStructuresUsingTimeArgs(ExecState *exec, const List &args, int maxArgs, double *ms, tm*t)205 static void fillStructuresUsingTimeArgs(ExecState *exec, const List &args, int maxArgs, double *ms, GregorianDateTime *t) 206 206 { 207 207 double milliseconds = 0; … … 215 215 // hours 216 216 if (maxArgs >= 4 && idx < numArgs) { 217 t-> tm_hour = 0;217 t->hour = 0; 218 218 milliseconds += args[idx++]->toInt32(exec) * msPerHour; 219 219 } … … 221 221 // minutes 222 222 if (maxArgs >= 3 && idx < numArgs) { 223 t-> tm_min= 0;223 t->minute = 0; 224 224 milliseconds += args[idx++]->toInt32(exec) * msPerMinute; 225 225 } … … 227 227 // seconds 228 228 if (maxArgs >= 2 && idx < numArgs) { 229 t-> tm_sec= 0;229 t->second = 0; 230 230 milliseconds += args[idx++]->toInt32(exec) * msPerSecond; 231 231 } … … 245 245 // 246 246 // Format of member function: f([years,] [months,] [days]) 247 static void fillStructuresUsingDateArgs(ExecState *exec, const List &args, int maxArgs, double *ms, tm*t)247 static void fillStructuresUsingDateArgs(ExecState *exec, const List &args, int maxArgs, double *ms, GregorianDateTime *t) 248 248 { 249 249 int idx = 0; … … 256 256 // years 257 257 if (maxArgs >= 3 && idx < numArgs) 258 t-> tm_year = args[idx++]->toInt32(exec) - 1900;258 t->year = args[idx++]->toInt32(exec) - 1900; 259 259 260 260 // months 261 261 if (maxArgs >= 2 && idx < numArgs) 262 t-> tm_mon= args[idx++]->toInt32(exec);262 t->month = args[idx++]->toInt32(exec); 263 263 264 264 // days 265 265 if (idx < numArgs) { 266 t-> tm_mday = 0;266 t->monthDay = 0; 267 267 *ms += args[idx]->toInt32(exec) * msPerDay; 268 268 } … … 278 278 } 279 279 280 bool DateInstance::getTime( tm&t, int &offset) const280 bool DateInstance::getTime(GregorianDateTime &t, int &offset) const 281 281 { 282 282 double milli = internalValue()->getNumber(); … … 284 284 return false; 285 285 286 msTo TM(milli, false, t);286 msToGregorianDateTime(milli, false, t); 287 287 offset = gmtoffset(t); 288 288 return true; 289 289 } 290 290 291 bool DateInstance::getUTCTime( tm&t) const291 bool DateInstance::getUTCTime(GregorianDateTime &t) const 292 292 { 293 293 double milli = internalValue()->getNumber(); … … 295 295 return false; 296 296 297 msTo TM(milli, true, t);297 msToGregorianDateTime(milli, true, t); 298 298 return true; 299 299 } … … 305 305 return false; 306 306 307 tmt;308 msTo TM(milli, false, t);307 GregorianDateTime t; 308 msToGregorianDateTime(milli, false, t); 309 309 offset = gmtoffset(t); 310 310 return true; … … 453 453 double ms = milli - secs * msPerSecond; 454 454 455 tmt;456 msTo TM(milli, utc, t);455 GregorianDateTime t; 456 msToGregorianDateTime(milli, utc, t); 457 457 458 458 switch (id) { … … 505 505 // IE returns the full year even in getYear. 506 506 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); 509 509 case GetFullYear: 510 return jsNumber(1900 + t. tm_year);510 return jsNumber(1900 + t.year); 511 511 case GetMonth: 512 return jsNumber(t. tm_mon);512 return jsNumber(t.month); 513 513 case GetDate: 514 return jsNumber(t. tm_mday);514 return jsNumber(t.monthDay); 515 515 case GetDay: 516 return jsNumber(t. tm_wday);516 return jsNumber(t.weekDay); 517 517 case GetHours: 518 return jsNumber(t. tm_hour);518 return jsNumber(t.hour); 519 519 case GetMinutes: 520 return jsNumber(t. tm_min);520 return jsNumber(t.minute); 521 521 case GetSeconds: 522 return jsNumber(t. tm_sec);522 return jsNumber(t.second); 523 523 case GetMilliSeconds: 524 524 return jsNumber(ms); … … 552 552 break; 553 553 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); 555 555 break; 556 556 } … … 559 559 id == SetMinutes || id == SetHours || id == SetDate || 560 560 id == SetMonth || id == SetFullYear ) { 561 result = jsNumber( dateToMS(t, ms, utc));561 result = jsNumber(gregorianDateTimeToMS(t, ms, utc)); 562 562 thisDateObj->setInternalValue(result); 563 563 } … … 635 635 value = NaN; 636 636 } else { 637 tmt;637 GregorianDateTime t; 638 638 memset(&t, 0, sizeof(t)); 639 639 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; 647 647 double ms = (numArgs >= 7) ? roundValue(exec, args[6]) : 0; 648 value = dateToMS(t, ms, false);648 value = gregorianDateTimeToMS(t, ms, false); 649 649 } 650 650 } … … 659 659 { 660 660 time_t t = time(0); 661 tm ts = tmToKJStm(*localtime(&t));661 GregorianDateTime ts(*localtime(&t)); 662 662 return jsString(formatDate(ts) + " " + formatTime(ts, false)); 663 663 } … … 689 689 } 690 690 691 tmt;691 GregorianDateTime t; 692 692 memset(&t, 0, sizeof(t)); 693 693 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; 700 700 double ms = (n >= 7) ? roundValue(exec, args[6]) : 0; 701 return jsNumber( dateToMS(t, ms, true));701 return jsNumber(gregorianDateTimeToMS(t, ms, true)); 702 702 } 703 703 } … … 1056 1056 // fall back to local timezone 1057 1057 if (!haveTZ) { 1058 tmt;1058 GregorianDateTime t; 1059 1059 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); 1070 1070 } 1071 1071 -
trunk/JavaScriptCore/kjs/date_object.h
r17010 r17031 27 27 namespace KJS { 28 28 29 struct tm;29 struct GregorianDateTime; 30 30 31 31 class FunctionPrototype; … … 36 36 DateInstance(JSObject *proto); 37 37 38 bool getTime( tm &t, int &gmtoffset) const;39 bool getUTCTime( tm &t) const;40 bool getTime(double &ms, int &gmtoffset) const;41 bool getUTCTime(double &ms) const;38 bool getTime(GregorianDateTime&, int& offset) const; 39 bool getUTCTime(GregorianDateTime&) const; 40 bool getTime(double& milli, int& offset) const; 41 bool getUTCTime(double& milli) const; 42 42 43 43 virtual const ClassInfo *classInfo() const { return &info; }
Note:
See TracChangeset
for help on using the changeset viewer.