Changeset 17010 in webkit for trunk/JavaScriptCore/kjs/DateMath.cpp
- Timestamp:
- Oct 12, 2006, 10:58:09 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/DateMath.cpp
r16855 r17010 271 271 } 272 272 273 static inline double timeToM seconds(double hour, double min, double sec, double ms)273 static inline double timeToMS(double hour, double min, double sec, double ms) 274 274 { 275 275 return (((hour * minutesPerHour + min) * secondsPerMinute + sec) * msPerSecond + ms); … … 320 320 static bool utcOffsetInitialized = false; 321 321 if (!utcOffsetInitialized) { 322 struct tm ltime; 323 324 ltime.tm_sec = 0; 325 ltime.tm_min = 0; 326 ltime.tm_hour = 0; 327 ltime.tm_mon = 0; 328 ltime.tm_wday = 0; 329 ltime.tm_yday = 0; 330 ltime.tm_isdst = 0; 331 322 struct ::tm ltime; 323 324 memset(<ime, 0, sizeof(ltime)); 325 332 326 // get the difference between this time zone and GMT 333 327 ltime.tm_mday = 2; 334 328 ltime.tm_year = 70; 335 336 #if !PLATFORM(WIN_OS)337 ltime.tm_zone = 0;338 ltime.tm_gmtoff = 0;339 #endif340 329 341 330 utcOffset = mktime(<ime) - (hoursPerDay * secondsPerHour); … … 359 348 localTimeSeconds += secondsPerDay; 360 349 361 struct tm prtm;362 350 double offsetTime = (localTimeSeconds * usecPerMsec) + getUTCOffset() ; 363 351 364 prtm.tm_hour = msToHours(offsetTime); 365 prtm.tm_min = msToMinutes(offsetTime); 352 // Offset from UTC but doesn't include DST obviously 353 int offsetHour = msToHours(offsetTime); 354 int offsetMinute = msToMinutes(offsetTime); 366 355 367 356 // FIXME: time_t has a potential problem in 2038 368 357 time_t localTime = static_cast<time_t>(localTimeSeconds); 369 358 370 struct tm tm;359 struct ::tm tm; 371 360 #if PLATFORM(WIN_OS) 372 361 localtime_s(&tm, &localTime); … … 374 363 localtime_r(&localTime, &tm); 375 364 #endif 376 377 double diff = ((tm.tm_hour - prtm.tm_hour) * secondsPerHour) + ((tm.tm_min - prtm.tm_min) * 60);365 366 double diff = ((tm.tm_hour - offsetHour) * secondsPerHour) + ((tm.tm_min - offsetMinute) * 60); 378 367 379 368 if(diff < 0) … … 383 372 } 384 373 385 // get the DST offset the time passed in 374 // Get the DST offset the time passed in 375 // ms is in UTC 386 376 static double getDSTOffset(double ms) 387 377 { … … 402 392 } 403 393 404 double dateToMseconds(tm* t, double ms, bool inputIsUTC) 405 { 406 int day = dateToDayInYear(t->tm_year + 1900, t->tm_mon, t->tm_mday); 407 double msec_time = timeToMseconds(t->tm_hour, t->tm_min, t->tm_sec, ms); 408 double result = (day * msPerDay) + msec_time; 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); 399 double result = (day * msPerDay) + ms; 409 400 410 401 if(!inputIsUTC) { // convert to UTC 411 result -= getUTCOffset(); 402 result -= getUTCOffset(); 412 403 result -= getDSTOffset(result); 413 404 } … … 436 427 tm.tm_isdst = dstOff != 0.0; 437 428 438 // All other OS' seems to have these fields 429 tm.tm_gmtoff = (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 439 449 #if !PLATFORM(WIN_OS) 440 struct tm xtm; 441 // FIXME: time_t has a potential problem in 2038 442 time_t seconds = static_cast<time_t>(ms/usecPerMsec); 443 localtime_r(&seconds, &xtm); 444 tm.tm_gmtoff = xtm.tm_gmtoff; 445 tm.tm_zone = xtm.tm_zone; 450 ret.tm_gmtoff = inTm.tm_gmtoff; 451 ret.tm_zone = inTm.tm_zone; 446 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; 447 478 } 448 479
Note:
See TracChangeset
for help on using the changeset viewer.