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

Unified Diff: runtime/vm/os_macos.cc

Issue 9969098: Set the TZ env to get the UTC-ms since epoch. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments and rebased. Created 8 years, 8 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
Index: runtime/vm/os_macos.cc
diff --git a/runtime/vm/os_macos.cc b/runtime/vm/os_macos.cc
index e6107650d00cec279b45ca5bdf231d49aa18e632..1cc1c5f04fab3b56c1a9e15a8b5d26afb0cc703e 100644
--- a/runtime/vm/os_macos.cc
+++ b/runtime/vm/os_macos.cc
@@ -26,9 +26,6 @@ bool OS::BreakDownSecondsSinceEpoch(time_t seconds_since_epoch,
if (in_utc) {
error_code = gmtime_r(&seconds_since_epoch, &tm_result);
} else {
- // TODO(floitsch): we should be able to call tzset only once during
- // initialization.
- tzset(); // Make sure the libc knows about the local zone.
cshapiro 2012/04/19 23:52:12 I am confused by this call being removed for Win32
floitsch 2012/04/20 16:09:57 removed.
error_code = localtime_r(&seconds_since_epoch, &tm_result);
}
result->year = tm_result.tm_year;
@@ -41,6 +38,14 @@ bool OS::BreakDownSecondsSinceEpoch(time_t seconds_since_epoch,
}
+// TODO(floitsch): cache utc offset.
cshapiro 2012/04/19 23:52:12 This seems unnecessary. See below.
+static int UtcOffsetInSeconds(time_t seconds_since_epoch) {
+ struct tm t;
+ struct tm* error_code = localtime_r(&seconds_since_epoch, &t);
+ ASSERT(error_code != NULL);
+ return t.tm_gmtoff;
+}
+
bool OS::BrokenDownToSecondsSinceEpoch(
const BrokenDownDate& broken_down, bool in_utc, time_t* result) {
struct tm tm_broken_down;
@@ -54,27 +59,18 @@ bool OS::BrokenDownToSecondsSinceEpoch(
// Set wday to an impossible day, so that we can catch bad input.
tm_broken_down.tm_wday = -1;
// Make sure the libc knows about the local zone.
- // In case of 'in_utc' this call is mainly for multi-threading issues. If
- // another thread uses a time-function it will set the timezone. The timezone
- // adjustement below would then not work anymore.
// TODO(floitsch): we should be able to call tzset only once during
// initialization.
tzset();
- if (in_utc) {
- // Disable daylight saving in utc mode.
- tm_broken_down.tm_isdst = 0;
- // mktime assumes that the given date is local time zone.
- *result = mktime(&tm_broken_down);
- // Remove the timezone.
- *result -= timezone;
- } else {
- // Let libc figure out if daylight saving is active.
- tm_broken_down.tm_isdst = -1;
- *result = mktime(&tm_broken_down);
- }
+ // Let libc figure out if daylight saving is active.
+ tm_broken_down.tm_isdst = -1;
+ *result = mktime(&tm_broken_down);
if ((*result == -1) && (tm_broken_down.tm_wday == -1)) {
return false;
}
+ if (in_utc) {
+ *result += UtcOffsetInSeconds(*result);
cshapiro 2012/04/19 23:52:12 use timegm instead of mktime and correcting with U
floitsch 2012/04/20 16:09:57 The manpage of timegm explicitly states that it is
cshapiro 2012/04/20 20:47:49 I see no mention of timegm being deprecated or tha
floitsch 2012/04/23 08:37:09 Ok. "deprecated" was too strong. But they explicit
+ }
return true;
}

Powered by Google App Engine
This is Rietveld 408576698