Changeset 17031 in webkit for trunk/JavaScriptCore/kjs/DateMath.cpp
- Timestamp:
- Oct 13, 2006, 10:31:11 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.