Index: runtime/vm/os_linux.cc |
diff --git a/runtime/vm/os_linux.cc b/runtime/vm/os_linux.cc |
index 52bdaf7b538f92e3abf87cdd86acc0d4a8f692ca..91788c8771403e77837d42423664285c9c8c688b 100644 |
--- a/runtime/vm/os_linux.cc |
+++ b/runtime/vm/os_linux.cc |
@@ -14,6 +14,7 @@ |
#include "platform/utils.h" |
#include "vm/isolate.h" |
+#include "vm/thread.h" |
Ivan Posva
2012/04/11 12:01:24
Please only include what you need.
floitsch
2012/04/11 12:10:21
Done.
|
namespace dart { |
@@ -25,8 +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. |
error_code = localtime_r(&seconds_since_epoch, &tm_result); |
} |
@@ -40,6 +39,15 @@ bool OS::BreakDownSecondsSinceEpoch(time_t seconds_since_epoch, |
} |
+// TODO(floitsch): cache utc offset. |
Ivan Posva
2012/04/11 12:01:24
If you cache how long are you willing to cache the
floitsch
2012/04/11 12:10:21
I would do the same as V8. Changed comment to incl
|
+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; |
@@ -53,27 +61,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); |
+ } |
return true; |
} |