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

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

Issue 12824: Change Windows daylight saving time calculations to... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 12 years 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 | « src/date-delay.js ('k') | 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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 #define NOMCX 49 #define NOMCX
50 #endif 50 #endif
51 // Require Windows 2000 or higher (this is required for the IsDebuggerPresent 51 // Require Windows 2000 or higher (this is required for the IsDebuggerPresent
52 // function to be present). 52 // function to be present).
53 #ifndef _WIN32_WINNT 53 #ifndef _WIN32_WINNT
54 #define _WIN32_WINNT 0x500 54 #define _WIN32_WINNT 0x500
55 #endif 55 #endif
56 56
57 #include <windows.h> 57 #include <windows.h>
58 58
59 #include <time.h> // For LocalOffset() implementation.
59 #include <mmsystem.h> // For timeGetTime(). 60 #include <mmsystem.h> // For timeGetTime().
60 #include <dbghelp.h> // For SymLoadModule64 and al. 61 #include <dbghelp.h> // For SymLoadModule64 and al.
61 #include <tlhelp32.h> // For Module32First and al. 62 #include <tlhelp32.h> // For Module32First and al.
62 63
63 // These aditional WIN32 includes have to be right here as the #undef's below 64 // These aditional WIN32 includes have to be right here as the #undef's below
64 // makes it impossible to have them elsewhere. 65 // makes it impossible to have them elsewhere.
65 #include <winsock2.h> 66 #include <winsock2.h>
66 #include <process.h> // for _beginthreadex() 67 #include <process.h> // for _beginthreadex()
67 #include <stdlib.h> 68 #include <stdlib.h>
68 69
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 } 317 }
317 318
318 319
319 // Initialize timezone information. The timezone information is obtained from 320 // Initialize timezone information. The timezone information is obtained from
320 // windows. If we cannot get the timezone information we fall back to CET. 321 // windows. If we cannot get the timezone information we fall back to CET.
321 // Please notice that this code is not thread-safe. 322 // Please notice that this code is not thread-safe.
322 void Time::TzSet() { 323 void Time::TzSet() {
323 // Just return if timezone information has already been initialized. 324 // Just return if timezone information has already been initialized.
324 if (tz_initialized_) return; 325 if (tz_initialized_) return;
325 326
327 // Initialize POSIX time zone data.
328 _tzset();
326 // Obtain timezone information from operating system. 329 // Obtain timezone information from operating system.
327 memset(&tzinfo_, 0, sizeof(tzinfo_)); 330 memset(&tzinfo_, 0, sizeof(tzinfo_));
328 if (GetTimeZoneInformation(&tzinfo_) == TIME_ZONE_ID_INVALID) { 331 if (GetTimeZoneInformation(&tzinfo_) == TIME_ZONE_ID_INVALID) {
329 // If we cannot get timezone information we fall back to CET. 332 // If we cannot get timezone information we fall back to CET.
330 tzinfo_.Bias = -60; 333 tzinfo_.Bias = -60;
331 tzinfo_.StandardDate.wMonth = 10; 334 tzinfo_.StandardDate.wMonth = 10;
332 tzinfo_.StandardDate.wDay = 5; 335 tzinfo_.StandardDate.wDay = 5;
333 tzinfo_.StandardDate.wHour = 3; 336 tzinfo_.StandardDate.wHour = 3;
334 tzinfo_.StandardBias = 0; 337 tzinfo_.StandardBias = 0;
335 tzinfo_.DaylightDate.wMonth = 3; 338 tzinfo_.DaylightDate.wMonth = 3;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 // 392 //
390 // To use the clock, we use GetSystemTimeAsFileTime as our base; 393 // To use the clock, we use GetSystemTimeAsFileTime as our base;
391 // and then use timeGetTime to extrapolate current time from the 394 // and then use timeGetTime to extrapolate current time from the
392 // start time. To deal with rollovers, we resync the clock 395 // start time. To deal with rollovers, we resync the clock
393 // any time when more than kMaxClockElapsedTime has passed or 396 // any time when more than kMaxClockElapsedTime has passed or
394 // whenever timeGetTime creates a rollover. 397 // whenever timeGetTime creates a rollover.
395 398
396 static bool initialized = false; 399 static bool initialized = false;
397 static TimeStamp init_time; 400 static TimeStamp init_time;
398 static DWORD init_ticks; 401 static DWORD init_ticks;
399 static const int kHundredNanosecondsPerSecond = 10000; 402 static const int64_t kHundredNanosecondsPerSecond = 10000000;
400 static const int kMaxClockElapsedTime = 403 static const int64_t kMaxClockElapsedTime =
401 60*60*24*kHundredNanosecondsPerSecond; // 1 day 404 60*kHundredNanosecondsPerSecond; // 1 minute
402 405
403 // If we are uninitialized, we need to resync the clock. 406 // If we are uninitialized, we need to resync the clock.
404 bool needs_resync = !initialized; 407 bool needs_resync = !initialized;
405 408
406 // Get the current time. 409 // Get the current time.
407 TimeStamp time_now; 410 TimeStamp time_now;
408 GetSystemTimeAsFileTime(&time_now.ft_); 411 GetSystemTimeAsFileTime(&time_now.ft_);
409 DWORD ticks_now = timeGetTime(); 412 DWORD ticks_now = timeGetTime();
410 413
411 // Check if we need to resync due to clock rollover. 414 // Check if we need to resync due to clock rollover.
(...skipping 10 matching lines...) Expand all
422 } 425 }
423 426
424 // Finally, compute the actual time. Why is this so hard. 427 // Finally, compute the actual time. Why is this so hard.
425 DWORD elapsed = ticks_now - init_ticks; 428 DWORD elapsed = ticks_now - init_ticks;
426 this->time_.t_ = init_time.t_ + (static_cast<int64_t>(elapsed) * 10000); 429 this->time_.t_ = init_time.t_ + (static_cast<int64_t>(elapsed) * 10000);
427 } 430 }
428 431
429 432
430 // Return the local timezone offset in milliseconds east of UTC. This 433 // Return the local timezone offset in milliseconds east of UTC. This
431 // takes into account whether daylight saving is in effect at the time. 434 // takes into account whether daylight saving is in effect at the time.
435 // Only times in the 32-bit Unix range may be passed to this function.
436 // Also, adding the time-zone offset to the input must not overflow.
437 // The function EquivalentTime() in date-delay.js guarantees this.
432 int64_t Time::LocalOffset() { 438 int64_t Time::LocalOffset() {
433 // Initialize timezone information, if needed. 439 // Initialize timezone information, if needed.
434 TzSet(); 440 TzSet();
435 441
436 // Convert timestamp to date/time components. These are now in UTC 442 Time rounded_to_second(*this);
437 // format. NB: Please do not replace the following three calls with one 443 rounded_to_second.t() = rounded_to_second.t() / 1000 / kTimeScaler *
438 // call to FileTimeToLocalFileTime(), because it does not handle 444 1000 * kTimeScaler;
439 // daylight saving correctly. 445 // Convert to local time using POSIX localtime function.
440 SYSTEMTIME utc; 446 // Windows XP Service Pack 3 made SystemTimeToTzSpecificLocalTime()
441 FileTimeToSystemTime(&ft(), &utc); 447 // very slow. Other browsers use localtime().
442 448
443 // Convert to local time, using timezone information. 449 // Convert from JavaScript milliseconds past 1/1/1970 0:00:00 to
444 SYSTEMTIME local; 450 // POSIX seconds past 1/1/1970 0:00:00.
445 SystemTimeToTzSpecificLocalTime(&tzinfo_, &utc, &local); 451 double unchecked_posix_time = rounded_to_second.ToJSTime() / 1000;
452 if (unchecked_posix_time > INT_MAX || unchecked_posix_time < 0) {
453 return 0;
454 }
455 // Because _USE_32BIT_TIME_T is defined, time_t is a 32-bit int.
456 time_t posix_time = static_cast<time_t>(unchecked_posix_time);
446 457
447 // Convert local time back to a timestamp. This timestamp now 458 // Convert to local time, as struct with fields for day, hour, year, etc.
448 // has a bias similar to the local timezone bias in effect 459 tm posix_local_time_struct;
449 // at the time of the original timestamp. 460 if (localtime_s(&posix_local_time_struct, &posix_time)) return 0;
450 Time localtime; 461 // Convert local time in struct to POSIX time as if it were a UTC time.
451 SystemTimeToFileTime(&local, &localtime.ft()); 462 time_t local_posix_time = _mkgmtime(&posix_local_time_struct);
463 Time localtime(1000.0 * local_posix_time);
452 464
453 // The difference between the new local timestamp and the original 465 return localtime.Diff(&rounded_to_second);
454 // timestamp and is the local timezone offset.
455 return localtime.Diff(this);
456 } 466 }
457 467
458 468
459 // Return whether or not daylight savings time is in effect at this time. 469 // Return whether or not daylight savings time is in effect at this time.
460 bool Time::InDST() { 470 bool Time::InDST() {
461 // Initialize timezone information, if needed. 471 // Initialize timezone information, if needed.
462 TzSet(); 472 TzSet();
463 473
464 // Determine if DST is in effect at the specified time. 474 // Determine if DST is in effect at the specified time.
465 bool in_dst = false; 475 bool in_dst = false;
(...skipping 1102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1568 1578
1569 // Release the thread handles 1579 // Release the thread handles
1570 CloseHandle(data_->sampler_thread_); 1580 CloseHandle(data_->sampler_thread_);
1571 CloseHandle(data_->profiled_thread_); 1581 CloseHandle(data_->profiled_thread_);
1572 } 1582 }
1573 1583
1574 1584
1575 #endif // ENABLE_LOGGING_AND_PROFILING 1585 #endif // ENABLE_LOGGING_AND_PROFILING
1576 1586
1577 } } // namespace v8::internal 1587 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/date-delay.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698