Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: src/base/platform/platform-win32.cc

Issue 654843012: Windows: use SystemTimeToTzSpecificLocalTime instead of localtime_s. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
349 // Return the local timezone offset in milliseconds east of UTC. This 357 // Return the local timezone offset in milliseconds east of UTC. This
350 // takes into account whether daylight saving is in effect at the time. 358 // takes into account whether daylight saving is in effect at the time.
351 // Only times in the 32-bit Unix range may be passed to this function. 359 // Only times in the 32-bit Unix range may be passed to this function.
352 // Also, adding the time-zone offset to the input must not overflow. 360 // Also, adding the time-zone offset to the input must not overflow.
353 // The function EquivalentTime() in date.js guarantees this. 361 // The function EquivalentTime() in date.js guarantees this.
354 int64_t Win32Time::LocalOffset(TimezoneCache* cache) { 362 int64_t Win32Time::LocalOffset(TimezoneCache* cache) {
355 cache->InitializeIfNeeded(); 363 FILETIME local;
356 364 SYSTEMTIME system_utc, system_local;
357 Win32Time rounded_to_second(*this); 365 FileTimeToSystemTime(&time_.ft_, &system_utc);
358 rounded_to_second.t() = rounded_to_second.t() / 1000 / kTimeScaler * 366 SystemTimeToTzSpecificLocalTime(NULL, &system_utc, &system_local);
359 1000 * kTimeScaler; 367 SystemTimeToFileTime(&system_local, &local);
360 // Convert to local time using POSIX localtime function. 368 return (FileTimeToInt64(local) - FileTimeToInt64(time_.ft_)) / kTimeScaler;
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 }
384 } 369 }
385 370
386 371
387 // Return whether or not daylight savings time is in effect at this time. 372 // Return whether or not daylight savings time is in effect at this time.
388 bool Win32Time::InDST(TimezoneCache* cache) { 373 bool Win32Time::InDST(TimezoneCache* cache) {
389 cache->InitializeIfNeeded(); 374 cache->InitializeIfNeeded();
390 375
391 // Determine if DST is in effect at the specified time. 376 // Determine if DST is in effect at the specified time.
392 bool in_dst = false; 377 bool in_dst = false;
393 if (cache->tzinfo_.StandardDate.wMonth != 0 || 378 if (cache->tzinfo_.StandardDate.wMonth != 0 ||
(...skipping 987 matching lines...) Expand 10 before | Expand all | Expand 10 after
1381 DCHECK(result); 1366 DCHECK(result);
1382 } 1367 }
1383 1368
1384 1369
1385 1370
1386 void Thread::YieldCPU() { 1371 void Thread::YieldCPU() {
1387 Sleep(0); 1372 Sleep(0);
1388 } 1373 }
1389 1374
1390 } } // namespace v8::base 1375 } } // namespace v8::base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698