Index: runtime/vm/os_fuchsia.cc |
diff --git a/runtime/vm/os_fuchsia.cc b/runtime/vm/os_fuchsia.cc |
index 48181f7a1b00c33f51ff2ccee593d36d75e03ae7..22a1635953eaf5559ac492009653261696892198 100644 |
--- a/runtime/vm/os_fuchsia.cc |
+++ b/runtime/vm/os_fuchsia.cc |
@@ -33,24 +33,38 @@ intptr_t OS::ProcessId() { |
} |
+static bool 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); |
+ return error_code != NULL; |
+} |
+ |
+ |
const char* OS::GetTimeZoneName(int64_t seconds_since_epoch) { |
- UNIMPLEMENTED(); |
- return ""; |
+ tm decomposed; |
+ bool succeeded = LocalTime(seconds_since_epoch, &decomposed); |
+ // If unsuccessful, return an empty string like V8 does. |
+ return (succeeded && (decomposed.tm_zone != NULL)) ? decomposed.tm_zone : ""; |
} |
int OS::GetTimeZoneOffsetInSeconds(int64_t seconds_since_epoch) { |
- UNIMPLEMENTED(); |
- return 0; |
+ tm decomposed; |
+ bool succeeded = LocalTime(seconds_since_epoch, &decomposed); |
+ // Even if the offset was 24 hours it would still easily fit into 32 bits. |
+ // If unsuccessful, return zero like V8 does. |
+ return succeeded ? static_cast<int>(decomposed.tm_gmtoff) : 0; |
} |
zra
2016/10/22 06:40:56
Two newlines between functions.
|
- |
int OS::GetLocalTimeZoneAdjustmentInSeconds() { |
- UNIMPLEMENTED(); |
- return 0; |
+ // TODO(floitsch): avoid excessive calls to tzset? |
+ tzset(); |
+ // 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); |
} |
zra
2016/10/22 06:40:56
ditto.
|
- |
int64_t OS::GetCurrentTimeMillis() { |
return GetCurrentTimeMicros() / 1000; |
} |