OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/globals.h" | 5 #include "vm/globals.h" |
6 #if defined(TARGET_OS_WINDOWS) | 6 #if defined(TARGET_OS_WINDOWS) |
7 | 7 |
8 #include "vm/os.h" | 8 #include "vm/os.h" |
9 | 9 |
10 #include <malloc.h> // NOLINT | 10 #include <malloc.h> // NOLINT |
(...skipping 16 matching lines...) Expand all Loading... | |
27 | 27 |
28 | 28 |
29 intptr_t OS::ProcessId() { | 29 intptr_t OS::ProcessId() { |
30 return static_cast<intptr_t>(GetCurrentProcessId()); | 30 return static_cast<intptr_t>(GetCurrentProcessId()); |
31 } | 31 } |
32 | 32 |
33 | 33 |
34 // As a side-effect sets the globals _timezone, _daylight and _tzname. | 34 // As a side-effect sets the globals _timezone, _daylight and _tzname. |
35 static bool LocalTime(int64_t seconds_since_epoch, tm* tm_result) { | 35 static bool LocalTime(int64_t seconds_since_epoch, tm* tm_result) { |
36 time_t seconds = static_cast<time_t>(seconds_since_epoch); | 36 time_t seconds = static_cast<time_t>(seconds_since_epoch); |
37 if (seconds != seconds_since_epoch) return false; | 37 if (seconds != seconds_since_epoch) { |
38 return false; | |
39 } | |
38 // localtime_s implicitly sets _timezone, _daylight and _tzname. | 40 // localtime_s implicitly sets _timezone, _daylight and _tzname. |
39 errno_t error_code = localtime_s(tm_result, &seconds); | 41 errno_t error_code = localtime_s(tm_result, &seconds); |
40 return error_code == 0; | 42 return error_code == 0; |
41 } | 43 } |
42 | 44 |
43 | 45 |
44 static int GetDaylightSavingBiasInSeconds() { | 46 static int GetDaylightSavingBiasInSeconds() { |
45 TIME_ZONE_INFORMATION zone_information; | 47 TIME_ZONE_INFORMATION zone_information; |
46 memset(&zone_information, 0, sizeof(zone_information)); | 48 memset(&zone_information, 0, sizeof(zone_information)); |
47 if (GetTimeZoneInformation(&zone_information) == TIME_ZONE_ID_INVALID) { | 49 if (GetTimeZoneInformation(&zone_information) == TIME_ZONE_ID_INVALID) { |
48 // By default the daylight saving offset is an hour. | 50 // By default the daylight saving offset is an hour. |
49 return -60 * 60; | 51 return -60 * 60; |
50 } else { | 52 } else { |
51 return static_cast<int>(zone_information.DaylightBias * 60); | 53 return static_cast<int>(zone_information.DaylightBias * 60); |
52 } | 54 } |
53 } | 55 } |
54 | 56 |
55 | 57 |
56 const char* OS::GetTimeZoneName(int64_t seconds_since_epoch) { | 58 const char* OS::GetTimeZoneName(int64_t seconds_since_epoch) { |
57 tm decomposed; | 59 TIME_ZONE_INFORMATION zone_information; |
58 // LocalTime will set _tzname. | 60 memset(&zone_information, 0, sizeof(zone_information)); |
59 bool succeeded = LocalTime(seconds_since_epoch, &decomposed); | 61 |
60 if (succeeded) { | 62 // Initialize and grab the time zone data. |
61 int inDaylightSavingsTime = decomposed.tm_isdst; | 63 _tzset(); |
62 ASSERT(inDaylightSavingsTime == 0 || inDaylightSavingsTime == 1); | 64 if (GetTimeZoneInformation(&zone_information) == TIME_ZONE_ID_INVALID) { |
63 return _tzname[inDaylightSavingsTime]; | 65 // If we can't get the time zone data, fallback on PDT. |
siva
2016/06/14 20:07:06
fallback on PST ?
In the past looks like we were
zra
2016/06/14 20:42:18
I didn't notice that on other platforms we also re
| |
64 } else { | 66 return "Pacific Standard Time"; |
65 // Return an empty string like V8 does. | |
66 return ""; | |
67 } | 67 } |
68 | |
69 // Grab the local time to see if we are in daylight savings time. | |
70 tm local_time; | |
71 bool daylight_savings = false; | |
72 if (LocalTime(seconds_since_epoch, &local_time)) { | |
73 daylight_savings = (local_time.tm_isdst == 1); | |
74 } | |
75 | |
76 // Convert the wchar string to a null-terminated utf8 string. | |
77 wchar_t* wchar_name = daylight_savings | |
78 ? zone_information.DaylightName | |
79 : zone_information.StandardName; | |
80 intptr_t utf8_len = WideCharToMultiByte( | |
81 CP_UTF8, 0, wchar_name, -1, NULL, 0, NULL, NULL); | |
82 char* name = Thread::Current()->zone()->Alloc<char>(utf8_len + 1); | |
83 WideCharToMultiByte( | |
84 CP_UTF8, 0, wchar_name, -1, name, utf8_len, NULL, NULL); | |
85 name[utf8_len] = '\0'; | |
86 return name; | |
68 } | 87 } |
69 | 88 |
70 | 89 |
71 int OS::GetTimeZoneOffsetInSeconds(int64_t seconds_since_epoch) { | 90 int OS::GetTimeZoneOffsetInSeconds(int64_t seconds_since_epoch) { |
72 tm decomposed; | 91 tm decomposed; |
73 // LocalTime will set _timezone. | 92 // LocalTime will set _timezone. |
74 bool succeeded = LocalTime(seconds_since_epoch, &decomposed); | 93 bool succeeded = LocalTime(seconds_since_epoch, &decomposed); |
75 if (succeeded) { | 94 if (succeeded) { |
76 int inDaylightSavingsTime = decomposed.tm_isdst; | 95 int inDaylightSavingsTime = decomposed.tm_isdst; |
77 ASSERT(inDaylightSavingsTime == 0 || inDaylightSavingsTime == 1); | 96 ASSERT(inDaylightSavingsTime == 0 || inDaylightSavingsTime == 1); |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
424 // TODO(zra): Remove once VM shuts down cleanly. | 443 // TODO(zra): Remove once VM shuts down cleanly. |
425 private_flag_windows_run_tls_destructors = false; | 444 private_flag_windows_run_tls_destructors = false; |
426 // On Windows we use ExitProcess so that threads can't clobber the exit_code. | 445 // On Windows we use ExitProcess so that threads can't clobber the exit_code. |
427 // See: https://code.google.com/p/nativeclient/issues/detail?id=2870 | 446 // See: https://code.google.com/p/nativeclient/issues/detail?id=2870 |
428 ::ExitProcess(code); | 447 ::ExitProcess(code); |
429 } | 448 } |
430 | 449 |
431 } // namespace dart | 450 } // namespace dart |
432 | 451 |
433 #endif // defined(TARGET_OS_WINDOWS) | 452 #endif // defined(TARGET_OS_WINDOWS) |
OLD | NEW |