Skip to content

Commit c313056

Browse files
Abseil Teamcopybara-github
authored andcommitted
Import of CCTZ from GitHub.
PiperOrigin-RevId: 696219306 Change-Id: I513f7da5370539663ecce5c1b374c6802587cdfe
1 parent 3a3b7e4 commit c313056

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

absl/time/internal/cctz/BUILD.bazel

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ package(features = [
2020

2121
licenses(["notice"])
2222

23-
filegroup(
24-
name = "zoneinfo",
25-
srcs = glob(["testdata/zoneinfo/**"]),
26-
visibility = ["//absl/time:__subpackages__"],
27-
)
28-
2923
### libraries
3024

3125
cc_library(
@@ -165,3 +159,9 @@ cc_test(
165159
### examples
166160

167161
### binaries
162+
163+
filegroup(
164+
name = "zoneinfo",
165+
srcs = glob(["testdata/zoneinfo/**"]),
166+
visibility = ["//absl/time:__subpackages__"],
167+
)

absl/time/internal/cctz/src/time_zone_lookup.cc

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#endif
2727

2828
#if defined(__Fuchsia__)
29-
#include <fuchsia/intl/cpp/fidl.h>
29+
#include <fidl/fuchsia.intl/cpp/fidl.h>
3030
#include <lib/async-loop/cpp/loop.h>
3131
#include <lib/fdio/directory.h>
3232
#include <zircon/types.h>
@@ -219,32 +219,29 @@ time_zone local_time_zone() {
219219
// Note: We can't use the synchronous FIDL API here because it doesn't
220220
// allow timeouts; if the FIDL call failed, local_time_zone() would never
221221
// return.
222-
223222
const zx::duration kTimeout = zx::msec(500);
224223

225224
// Don't attach to the thread because otherwise the thread's dispatcher
226225
// would be set to null when the loop is destroyed, causing any other FIDL
227226
// code running on the same thread to crash.
228227
async::Loop loop(&kAsyncLoopConfigNeverAttachToThread);
229-
230-
fuchsia::intl::PropertyProviderHandle handle;
228+
auto endpoints = fidl::Endpoints<fuchsia_intl::PropertyProvider>::Create();
231229
zx_status_t status = fdio_service_connect_by_name(
232-
fuchsia::intl::PropertyProvider::Name_,
233-
handle.NewRequest().TakeChannel().release());
230+
fidl::DiscoverableProtocolName<fuchsia_intl::PropertyProvider>,
231+
endpoints.server.TakeChannel().release());
234232
if (status != ZX_OK) {
235233
return;
236234
}
237-
238-
fuchsia::intl::PropertyProviderPtr intl_provider;
239-
status = intl_provider.Bind(std::move(handle), loop.dispatcher());
240-
if (status != ZX_OK) {
241-
return;
242-
}
243-
244-
intl_provider->GetProfile(
245-
[&loop, &primary_tz](fuchsia::intl::Profile profile) {
246-
if (!profile.time_zones().empty()) {
247-
primary_tz = profile.time_zones()[0].id;
235+
fidl::Client intl_provider(std::move(endpoints.client), loop.dispatcher());
236+
237+
// Attempt to initialize the time zone only once, and fail quietly.
238+
// The end result of an error is an empty time zone string.
239+
intl_provider->GetProfile().Then(
240+
[&loop, &primary_tz](
241+
fidl::Result<fuchsia_intl::PropertyProvider::GetProfile>& result) {
242+
if (result.is_ok()) {
243+
const auto& response = result.value();
244+
primary_tz = response.profile().time_zones().value()[0].id();
248245
}
249246
loop.Quit();
250247
});

0 commit comments

Comments
 (0)