OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Platform-specific code for Win32. | 5 // Platform-specific code for Win32. |
6 | 6 |
7 // Secure API functions are not available using MinGW with msvcrt.dll | 7 // Secure API functions are not available using MinGW with msvcrt.dll |
8 // on Windows XP. Make sure MINGW_HAS_SECURE_API is not defined to | 8 // on Windows XP. Make sure MINGW_HAS_SECURE_API is not defined to |
9 // disable definition of secure API functions in standard headers that | 9 // disable definition of secure API functions in standard headers that |
10 // would conflict with our own implementation. | 10 // would conflict with our own implementation. |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 init_ticks = ticks_now = timeGetTime(); | 339 init_ticks = ticks_now = timeGetTime(); |
340 initialized = true; | 340 initialized = true; |
341 } | 341 } |
342 | 342 |
343 // Finally, compute the actual time. Why is this so hard. | 343 // Finally, compute the actual time. Why is this so hard. |
344 DWORD elapsed = ticks_now - init_ticks; | 344 DWORD elapsed = ticks_now - init_ticks; |
345 this->time_.t_ = init_time.t_ + (static_cast<int64_t>(elapsed) * 10000); | 345 this->time_.t_ = init_time.t_ + (static_cast<int64_t>(elapsed) * 10000); |
346 } | 346 } |
347 | 347 |
348 | 348 |
349 int64_t FileTimeToInt64(FILETIME ft) { | |
350 ULARGE_INTEGER result; | |
351 result.LowPart = ft.dwLowDateTime; | |
352 result.HighPart = ft.dwHighDateTime; | |
353 return static_cast<int64_t>(result.QuadPart); | |
354 } | |
355 | |
356 | |
357 // Return the local timezone offset in milliseconds east of UTC. This | 349 // Return the local timezone offset in milliseconds east of UTC. This |
358 // takes into account whether daylight saving is in effect at the time. | 350 // takes into account whether daylight saving is in effect at the time. |
359 // Only times in the 32-bit Unix range may be passed to this function. | 351 // Only times in the 32-bit Unix range may be passed to this function. |
360 // Also, adding the time-zone offset to the input must not overflow. | 352 // Also, adding the time-zone offset to the input must not overflow. |
361 // The function EquivalentTime() in date.js guarantees this. | 353 // The function EquivalentTime() in date.js guarantees this. |
362 int64_t Win32Time::LocalOffset(TimezoneCache* cache) { | 354 int64_t Win32Time::LocalOffset(TimezoneCache* cache) { |
363 FILETIME local; | 355 cache->InitializeIfNeeded(); |
364 SYSTEMTIME system_utc, system_local; | 356 |
365 FileTimeToSystemTime(&time_.ft_, &system_utc); | 357 Win32Time rounded_to_second(*this); |
366 SystemTimeToTzSpecificLocalTime(NULL, &system_utc, &system_local); | 358 rounded_to_second.t() = |
367 SystemTimeToFileTime(&system_local, &local); | 359 rounded_to_second.t() / 1000 / kTimeScaler * 1000 * kTimeScaler; |
368 return (FileTimeToInt64(local) - FileTimeToInt64(time_.ft_)) / kTimeScaler; | 360 // Convert to local time using POSIX localtime function. |
| 361 // Windows XP Service Pack 3 made SystemTimeToTzSpecificLocalTime() |
| 362 // very slow. Other browsers use localtime(). |
| 363 |
| 364 // Convert from JavaScript milliseconds past 1/1/1970 0:00:00 to |
| 365 // POSIX seconds past 1/1/1970 0:00:00. |
| 366 double unchecked_posix_time = rounded_to_second.ToJSTime() / 1000; |
| 367 if (unchecked_posix_time > INT_MAX || unchecked_posix_time < 0) { |
| 368 return 0; |
| 369 } |
| 370 // Because _USE_32BIT_TIME_T is defined, time_t is a 32-bit int. |
| 371 time_t posix_time = static_cast<time_t>(unchecked_posix_time); |
| 372 |
| 373 // Convert to local time, as struct with fields for day, hour, year, etc. |
| 374 tm posix_local_time_struct; |
| 375 if (localtime_s(&posix_local_time_struct, &posix_time)) return 0; |
| 376 |
| 377 if (posix_local_time_struct.tm_isdst > 0) { |
| 378 return (cache->tzinfo_.Bias + cache->tzinfo_.DaylightBias) * -kMsPerMinute; |
| 379 } else if (posix_local_time_struct.tm_isdst == 0) { |
| 380 return (cache->tzinfo_.Bias + cache->tzinfo_.StandardBias) * -kMsPerMinute; |
| 381 } else { |
| 382 return cache->tzinfo_.Bias * -kMsPerMinute; |
| 383 } |
369 } | 384 } |
370 | 385 |
371 | 386 |
372 // Return whether or not daylight savings time is in effect at this time. | 387 // Return whether or not daylight savings time is in effect at this time. |
373 bool Win32Time::InDST(TimezoneCache* cache) { | 388 bool Win32Time::InDST(TimezoneCache* cache) { |
374 cache->InitializeIfNeeded(); | 389 cache->InitializeIfNeeded(); |
375 | 390 |
376 // Determine if DST is in effect at the specified time. | 391 // Determine if DST is in effect at the specified time. |
377 bool in_dst = false; | 392 bool in_dst = false; |
378 if (cache->tzinfo_.StandardDate.wMonth != 0 || | 393 if (cache->tzinfo_.StandardDate.wMonth != 0 || |
(...skipping 987 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1366 DCHECK(result); | 1381 DCHECK(result); |
1367 } | 1382 } |
1368 | 1383 |
1369 | 1384 |
1370 | 1385 |
1371 void Thread::YieldCPU() { | 1386 void Thread::YieldCPU() { |
1372 Sleep(0); | 1387 Sleep(0); |
1373 } | 1388 } |
1374 | 1389 |
1375 } } // namespace v8::base | 1390 } } // namespace v8::base |
OLD | NEW |