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

Unified Diff: runtime/vm/os_win.cc

Issue 2069783002: Fix Windows time zone name extraction. Update API docs (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/os.h ('k') | sdk/lib/core/date_time.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/os_win.cc
diff --git a/runtime/vm/os_win.cc b/runtime/vm/os_win.cc
index 2ea8c1dd6755c44e65c6361a9b3ef89d4e0e2136..39b7306113a17047338e539664c1ccf30a2bcc0f 100644
--- a/runtime/vm/os_win.cc
+++ b/runtime/vm/os_win.cc
@@ -34,7 +34,9 @@ intptr_t OS::ProcessId() {
// As a side-effect sets the globals _timezone, _daylight and _tzname.
static bool LocalTime(int64_t seconds_since_epoch, tm* tm_result) {
time_t seconds = static_cast<time_t>(seconds_since_epoch);
- if (seconds != seconds_since_epoch) return false;
+ if (seconds != seconds_since_epoch) {
+ return false;
+ }
// localtime_s implicitly sets _timezone, _daylight and _tzname.
errno_t error_code = localtime_s(tm_result, &seconds);
return error_code == 0;
@@ -54,17 +56,34 @@ static int GetDaylightSavingBiasInSeconds() {
const char* OS::GetTimeZoneName(int64_t seconds_since_epoch) {
- tm decomposed;
- // LocalTime will set _tzname.
- bool succeeded = LocalTime(seconds_since_epoch, &decomposed);
- if (succeeded) {
- int inDaylightSavingsTime = decomposed.tm_isdst;
- ASSERT(inDaylightSavingsTime == 0 || inDaylightSavingsTime == 1);
- return _tzname[inDaylightSavingsTime];
- } else {
- // Return an empty string like V8 does.
- return "";
+ TIME_ZONE_INFORMATION zone_information;
+ memset(&zone_information, 0, sizeof(zone_information));
+
+ // Initialize and grab the time zone data.
+ _tzset();
+ if (GetTimeZoneInformation(&zone_information) == TIME_ZONE_ID_INVALID) {
+ // 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
+ return "Pacific Standard Time";
}
+
+ // Grab the local time to see if we are in daylight savings time.
+ tm local_time;
+ bool daylight_savings = false;
+ if (LocalTime(seconds_since_epoch, &local_time)) {
+ daylight_savings = (local_time.tm_isdst == 1);
+ }
+
+ // Convert the wchar string to a null-terminated utf8 string.
+ wchar_t* wchar_name = daylight_savings
+ ? zone_information.DaylightName
+ : zone_information.StandardName;
+ intptr_t utf8_len = WideCharToMultiByte(
+ CP_UTF8, 0, wchar_name, -1, NULL, 0, NULL, NULL);
+ char* name = Thread::Current()->zone()->Alloc<char>(utf8_len + 1);
+ WideCharToMultiByte(
+ CP_UTF8, 0, wchar_name, -1, name, utf8_len, NULL, NULL);
+ name[utf8_len] = '\0';
+ return name;
}
« no previous file with comments | « runtime/vm/os.h ('k') | sdk/lib/core/date_time.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698