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

Unified Diff: runtime/vm/os_win.cc

Issue 10383218: Add support for timezone offset and timezone name. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add test. Created 8 years, 7 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_macos.cc ('k') | tests/corelib/date_time7_test.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 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;
}
« no previous file with comments | « runtime/vm/os_macos.cc ('k') | tests/corelib/date_time7_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698