Index: runtime/vm/os_macos.cc |
diff --git a/runtime/vm/os_macos.cc b/runtime/vm/os_macos.cc |
index 7910b828ecb1db27cdbf10806e390f2cdc7b0dd1..3936e99e93ea46546e6623ca1749ec72d25977cc 100644 |
--- a/runtime/vm/os_macos.cc |
+++ b/runtime/vm/os_macos.cc |
@@ -18,7 +18,15 @@ |
namespace dart { |
-static bool LocalTime(int64_t seconds_since_epoch, tm* tm_result) { |
+bool OS::GmTime(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; |
+ struct tm* error_code = gmtime_r(&seconds, tm_result); |
+ return error_code != NULL; |
+} |
+ |
+ |
+bool OS::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; |
struct tm* error_code = localtime_r(&seconds, tm_result); |
@@ -26,29 +34,50 @@ static bool LocalTime(int64_t seconds_since_epoch, tm* tm_result) { |
} |
-const char* OS::GetTimeZoneName(int64_t seconds_since_epoch) { |
- tm decomposed; |
- bool succeeded = LocalTime(seconds_since_epoch, &decomposed); |
- ASSERT(succeeded); |
- return decomposed.tm_zone; |
+bool OS::MkGmTime(tm* tm, int64_t* seconds_result) { |
+ // Set wday to an impossible day, so that we can catch bad input. |
+ tm->tm_wday = -1; |
+ time_t seconds = timegm(tm); |
+ if ((seconds == -1) && (tm->tm_wday == -1)) { |
+ return false; |
+ } |
+ *seconds_result = seconds; |
+ return true; |
+} |
+ |
+ |
+bool OS::MkTime(tm* tm, int64_t* seconds_result) { |
+ // Let the libc figure out if daylight saving is active. |
+ tm->tm_isdst = -1; |
+ // Set wday to an impossible day, so that we can catch bad input. |
+ tm->tm_wday = -1; |
+ time_t seconds = mktime(tm); |
+ if ((seconds == -1) && (tm->tm_wday == -1)) { |
+ return false; |
+ } |
+ *seconds_result = seconds; |
+ return true; |
} |
-int OS::GetTimeZoneOffsetInSeconds(int64_t seconds_since_epoch) { |
+bool OS::GetTimeZoneName(int64_t seconds_since_epoch, |
+ const char** name_result) { |
tm decomposed; |
bool succeeded = LocalTime(seconds_since_epoch, &decomposed); |
- ASSERT(succeeded); |
- // Even if the offset was 24 hours it would still easily fit into 32 bits. |
- return static_cast<int>(decomposed.tm_gmtoff); |
+ if (!succeeded) return false; |
+ *name_result = decomposed.tm_zone; |
+ return true; |
} |
-int OS::GetLocalTimeZoneAdjustmentInSeconds() { |
- // TODO(floitsch): avoid excessive calls to tzset? |
- tzset(); |
+bool OS::GetTimeZoneOffsetInSeconds(int64_t seconds_since_epoch, |
+ int* offset_result) { |
+ tm decomposed; |
+ bool succeeded = LocalTime(seconds_since_epoch, &decomposed); |
+ if (!succeeded) return false; |
// Even if the offset was 24 hours it would still easily fit into 32 bits. |
- // Note that Unix and Dart disagree on the sign. |
- return static_cast<int>(-timezone); |
+ *offset_result = static_cast<int>(decomposed.tm_gmtoff); |
+ return true; |
} |