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

Unified Diff: runtime/vm/os_fuchsia.cc

Issue 2435273003: runtime: Use Linux timezone implementation on Fuchsia (Closed)
Patch Set: Created 4 years, 2 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698