[vm, fuchsia] Add timezone support in Fuchsia SDK builds

Previously Fuchsia did not expose a timezone API in their public API.
Support for the existing private APIs was added in:

https://fuchsia-review.googlesource.com/c/fuchsia/+/284531
https://fuchsia-review.googlesource.com/c/fuchsia/+/284654

as fuchsia::deprecatedtimezone. A replacement API has not yet been added
to the public SDK.

This resolves b/141224241.

Change-Id: I50d3cb61f869508a6cf90e918c5af001a27192f8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/119820
Auto-Submit: Chris Bracken <cbracken@google.com>
Commit-Queue: Zach Anderson <zra@google.com>
Reviewed-by: Zach Anderson <zra@google.com>
diff --git a/runtime/vm/BUILD.gn b/runtime/vm/BUILD.gn
index 9223327..d5867a4 100644
--- a/runtime/vm/BUILD.gn
+++ b/runtime/vm/BUILD.gn
@@ -68,7 +68,10 @@
   extra_deps = [ "//third_party/icu" ]
   if (is_fuchsia) {
     if (using_fuchsia_sdk) {
-      extra_deps += [ "$fuchsia_sdk_root/pkg:sys_cpp" ]
+      extra_deps += [
+        "$fuchsia_sdk_root/fidl:fuchsia.deprecatedtimezone",
+        "$fuchsia_sdk_root/pkg:sys_cpp",
+      ]
     } else {
       extra_deps += [
         # TODO(US-399): Remove time_service specific code when it is no longer
diff --git a/runtime/vm/os_fuchsia.cc b/runtime/vm/os_fuchsia.cc
index 4eaae29..2641103 100644
--- a/runtime/vm/os_fuchsia.cc
+++ b/runtime/vm/os_fuchsia.cc
@@ -8,9 +8,14 @@
 #include "vm/os.h"
 
 #include <errno.h>
-#if !defined(FUCHSIA_SDK)
+#if defined(FUCHSIA_SDK)
+#include <fuchsia/deprecatedtimezone/cpp/fidl.h>
+namespace fuchsia {
+namespace timezone = deprecatedtimezone;
+}
+#else
 #include <fuchsia/timezone/cpp/fidl.h>
-#endif  //  !defined(FUCHSIA_SDK)
+#endif  //  defined(FUCHSIA_SDK)
 #include <lib/sys/cpp/service_directory.h>
 #include <zircon/process.h>
 #include <zircon/syscalls.h>
@@ -39,7 +44,6 @@
   return static_cast<intptr_t>(getpid());
 }
 
-#if !defined(FUCHSIA_SDK)
 // TODO(FL-98): Change this to talk to fuchsia.dart to get timezone service to
 // directly get timezone.
 //
@@ -47,12 +51,10 @@
 // component:ConnectToEnvironmentServices and this is the only thing that is
 // blocking it and FL-98 will take time.
 static fuchsia::timezone::TimezoneSyncPtr tz;
-#endif  //  !defined(FUCHSIA_SDK)
 
 static zx_status_t GetLocalAndDstOffsetInSeconds(int64_t seconds_since_epoch,
                                                  int32_t* local_offset,
                                                  int32_t* dst_offset) {
-#if !defined(FUCHSIA_SDK)
   zx_status_t status = tz->GetTimezoneOffsetMinutes(seconds_since_epoch * 1000,
                                                     local_offset, dst_offset);
   if (status != ZX_OK) {
@@ -61,13 +63,9 @@
   *local_offset *= 60;
   *dst_offset *= 60;
   return ZX_OK;
-#else
-  return ZX_ERR_NOT_SUPPORTED;
-#endif  //  !defined(FUCHSIA_SDK)
 }
 
 const char* OS::GetTimeZoneName(int64_t seconds_since_epoch) {
-#if !defined(FUCHSIA_SDK)
   // TODO(abarth): Handle time zone changes.
   static const auto* tz_name = new std::string([] {
     std::string result;
@@ -75,9 +73,6 @@
     return result;
   }());
   return tz_name->c_str();
-#else
-  return "";
-#endif  //  !defined(FUCHSIA_SDK)}
 }
 
 int OS::GetTimeZoneOffsetInSeconds(int64_t seconds_since_epoch) {
@@ -274,10 +269,8 @@
 }
 
 void OS::Init() {
-#if !defined(FUCHSIA_SDK)
   auto services = sys::ServiceDirectory::CreateFromNamespace();
   services->Connect(tz.NewRequest());
-#endif  //  !defined(FUCHSIA_SDK)
 }
 
 void OS::Cleanup() {}