Commit c3130563 by Abseil Team Committed by Copybara-Service

Import of CCTZ from GitHub.

PiperOrigin-RevId: 696219306
Change-Id: I513f7da5370539663ecce5c1b374c6802587cdfe
parent 3a3b7e46
...@@ -20,12 +20,6 @@ package(features = [ ...@@ -20,12 +20,6 @@ package(features = [
licenses(["notice"]) licenses(["notice"])
filegroup(
name = "zoneinfo",
srcs = glob(["testdata/zoneinfo/**"]),
visibility = ["//absl/time:__subpackages__"],
)
### libraries ### libraries
cc_library( cc_library(
...@@ -165,3 +159,9 @@ cc_test( ...@@ -165,3 +159,9 @@ cc_test(
### examples ### examples
### binaries ### binaries
filegroup(
name = "zoneinfo",
srcs = glob(["testdata/zoneinfo/**"]),
visibility = ["//absl/time:__subpackages__"],
)
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#endif #endif
#if defined(__Fuchsia__) #if defined(__Fuchsia__)
#include <fuchsia/intl/cpp/fidl.h> #include <fidl/fuchsia.intl/cpp/fidl.h>
#include <lib/async-loop/cpp/loop.h> #include <lib/async-loop/cpp/loop.h>
#include <lib/fdio/directory.h> #include <lib/fdio/directory.h>
#include <zircon/types.h> #include <zircon/types.h>
...@@ -219,32 +219,29 @@ time_zone local_time_zone() { ...@@ -219,32 +219,29 @@ time_zone local_time_zone() {
// Note: We can't use the synchronous FIDL API here because it doesn't // Note: We can't use the synchronous FIDL API here because it doesn't
// allow timeouts; if the FIDL call failed, local_time_zone() would never // allow timeouts; if the FIDL call failed, local_time_zone() would never
// return. // return.
const zx::duration kTimeout = zx::msec(500); const zx::duration kTimeout = zx::msec(500);
// Don't attach to the thread because otherwise the thread's dispatcher // Don't attach to the thread because otherwise the thread's dispatcher
// would be set to null when the loop is destroyed, causing any other FIDL // would be set to null when the loop is destroyed, causing any other FIDL
// code running on the same thread to crash. // code running on the same thread to crash.
async::Loop loop(&kAsyncLoopConfigNeverAttachToThread); async::Loop loop(&kAsyncLoopConfigNeverAttachToThread);
auto endpoints = fidl::Endpoints<fuchsia_intl::PropertyProvider>::Create();
fuchsia::intl::PropertyProviderHandle handle;
zx_status_t status = fdio_service_connect_by_name( zx_status_t status = fdio_service_connect_by_name(
fuchsia::intl::PropertyProvider::Name_, fidl::DiscoverableProtocolName<fuchsia_intl::PropertyProvider>,
handle.NewRequest().TakeChannel().release()); endpoints.server.TakeChannel().release());
if (status != ZX_OK) { if (status != ZX_OK) {
return; return;
} }
fidl::Client intl_provider(std::move(endpoints.client), loop.dispatcher());
fuchsia::intl::PropertyProviderPtr intl_provider;
status = intl_provider.Bind(std::move(handle), loop.dispatcher()); // Attempt to initialize the time zone only once, and fail quietly.
if (status != ZX_OK) { // The end result of an error is an empty time zone string.
return; intl_provider->GetProfile().Then(
} [&loop, &primary_tz](
fidl::Result<fuchsia_intl::PropertyProvider::GetProfile>& result) {
intl_provider->GetProfile( if (result.is_ok()) {
[&loop, &primary_tz](fuchsia::intl::Profile profile) { const auto& response = result.value();
if (!profile.time_zones().empty()) { primary_tz = response.profile().time_zones().value()[0].id();
primary_tz = profile.time_zones()[0].id;
} }
loop.Quit(); loop.Quit();
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment