Index: runtime/vm/os_win.cc |
diff --git a/runtime/vm/os_win.cc b/runtime/vm/os_win.cc |
index 96a00359df610e396aefefd1da4776a427c61a2d..37817cfd80dc0d3a57d38601e7786c83981aad69 100644 |
--- a/runtime/vm/os_win.cc |
+++ b/runtime/vm/os_win.cc |
@@ -54,6 +54,61 @@ bool OS::MkTime(tm* tm, int64_t* seconds_result) { |
} |
+// Calls _tzset if necessary. |
+static void TzSet() { |
+ static bool tz_is_initialized = false; |
+ if (!tz_is_initialized) { |
+ _tzset(); |
+ tz_is_initialized = true; |
+ } |
+} |
+ |
+ |
+int GetDaylightSavingOffsetInSeconds() { |
Mads Ager (google)
2012/05/21 12:53:28
static int GetDaylightSavingsOffsetInSeconds() {
floitsch
2012/05/21 13:26:45
Done.
|
+ TzSet(); |
Mads Ager (google)
2012/05/21 12:53:28
Is the call to TzSet needed here?
floitsch
2012/05/21 13:26:45
No. Apparently not. Removed.
|
+ TIME_ZONE_INFORMATION zone_information; |
+ memset(&zone_information, 0, sizeof(zone_information)); |
+ if (GetTimeZoneInformation(&zone_information) == TIME_ZONE_ID_INVALID) { |
+ // By default the daylight saving offset is an hour. |
+ return -60 * 60; |
+ } else { |
+ return static_cast<int>(zone_information.DaylightBias * 60); |
+ } |
+} |
+ |
+bool OS::GetTimeZoneName(int64_t seconds_since_epoch, |
Mads Ager (google)
2012/05/21 12:53:28
There is a TzSet() call missing in this method I t
floitsch
2012/05/21 13:26:45
Updated comment: LocalTime implicitly calls tzset.
|
+ const char** name_result) { |
+ tm decomposed; |
+ bool succeeded = LocalTime(seconds_since_epoch, &decomposed); |
+ if (!succeeded) return false; |
+ int inDaylightSavingsTime = decomposed.tm_isdst; |
+ if (inDaylightSavingsTime != 0 && inDaylightSavingsTime != 1) { |
+ return false; |
+ } |
+ *name_result = _tzname[inDaylightSavingsTime]; |
+ return true; |
+} |
+ |
+ |
+bool OS::GetTimeZoneOffsetInSeconds(int64_t seconds_since_epoch, |
+ int* offset_result) { |
+ tm decomposed; |
+ bool succeeded = LocalTime(seconds_since_epoch, &decomposed); |
+ if (!succeeded) return false; |
+ int inDaylightSavingsTime = decomposed.tm_isdst; |
+ if (inDaylightSavingsTime != 0 && inDaylightSavingsTime != 1) return false; |
Mads Ager (google)
2012/05/21 12:53:28
Either a one-liner above or split into lines with
floitsch
2012/05/21 13:26:45
Done.
|
+ TzSet(); |
+ // Dart and Windows disagree on the sign of the bias. |
+ *offset_result = static_cast<int>(-_timezone); |
+ if (inDaylightSavingsTime == 1) { |
+ static int daylight_offset = GetDaylightSavingOffsetInSeconds() |
+ // Subtract because windows and Dart disagree on the sign. |
+ *offset_result -= daylight_offset; |
+ } |
+ return true; |
+} |
+ |
+ |
int64_t OS::GetCurrentTimeMillis() { |
return GetCurrentTimeMicros() / 1000; |
} |