diff options
author | thegeorg <thegeorg@yandex-team.ru> | 2022-02-10 16:45:12 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:12 +0300 |
commit | 49116032d905455a7b1c994e4a696afc885c1e71 (patch) | |
tree | be835aa92c6248212e705f25388ebafcf84bc7a1 /contrib/restricted/abseil-cpp/absl/time | |
parent | 4e839db24a3bbc9f1c610c43d6faaaa99824dcca (diff) | |
download | ydb-49116032d905455a7b1c994e4a696afc885c1e71.tar.gz |
Restoring authorship annotation for <thegeorg@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/restricted/abseil-cpp/absl/time')
10 files changed, 301 insertions, 301 deletions
diff --git a/contrib/restricted/abseil-cpp/absl/time/civil_time.cc b/contrib/restricted/abseil-cpp/absl/time/civil_time.cc index ab34f117fa..6a231edb2d 100644 --- a/contrib/restricted/abseil-cpp/absl/time/civil_time.cc +++ b/contrib/restricted/abseil-cpp/absl/time/civil_time.cc @@ -38,7 +38,7 @@ std::string FormatYearAnd(string_view fmt, CivilSecond cs) { const CivilSecond ncs(NormalizeYear(cs.year()), cs.month(), cs.day(), cs.hour(), cs.minute(), cs.second()); const TimeZone utc = UTCTimeZone(); - return StrCat(cs.year(), FormatTime(fmt, FromCivil(ncs, utc), utc)); + return StrCat(cs.year(), FormatTime(fmt, FromCivil(ncs, utc), utc)); } template <typename CivilT> diff --git a/contrib/restricted/abseil-cpp/absl/time/internal/cctz/include/cctz/time_zone.h b/contrib/restricted/abseil-cpp/absl/time/internal/cctz/include/cctz/time_zone.h index 21cbf8574c..6e382dc6c9 100644 --- a/contrib/restricted/abseil-cpp/absl/time/internal/cctz/include/cctz/time_zone.h +++ b/contrib/restricted/abseil-cpp/absl/time/internal/cctz/include/cctz/time_zone.h @@ -22,7 +22,7 @@ #include <chrono> #include <cstdint> -#include <limits> +#include <limits> #include <string> #include <utility> @@ -42,9 +42,9 @@ using sys_seconds = seconds; // Deprecated. Use cctz::seconds instead. namespace detail { template <typename D> -std::pair<time_point<seconds>, D> split_seconds(const time_point<D>& tp); -std::pair<time_point<seconds>, seconds> split_seconds( - const time_point<seconds>& tp); +std::pair<time_point<seconds>, D> split_seconds(const time_point<D>& tp); +std::pair<time_point<seconds>, seconds> split_seconds( + const time_point<seconds>& tp); } // namespace detail // cctz::time_zone is an opaque, small, value-type class representing a @@ -269,20 +269,20 @@ std::string format(const std::string&, const time_point<seconds>&, const femtoseconds&, const time_zone&); bool parse(const std::string&, const std::string&, const time_zone&, time_point<seconds>*, femtoseconds*, std::string* err = nullptr); -template <typename Rep, std::intmax_t Denom> -bool join_seconds( - const time_point<seconds>& sec, const femtoseconds& fs, - time_point<std::chrono::duration<Rep, std::ratio<1, Denom>>>* tpp); -template <typename Rep, std::intmax_t Num> -bool join_seconds( - const time_point<seconds>& sec, const femtoseconds& fs, - time_point<std::chrono::duration<Rep, std::ratio<Num, 1>>>* tpp); -template <typename Rep> -bool join_seconds( - const time_point<seconds>& sec, const femtoseconds& fs, - time_point<std::chrono::duration<Rep, std::ratio<1, 1>>>* tpp); -bool join_seconds(const time_point<seconds>& sec, const femtoseconds&, - time_point<seconds>* tpp); +template <typename Rep, std::intmax_t Denom> +bool join_seconds( + const time_point<seconds>& sec, const femtoseconds& fs, + time_point<std::chrono::duration<Rep, std::ratio<1, Denom>>>* tpp); +template <typename Rep, std::intmax_t Num> +bool join_seconds( + const time_point<seconds>& sec, const femtoseconds& fs, + time_point<std::chrono::duration<Rep, std::ratio<Num, 1>>>* tpp); +template <typename Rep> +bool join_seconds( + const time_point<seconds>& sec, const femtoseconds& fs, + time_point<std::chrono::duration<Rep, std::ratio<1, 1>>>* tpp); +bool join_seconds(const time_point<seconds>& sec, const femtoseconds&, + time_point<seconds>* tpp); } // namespace detail // Formats the given time_point in the given cctz::time_zone according to @@ -373,84 +373,84 @@ inline bool parse(const std::string& fmt, const std::string& input, const time_zone& tz, time_point<D>* tpp) { time_point<seconds> sec; detail::femtoseconds fs; - return detail::parse(fmt, input, tz, &sec, &fs) && - detail::join_seconds(sec, fs, tpp); -} - -namespace detail { - -// Split a time_point<D> into a time_point<seconds> and a D subseconds. -// Undefined behavior if time_point<seconds> is not of sufficient range. -// Note that this means it is UB to call cctz::time_zone::lookup(tp) or -// cctz::format(fmt, tp, tz) with a time_point that is outside the range -// of a 64-bit std::time_t. -template <typename D> -std::pair<time_point<seconds>, D> split_seconds(const time_point<D>& tp) { - auto sec = std::chrono::time_point_cast<seconds>(tp); - auto sub = tp - sec; - if (sub.count() < 0) { - sec -= seconds(1); - sub += seconds(1); + return detail::parse(fmt, input, tz, &sec, &fs) && + detail::join_seconds(sec, fs, tpp); +} + +namespace detail { + +// Split a time_point<D> into a time_point<seconds> and a D subseconds. +// Undefined behavior if time_point<seconds> is not of sufficient range. +// Note that this means it is UB to call cctz::time_zone::lookup(tp) or +// cctz::format(fmt, tp, tz) with a time_point that is outside the range +// of a 64-bit std::time_t. +template <typename D> +std::pair<time_point<seconds>, D> split_seconds(const time_point<D>& tp) { + auto sec = std::chrono::time_point_cast<seconds>(tp); + auto sub = tp - sec; + if (sub.count() < 0) { + sec -= seconds(1); + sub += seconds(1); } - return {sec, std::chrono::duration_cast<D>(sub)}; + return {sec, std::chrono::duration_cast<D>(sub)}; +} + +inline std::pair<time_point<seconds>, seconds> split_seconds( + const time_point<seconds>& tp) { + return {tp, seconds::zero()}; +} + +// Join a time_point<seconds> and femto subseconds into a time_point<D>. +// Floors to the resolution of time_point<D>. Returns false if time_point<D> +// is not of sufficient range. +template <typename Rep, std::intmax_t Denom> +bool join_seconds( + const time_point<seconds>& sec, const femtoseconds& fs, + time_point<std::chrono::duration<Rep, std::ratio<1, Denom>>>* tpp) { + using D = std::chrono::duration<Rep, std::ratio<1, Denom>>; + // TODO(#199): Return false if result unrepresentable as a time_point<D>. + *tpp = std::chrono::time_point_cast<D>(sec); + *tpp += std::chrono::duration_cast<D>(fs); + return true; } -inline std::pair<time_point<seconds>, seconds> split_seconds( - const time_point<seconds>& tp) { - return {tp, seconds::zero()}; -} - -// Join a time_point<seconds> and femto subseconds into a time_point<D>. -// Floors to the resolution of time_point<D>. Returns false if time_point<D> -// is not of sufficient range. -template <typename Rep, std::intmax_t Denom> -bool join_seconds( - const time_point<seconds>& sec, const femtoseconds& fs, - time_point<std::chrono::duration<Rep, std::ratio<1, Denom>>>* tpp) { - using D = std::chrono::duration<Rep, std::ratio<1, Denom>>; - // TODO(#199): Return false if result unrepresentable as a time_point<D>. - *tpp = std::chrono::time_point_cast<D>(sec); - *tpp += std::chrono::duration_cast<D>(fs); - return true; -} - -template <typename Rep, std::intmax_t Num> -bool join_seconds( - const time_point<seconds>& sec, const femtoseconds&, - time_point<std::chrono::duration<Rep, std::ratio<Num, 1>>>* tpp) { - using D = std::chrono::duration<Rep, std::ratio<Num, 1>>; - auto count = sec.time_since_epoch().count(); - if (count >= 0 || count % Num == 0) { - count /= Num; - } else { - count /= Num; - count -= 1; - } - if (count > (std::numeric_limits<Rep>::max)()) return false; - if (count < (std::numeric_limits<Rep>::min)()) return false; - *tpp = time_point<D>() + D{static_cast<Rep>(count)}; - return true; -} - -template <typename Rep> -bool join_seconds( - const time_point<seconds>& sec, const femtoseconds&, - time_point<std::chrono::duration<Rep, std::ratio<1, 1>>>* tpp) { - using D = std::chrono::duration<Rep, std::ratio<1, 1>>; - auto count = sec.time_since_epoch().count(); - if (count > (std::numeric_limits<Rep>::max)()) return false; - if (count < (std::numeric_limits<Rep>::min)()) return false; - *tpp = time_point<D>() + D{static_cast<Rep>(count)}; - return true; -} - -inline bool join_seconds(const time_point<seconds>& sec, const femtoseconds&, - time_point<seconds>* tpp) { - *tpp = sec; - return true; -} - -} // namespace detail +template <typename Rep, std::intmax_t Num> +bool join_seconds( + const time_point<seconds>& sec, const femtoseconds&, + time_point<std::chrono::duration<Rep, std::ratio<Num, 1>>>* tpp) { + using D = std::chrono::duration<Rep, std::ratio<Num, 1>>; + auto count = sec.time_since_epoch().count(); + if (count >= 0 || count % Num == 0) { + count /= Num; + } else { + count /= Num; + count -= 1; + } + if (count > (std::numeric_limits<Rep>::max)()) return false; + if (count < (std::numeric_limits<Rep>::min)()) return false; + *tpp = time_point<D>() + D{static_cast<Rep>(count)}; + return true; +} + +template <typename Rep> +bool join_seconds( + const time_point<seconds>& sec, const femtoseconds&, + time_point<std::chrono::duration<Rep, std::ratio<1, 1>>>* tpp) { + using D = std::chrono::duration<Rep, std::ratio<1, 1>>; + auto count = sec.time_since_epoch().count(); + if (count > (std::numeric_limits<Rep>::max)()) return false; + if (count < (std::numeric_limits<Rep>::min)()) return false; + *tpp = time_point<D>() + D{static_cast<Rep>(count)}; + return true; +} + +inline bool join_seconds(const time_point<seconds>& sec, const femtoseconds&, + time_point<seconds>* tpp) { + *tpp = sec; + return true; +} + +} // namespace detail } // namespace cctz } // namespace time_internal ABSL_NAMESPACE_END diff --git a/contrib/restricted/abseil-cpp/absl/time/internal/cctz/src/time_zone_fixed.cc b/contrib/restricted/abseil-cpp/absl/time/internal/cctz/src/time_zone_fixed.cc index a067fe5621..f2b3294ef7 100644 --- a/contrib/restricted/abseil-cpp/absl/time/internal/cctz/src/time_zone_fixed.cc +++ b/contrib/restricted/abseil-cpp/absl/time/internal/cctz/src/time_zone_fixed.cc @@ -53,7 +53,7 @@ int Parse02d(const char* p) { } // namespace bool FixedOffsetFromName(const std::string& name, seconds* offset) { - if (name == "UTC" || name == "UTC0") { + if (name == "UTC" || name == "UTC0") { *offset = seconds::zero(); return true; } diff --git a/contrib/restricted/abseil-cpp/absl/time/internal/cctz/src/time_zone_if.h b/contrib/restricted/abseil-cpp/absl/time/internal/cctz/src/time_zone_if.h index 20e753a147..7d3e42d3cd 100644 --- a/contrib/restricted/abseil-cpp/absl/time/internal/cctz/src/time_zone_if.h +++ b/contrib/restricted/abseil-cpp/absl/time/internal/cctz/src/time_zone_if.h @@ -56,8 +56,8 @@ class TimeZoneIf { // Convert between time_point<seconds> and a count of seconds since the // Unix epoch. We assume that the std::chrono::system_clock and the -// Unix clock are second aligned, and that the results are representable. -// (That is, that they share an epoch, which is required since C++20.) +// Unix clock are second aligned, and that the results are representable. +// (That is, that they share an epoch, which is required since C++20.) inline std::int_fast64_t ToUnixSeconds(const time_point<seconds>& tp) { return (tp - std::chrono::time_point_cast<seconds>( std::chrono::system_clock::from_time_t(0))) diff --git a/contrib/restricted/abseil-cpp/absl/time/internal/cctz/src/time_zone_info.cc b/contrib/restricted/abseil-cpp/absl/time/internal/cctz/src/time_zone_info.cc index 04ab1dd70f..4f175d95fc 100644 --- a/contrib/restricted/abseil-cpp/absl/time/internal/cctz/src/time_zone_info.cc +++ b/contrib/restricted/abseil-cpp/absl/time/internal/cctz/src/time_zone_info.cc @@ -39,12 +39,12 @@ #include <cstdio> #include <cstdlib> #include <cstring> -#include <fstream> +#include <fstream> #include <functional> #include <memory> #include <sstream> #include <string> -#include <utility> +#include <utility> #include "absl/base/config.h" #include "absl/time/internal/cctz/include/cctz/civil_time.h" @@ -578,17 +578,17 @@ bool TimeZoneInfo::Load(ZoneInfoSource* zip) { namespace { -using FilePtr = std::unique_ptr<FILE, int (*)(FILE*)>; - +using FilePtr = std::unique_ptr<FILE, int (*)(FILE*)>; + // fopen(3) adaptor. -inline FilePtr FOpen(const char* path, const char* mode) { +inline FilePtr FOpen(const char* path, const char* mode) { #if defined(_MSC_VER) FILE* fp; if (fopen_s(&fp, path, mode) != 0) fp = nullptr; - return FilePtr(fp, fclose); + return FilePtr(fp, fclose); #else - // TODO: Enable the close-on-exec flag. - return FilePtr(fopen(path, mode), fclose); + // TODO: Enable the close-on-exec flag. + return FilePtr(fopen(path, mode), fclose); #endif } @@ -616,11 +616,11 @@ class FileZoneInfoSource : public ZoneInfoSource { protected: explicit FileZoneInfoSource( - FilePtr fp, std::size_t len = std::numeric_limits<std::size_t>::max()) - : fp_(std::move(fp)), len_(len) {} + FilePtr fp, std::size_t len = std::numeric_limits<std::size_t>::max()) + : fp_(std::move(fp)), len_(len) {} private: - FilePtr fp_; + FilePtr fp_; std::size_t len_; }; @@ -649,9 +649,9 @@ std::unique_ptr<ZoneInfoSource> FileZoneInfoSource::Open( path.append(name, pos, std::string::npos); // Open the zoneinfo file. - auto fp = FOpen(path.c_str(), "rb"); + auto fp = FOpen(path.c_str(), "rb"); if (fp == nullptr) return nullptr; - return std::unique_ptr<ZoneInfoSource>(new FileZoneInfoSource(std::move(fp))); + return std::unique_ptr<ZoneInfoSource>(new FileZoneInfoSource(std::move(fp))); } class AndroidZoneInfoSource : public FileZoneInfoSource { @@ -660,9 +660,9 @@ class AndroidZoneInfoSource : public FileZoneInfoSource { std::string Version() const override { return version_; } private: - explicit AndroidZoneInfoSource(FilePtr fp, std::size_t len, - std::string version) - : FileZoneInfoSource(std::move(fp), len), version_(std::move(version)) {} + explicit AndroidZoneInfoSource(FilePtr fp, std::size_t len, + std::string version) + : FileZoneInfoSource(std::move(fp), len), version_(std::move(version)) {} std::string version_; }; @@ -674,8 +674,8 @@ std::unique_ptr<ZoneInfoSource> AndroidZoneInfoSource::Open( // See Android's libc/tzcode/bionic.cpp for additional information. for (const char* tzdata : {"/data/misc/zoneinfo/current/tzdata", "/system/usr/share/zoneinfo/tzdata"}) { - auto fp = FOpen(tzdata, "rb"); - if (fp == nullptr) continue; + auto fp = FOpen(tzdata, "rb"); + if (fp == nullptr) continue; char hbuf[24]; // covers header.zonetab_offset too if (fread(hbuf, 1, sizeof(hbuf), fp.get()) != sizeof(hbuf)) continue; @@ -701,7 +701,7 @@ std::unique_ptr<ZoneInfoSource> AndroidZoneInfoSource::Open( if (strcmp(name.c_str() + pos, ebuf) == 0) { if (fseek(fp.get(), static_cast<long>(start), SEEK_SET) != 0) break; return std::unique_ptr<ZoneInfoSource>(new AndroidZoneInfoSource( - std::move(fp), static_cast<std::size_t>(length), vers)); + std::move(fp), static_cast<std::size_t>(length), vers)); } } } @@ -709,69 +709,69 @@ std::unique_ptr<ZoneInfoSource> AndroidZoneInfoSource::Open( return nullptr; } -// A zoneinfo source for use inside Fuchsia components. This attempts to -// read zoneinfo files from one of several known paths in a component's -// incoming namespace. [Config data][1] is preferred, but package-specific -// resources are also supported. -// -// Fuchsia's implementation supports `FileZoneInfoSource::Version()`. -// -// [1]: -// https://fuchsia.dev/fuchsia-src/development/components/data#using_config_data_in_your_component -class FuchsiaZoneInfoSource : public FileZoneInfoSource { - public: - static std::unique_ptr<ZoneInfoSource> Open(const std::string& name); - std::string Version() const override { return version_; } - - private: - explicit FuchsiaZoneInfoSource(FilePtr fp, std::string version) - : FileZoneInfoSource(std::move(fp)), version_(std::move(version)) {} - std::string version_; -}; - -std::unique_ptr<ZoneInfoSource> FuchsiaZoneInfoSource::Open( - const std::string& name) { - // Use of the "file:" prefix is intended for testing purposes only. - const std::size_t pos = (name.compare(0, 5, "file:") == 0) ? 5 : 0; - - // Prefixes where a Fuchsia component might find zoneinfo files, - // in descending order of preference. - const auto kTzdataPrefixes = { - "/config/data/tzdata/", - "/pkg/data/tzdata/", - "/data/tzdata/", - }; - const auto kEmptyPrefix = {""}; - const bool name_absolute = (pos != name.size() && name[pos] == '/'); - const auto prefixes = name_absolute ? kEmptyPrefix : kTzdataPrefixes; - - // Fuchsia builds place zoneinfo files at "<prefix><format><name>". - for (const std::string prefix : prefixes) { - std::string path = prefix; - if (!prefix.empty()) path += "zoneinfo/tzif2/"; // format - path.append(name, pos, std::string::npos); - - auto fp = FOpen(path.c_str(), "rb"); - if (fp == nullptr) continue; - - std::string version; - if (!prefix.empty()) { - // Fuchsia builds place the version in "<prefix>revision.txt". - std::ifstream version_stream(prefix + "revision.txt"); - if (version_stream.is_open()) { - // revision.txt should contain no newlines, but to be - // defensive we read just the first line. - std::getline(version_stream, version); - } - } - - return std::unique_ptr<ZoneInfoSource>( - new FuchsiaZoneInfoSource(std::move(fp), std::move(version))); - } - - return nullptr; -} - +// A zoneinfo source for use inside Fuchsia components. This attempts to +// read zoneinfo files from one of several known paths in a component's +// incoming namespace. [Config data][1] is preferred, but package-specific +// resources are also supported. +// +// Fuchsia's implementation supports `FileZoneInfoSource::Version()`. +// +// [1]: +// https://fuchsia.dev/fuchsia-src/development/components/data#using_config_data_in_your_component +class FuchsiaZoneInfoSource : public FileZoneInfoSource { + public: + static std::unique_ptr<ZoneInfoSource> Open(const std::string& name); + std::string Version() const override { return version_; } + + private: + explicit FuchsiaZoneInfoSource(FilePtr fp, std::string version) + : FileZoneInfoSource(std::move(fp)), version_(std::move(version)) {} + std::string version_; +}; + +std::unique_ptr<ZoneInfoSource> FuchsiaZoneInfoSource::Open( + const std::string& name) { + // Use of the "file:" prefix is intended for testing purposes only. + const std::size_t pos = (name.compare(0, 5, "file:") == 0) ? 5 : 0; + + // Prefixes where a Fuchsia component might find zoneinfo files, + // in descending order of preference. + const auto kTzdataPrefixes = { + "/config/data/tzdata/", + "/pkg/data/tzdata/", + "/data/tzdata/", + }; + const auto kEmptyPrefix = {""}; + const bool name_absolute = (pos != name.size() && name[pos] == '/'); + const auto prefixes = name_absolute ? kEmptyPrefix : kTzdataPrefixes; + + // Fuchsia builds place zoneinfo files at "<prefix><format><name>". + for (const std::string prefix : prefixes) { + std::string path = prefix; + if (!prefix.empty()) path += "zoneinfo/tzif2/"; // format + path.append(name, pos, std::string::npos); + + auto fp = FOpen(path.c_str(), "rb"); + if (fp == nullptr) continue; + + std::string version; + if (!prefix.empty()) { + // Fuchsia builds place the version in "<prefix>revision.txt". + std::ifstream version_stream(prefix + "revision.txt"); + if (version_stream.is_open()) { + // revision.txt should contain no newlines, but to be + // defensive we read just the first line. + std::getline(version_stream, version); + } + } + + return std::unique_ptr<ZoneInfoSource>( + new FuchsiaZoneInfoSource(std::move(fp), std::move(version))); + } + + return nullptr; +} + } // namespace bool TimeZoneInfo::Load(const std::string& name) { @@ -789,7 +789,7 @@ bool TimeZoneInfo::Load(const std::string& name) { name, [](const std::string& n) -> std::unique_ptr<ZoneInfoSource> { if (auto z = FileZoneInfoSource::Open(n)) return z; if (auto z = AndroidZoneInfoSource::Open(n)) return z; - if (auto z = FuchsiaZoneInfoSource::Open(n)) return z; + if (auto z = FuchsiaZoneInfoSource::Open(n)) return z; return nullptr; }); return zip != nullptr && Load(zip.get()); diff --git a/contrib/restricted/abseil-cpp/absl/time/internal/cctz/src/time_zone_lookup.cc b/contrib/restricted/abseil-cpp/absl/time/internal/cctz/src/time_zone_lookup.cc index a15554fac5..55843c5e5b 100644 --- a/contrib/restricted/abseil-cpp/absl/time/internal/cctz/src/time_zone_lookup.cc +++ b/contrib/restricted/abseil-cpp/absl/time/internal/cctz/src/time_zone_lookup.cc @@ -28,13 +28,13 @@ #include <vector> #endif -#if defined(__Fuchsia__) -#error #include <fuchsia/intl/cpp/fidl.h> -#error #include <lib/async-loop/cpp/loop.h> -#error #include <lib/sys/cpp/component_context.h> -#error #include <zircon/types.h> -#endif - +#if defined(__Fuchsia__) +#error #include <fuchsia/intl/cpp/fidl.h> +#error #include <lib/async-loop/cpp/loop.h> +#error #include <lib/sys/cpp/component_context.h> +#error #include <zircon/types.h> +#endif + #include <cstdlib> #include <cstring> #include <string> @@ -147,49 +147,49 @@ time_zone local_time_zone() { } CFRelease(tz_default); #endif -#if defined(__Fuchsia__) - std::string primary_tz; - [&]() { - // 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 - // return. - - const zx::duration kTimeout = zx::msec(500); - - // 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 - // code running on the same thread to crash. - async::Loop loop(&kAsyncLoopConfigNeverAttachToThread); - std::unique_ptr<sys::ComponentContext> context = - sys::ComponentContext::Create(); - - fuchsia::intl::PropertyProviderHandle handle; - zx_status_t status = context->svc()->Connect(handle.NewRequest()); - if (status != ZX_OK) { - return; - } - - fuchsia::intl::PropertyProviderPtr intl_provider; - status = intl_provider.Bind(std::move(handle), loop.dispatcher()); - if (status != ZX_OK) { - return; - } - - intl_provider->GetProfile( - [&loop, &primary_tz](fuchsia::intl::Profile profile) { - if (!profile.time_zones().empty()) { - primary_tz = profile.time_zones()[0].id; - } - loop.Quit(); - }); - loop.Run(zx::deadline_after(kTimeout)); - }(); - - if (!primary_tz.empty()) { - zone = primary_tz.c_str(); - } -#endif - +#if defined(__Fuchsia__) + std::string primary_tz; + [&]() { + // 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 + // return. + + const zx::duration kTimeout = zx::msec(500); + + // 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 + // code running on the same thread to crash. + async::Loop loop(&kAsyncLoopConfigNeverAttachToThread); + std::unique_ptr<sys::ComponentContext> context = + sys::ComponentContext::Create(); + + fuchsia::intl::PropertyProviderHandle handle; + zx_status_t status = context->svc()->Connect(handle.NewRequest()); + if (status != ZX_OK) { + return; + } + + fuchsia::intl::PropertyProviderPtr intl_provider; + status = intl_provider.Bind(std::move(handle), loop.dispatcher()); + if (status != ZX_OK) { + return; + } + + intl_provider->GetProfile( + [&loop, &primary_tz](fuchsia::intl::Profile profile) { + if (!profile.time_zones().empty()) { + primary_tz = profile.time_zones()[0].id; + } + loop.Quit(); + }); + loop.Run(zx::deadline_after(kTimeout)); + }(); + + if (!primary_tz.empty()) { + zone = primary_tz.c_str(); + } +#endif + // Allow ${TZ} to override to default zone. char* tz_env = nullptr; #if defined(_MSC_VER) diff --git a/contrib/restricted/abseil-cpp/absl/time/internal/cctz/src/tzfile.h b/contrib/restricted/abseil-cpp/absl/time/internal/cctz/src/tzfile.h index 88f5b477dc..31e8598257 100644 --- a/contrib/restricted/abseil-cpp/absl/time/internal/cctz/src/tzfile.h +++ b/contrib/restricted/abseil-cpp/absl/time/internal/cctz/src/tzfile.h @@ -43,7 +43,7 @@ struct tzhead { char tzh_magic[4]; /* TZ_MAGIC */ - char tzh_version[1]; /* '\0' or '2'-'4' as of 2021 */ + char tzh_version[1]; /* '\0' or '2'-'4' as of 2021 */ char tzh_reserved[15]; /* reserved; must be zero */ char tzh_ttisutcnt[4]; /* coded number of trans. time flags */ char tzh_ttisstdcnt[4]; /* coded number of trans. time flags */ diff --git a/contrib/restricted/abseil-cpp/absl/time/internal/cctz/src/zone_info_source.cc b/contrib/restricted/abseil-cpp/absl/time/internal/cctz/src/zone_info_source.cc index 4813160630..5ab5a59ecf 100644 --- a/contrib/restricted/abseil-cpp/absl/time/internal/cctz/src/zone_info_source.cc +++ b/contrib/restricted/abseil-cpp/absl/time/internal/cctz/src/zone_info_source.cc @@ -65,7 +65,7 @@ ZoneInfoSourceFactory zone_info_source_factory __attribute__((weak)) = extern ZoneInfoSourceFactory zone_info_source_factory; extern ZoneInfoSourceFactory default_factory; ZoneInfoSourceFactory default_factory = DefaultFactory; -#if defined(_M_IX86) || defined(_M_ARM) +#if defined(_M_IX86) || defined(_M_ARM) #pragma comment( \ linker, \ "/alternatename:?zone_info_source_factory@cctz_extension@time_internal@" ABSL_INTERNAL_MANGLED_NS \ @@ -83,7 +83,7 @@ ZoneInfoSourceFactory default_factory = DefaultFactory; "@@U?$default_delete@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS \ "@@@std@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@@Z@" ABSL_INTERNAL_MANGLED_BACKREFERENCE \ "@@ZA") -#elif defined(_M_IA_64) || defined(_M_AMD64) || defined(_M_ARM64) +#elif defined(_M_IA_64) || defined(_M_AMD64) || defined(_M_ARM64) #pragma comment( \ linker, \ "/alternatename:?zone_info_source_factory@cctz_extension@time_internal@" ABSL_INTERNAL_MANGLED_NS \ diff --git a/contrib/restricted/abseil-cpp/absl/time/time.h b/contrib/restricted/abseil-cpp/absl/time/time.h index ec18030cfe..5abd815a79 100644 --- a/contrib/restricted/abseil-cpp/absl/time/time.h +++ b/contrib/restricted/abseil-cpp/absl/time/time.h @@ -182,30 +182,30 @@ class Duration { // Overloads that forward to either the int64_t or double overloads above. // Integer operands must be representable as int64_t. - template <typename T, time_internal::EnableIfIntegral<T> = 0> + template <typename T, time_internal::EnableIfIntegral<T> = 0> Duration& operator*=(T r) { int64_t x = r; return *this *= x; } - - template <typename T, time_internal::EnableIfIntegral<T> = 0> + + template <typename T, time_internal::EnableIfIntegral<T> = 0> Duration& operator/=(T r) { int64_t x = r; return *this /= x; } - template <typename T, time_internal::EnableIfFloat<T> = 0> - Duration& operator*=(T r) { - double x = r; - return *this *= x; - } - - template <typename T, time_internal::EnableIfFloat<T> = 0> - Duration& operator/=(T r) { - double x = r; - return *this /= x; - } - + template <typename T, time_internal::EnableIfFloat<T> = 0> + Duration& operator*=(T r) { + double x = r; + return *this *= x; + } + + template <typename T, time_internal::EnableIfFloat<T> = 0> + Duration& operator/=(T r) { + double x = r; + return *this /= x; + } + template <typename H> friend H AbslHashValue(H h, Duration d) { return H::combine(std::move(h), d.rep_hi_, d.rep_lo_); @@ -403,30 +403,30 @@ constexpr Duration InfiniteDuration(); // // absl::Duration a = absl::Seconds(60); // absl::Duration b = absl::Minutes(1); // b == a -template <typename T, time_internal::EnableIfIntegral<T> = 0> -constexpr Duration Nanoseconds(T n) { - return time_internal::FromInt64(n, std::nano{}); -} -template <typename T, time_internal::EnableIfIntegral<T> = 0> -constexpr Duration Microseconds(T n) { - return time_internal::FromInt64(n, std::micro{}); -} -template <typename T, time_internal::EnableIfIntegral<T> = 0> -constexpr Duration Milliseconds(T n) { - return time_internal::FromInt64(n, std::milli{}); -} -template <typename T, time_internal::EnableIfIntegral<T> = 0> -constexpr Duration Seconds(T n) { - return time_internal::FromInt64(n, std::ratio<1>{}); -} -template <typename T, time_internal::EnableIfIntegral<T> = 0> -constexpr Duration Minutes(T n) { - return time_internal::FromInt64(n, std::ratio<60>{}); -} -template <typename T, time_internal::EnableIfIntegral<T> = 0> -constexpr Duration Hours(T n) { - return time_internal::FromInt64(n, std::ratio<3600>{}); -} +template <typename T, time_internal::EnableIfIntegral<T> = 0> +constexpr Duration Nanoseconds(T n) { + return time_internal::FromInt64(n, std::nano{}); +} +template <typename T, time_internal::EnableIfIntegral<T> = 0> +constexpr Duration Microseconds(T n) { + return time_internal::FromInt64(n, std::micro{}); +} +template <typename T, time_internal::EnableIfIntegral<T> = 0> +constexpr Duration Milliseconds(T n) { + return time_internal::FromInt64(n, std::milli{}); +} +template <typename T, time_internal::EnableIfIntegral<T> = 0> +constexpr Duration Seconds(T n) { + return time_internal::FromInt64(n, std::ratio<1>{}); +} +template <typename T, time_internal::EnableIfIntegral<T> = 0> +constexpr Duration Minutes(T n) { + return time_internal::FromInt64(n, std::ratio<60>{}); +} +template <typename T, time_internal::EnableIfIntegral<T> = 0> +constexpr Duration Hours(T n) { + return time_internal::FromInt64(n, std::ratio<3600>{}); +} // Factory overloads for constructing `Duration` values from a floating-point // number of the unit indicated by the factory function's name. These functions @@ -480,9 +480,9 @@ Duration Hours(T n) { // ToInt64Hours() // // Helper functions that convert a Duration to an integral count of the -// indicated unit. These return the same results as the `IDivDuration()` -// function, though they usually do so more efficiently; see the -// documentation of `IDivDuration()` for details about overflow, etc. +// indicated unit. These return the same results as the `IDivDuration()` +// function, though they usually do so more efficiently; see the +// documentation of `IDivDuration()` for details about overflow, etc. // // Example: // @@ -577,20 +577,20 @@ inline std::ostream& operator<<(std::ostream& os, Duration d) { // `ZeroDuration()`. Parses "inf" and "-inf" as +/- `InfiniteDuration()`. bool ParseDuration(absl::string_view dur_string, Duration* d); -// AbslParseFlag() -// -// Parses a command-line flag string representation `text` into a a Duration -// value. Duration flags must be specified in a format that is valid input for -// `absl::ParseDuration()`. +// AbslParseFlag() +// +// Parses a command-line flag string representation `text` into a a Duration +// value. Duration flags must be specified in a format that is valid input for +// `absl::ParseDuration()`. bool AbslParseFlag(absl::string_view text, Duration* dst, std::string* error); - - -// AbslUnparseFlag() -// -// Unparses a Duration value into a command-line string representation using -// the format specified by `absl::ParseDuration()`. + + +// AbslUnparseFlag() +// +// Unparses a Duration value into a command-line string representation using +// the format specified by `absl::ParseDuration()`. std::string AbslUnparseFlag(Duration d); - + ABSL_DEPRECATED("Use AbslParseFlag() instead.") bool ParseFlag(const std::string& text, Duration* dst, std::string* error); ABSL_DEPRECATED("Use AbslUnparseFlag() instead.") @@ -853,13 +853,13 @@ Time FromChrono(const std::chrono::system_clock::time_point& tp); // // tp == std::chrono::system_clock::from_time_t(123); std::chrono::system_clock::time_point ToChronoTime(Time); -// AbslParseFlag() +// AbslParseFlag() +// +// Parses the command-line flag string representation `text` into a Time value. +// Time flags must be specified in a format that matches absl::RFC3339_full. +// +// For example: // -// Parses the command-line flag string representation `text` into a Time value. -// Time flags must be specified in a format that matches absl::RFC3339_full. -// -// For example: -// // --start_time=2016-01-02T03:04:05.678+08:00 // // Note: A UTC offset (or 'Z' indicating a zero-offset from UTC) is required. @@ -868,13 +868,13 @@ std::chrono::system_clock::time_point ToChronoTime(Time); // seconds/milliseconds/etc from the Unix epoch, use an absl::Duration flag // and add that duration to absl::UnixEpoch() to get an absl::Time. bool AbslParseFlag(absl::string_view text, Time* t, std::string* error); - -// AbslUnparseFlag() -// -// Unparses a Time value into a command-line string representation using -// the format specified by `absl::ParseTime()`. + +// AbslUnparseFlag() +// +// Unparses a Time value into a command-line string representation using +// the format specified by `absl::ParseTime()`. std::string AbslUnparseFlag(Time t); - + ABSL_DEPRECATED("Use AbslParseFlag() instead.") bool ParseFlag(const std::string& text, Time* t, std::string* error); ABSL_DEPRECATED("Use AbslUnparseFlag() instead.") @@ -1402,7 +1402,7 @@ constexpr Duration MakeDuration(int64_t hi, int64_t lo) { inline Duration MakePosDoubleDuration(double n) { const int64_t int_secs = static_cast<int64_t>(n); const uint32_t ticks = static_cast<uint32_t>( - std::round((n - static_cast<double>(int_secs)) * kTicksPerSecond)); + std::round((n - static_cast<double>(int_secs)) * kTicksPerSecond)); return ticks < kTicksPerSecond ? MakeDuration(int_secs, ticks) : MakeDuration(int_secs + 1, ticks - kTicksPerSecond); diff --git a/contrib/restricted/abseil-cpp/absl/time/ya.make b/contrib/restricted/abseil-cpp/absl/time/ya.make index 290ec6780a..feb835cc53 100644 --- a/contrib/restricted/abseil-cpp/absl/time/ya.make +++ b/contrib/restricted/abseil-cpp/absl/time/ya.make @@ -19,7 +19,7 @@ PEERDIR( contrib/restricted/abseil-cpp/absl/base/log_severity contrib/restricted/abseil-cpp/absl/numeric contrib/restricted/abseil-cpp/absl/strings - contrib/restricted/abseil-cpp/absl/strings/internal/absl_strings_internal + contrib/restricted/abseil-cpp/absl/strings/internal/absl_strings_internal contrib/restricted/abseil-cpp/absl/time/civil_time contrib/restricted/abseil-cpp/absl/time/time_zone ) |