| |
| |
| |
| |
| |
| |
| |
|
|
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
|
|
| #include <__config> |
|
|
| |
| #ifdef _LIBCPP_COMPILER_GCC |
| # pragma GCC optimize("-O0") |
| #endif |
|
|
| #include <algorithm> |
| #include <cctype> |
| #include <chrono> |
| #include <expected> |
| #include <map> |
| #include <numeric> |
| #include <ranges> |
|
|
| #include "include/tzdb/time_zone_private.h" |
| #include "include/tzdb/tzdb_list_private.h" |
|
|
| |
| #ifdef PRINT |
| # include <print> |
| #endif |
|
|
| _LIBCPP_BEGIN_NAMESPACE_STD |
|
|
| #ifdef PRINT |
| template <> |
| struct formatter<chrono::sys_info, char> { |
| template <class ParseContext> |
| constexpr typename ParseContext::iterator parse(ParseContext& ctx) { |
| return ctx.begin(); |
| } |
|
|
| template <class FormatContext> |
| typename FormatContext::iterator format(const chrono::sys_info& info, FormatContext& ctx) const { |
| return std::format_to( |
| ctx.out(), "[{}, {}) {:%Q%q} {:%Q%q} {}", info.begin, info.end, info.offset, info.save, info.abbrev); |
| } |
| }; |
| #endif |
|
|
| namespace chrono { |
|
|
| |
| |
| |
|
|
| struct __sys_info { |
| sys_info __info; |
| bool __can_merge; |
| }; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| using __sys_info_result = expected<__sys_info, sys_seconds>; |
|
|
| template <ranges::forward_range _Range, |
| class _Type, |
| class _Proj = identity, |
| indirect_strict_weak_order<const _Type*, projected<ranges::iterator_t<_Range>, _Proj>> _Comp = ranges::less> |
| [[nodiscard]] static ranges::borrowed_iterator_t<_Range> |
| __binary_find(_Range&& __r, const _Type& __value, _Comp __comp = {}, _Proj __proj = {}) { |
| auto __end = ranges::end(__r); |
| auto __ret = ranges::lower_bound(ranges::begin(__r), __end, __value, __comp, __proj); |
| if (__ret == __end) |
| return __end; |
|
|
| |
| |
| return !std::invoke(__comp, __value, std::invoke(__proj, *__ret)) ? __ret : __end; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| [[nodiscard]] static string |
| __format(const __tz::__continuation& __continuation, const string& __letters, seconds __save) { |
| bool __shift = false; |
| string __result; |
| for (char __c : __continuation.__format) { |
| if (__shift) { |
| switch (__c) { |
| case 's': |
| std::ranges::copy(__letters, std::back_inserter(__result)); |
| break; |
|
|
| case 'z': { |
| if (__continuation.__format.size() != 2) |
| std::__throw_runtime_error( |
| std::format("corrupt tzdb FORMAT field: %z should be the entire contents, instead contains '{}'", |
| __continuation.__format) |
| .c_str()); |
| chrono::hh_mm_ss __offset{__continuation.__stdoff + __save}; |
| if (__offset.is_negative()) { |
| __result += '-'; |
| __offset = chrono::hh_mm_ss{-(__continuation.__stdoff + __save)}; |
| } else |
| __result += '+'; |
|
|
| if (__offset.minutes() != 0min) |
| std::format_to(std::back_inserter(__result), "{:%H%M}", __offset); |
| else |
| std::format_to(std::back_inserter(__result), "{:%H}", __offset); |
| } break; |
|
|
| default: |
| std::__throw_runtime_error( |
| std::format("corrupt tzdb FORMAT field: invalid sequence '%{}' found, expected %s or %z", __c).c_str()); |
| } |
| __shift = false; |
|
|
| } else if (__c == '/') { |
| if (__save != 0s) |
| __result.clear(); |
| else |
| break; |
|
|
| } else if (__c == '%') { |
| __shift = true; |
| } else if (__c == '+' || __c == '-' || std::isalnum(__c)) { |
| __result.push_back(__c); |
| } else { |
| std::__throw_runtime_error( |
| std::format( |
| "corrupt tzdb FORMAT field: invalid character '{}' found, expected +, -, or an alphanumeric value", __c) |
| .c_str()); |
| } |
| } |
|
|
| if (__shift) |
| std::__throw_runtime_error("corrupt tzdb FORMAT field: input ended with the start of the escape sequence '%'"); |
|
|
| if (__result.empty()) |
| std::__throw_runtime_error("corrupt tzdb FORMAT field: result is empty"); |
|
|
| return __result; |
| } |
|
|
| [[nodiscard]] static sys_seconds __to_sys_seconds(year_month_day __ymd, seconds __seconds) { |
| seconds __result = static_cast<sys_days>(__ymd).time_since_epoch() + __seconds; |
| return sys_seconds{__result}; |
| } |
|
|
| [[nodiscard]] static seconds __at_to_sys_seconds(const __tz::__continuation& __continuation) { |
| switch (__continuation.__at.__clock) { |
| case __tz::__clock::__local: |
| return __continuation.__at.__time - __continuation.__stdoff - |
| std::visit( |
| [](const auto& __value) { |
| using _Tp = decay_t<decltype(__value)>; |
| if constexpr (same_as<_Tp, monostate>) |
| return chrono::seconds{0}; |
| else if constexpr (same_as<_Tp, __tz::__save>) |
| return chrono::duration_cast<seconds>(__value.__time); |
| else if constexpr (same_as<_Tp, std::string>) |
| |
| |
| return chrono::seconds{0}; |
| else |
| static_assert(false); |
|
|
| std::__libcpp_unreachable(); |
| }, |
| __continuation.__rules); |
|
|
| case __tz::__clock::__universal: |
| return __continuation.__at.__time; |
|
|
| case __tz::__clock::__standard: |
| return __continuation.__at.__time - __continuation.__stdoff; |
| } |
| std::__libcpp_unreachable(); |
| } |
|
|
| [[nodiscard]] static year_month_day __to_year_month_day(year __year, month __month, __tz::__on __on) { |
| return std::visit( |
| [&](const auto& __value) { |
| using _Tp = decay_t<decltype(__value)>; |
| if constexpr (same_as<_Tp, chrono::day>) |
| return year_month_day{__year, __month, __value}; |
| else if constexpr (same_as<_Tp, weekday_last>) |
| return year_month_day{static_cast<sys_days>(year_month_weekday_last{__year, __month, __value})}; |
| else if constexpr (same_as<_Tp, __tz::__constrained_weekday>) |
| return __value(__year, __month); |
| else |
| static_assert(false); |
|
|
| std::__libcpp_unreachable(); |
| }, |
| __on); |
| } |
|
|
| [[nodiscard]] static sys_seconds __until_to_sys_seconds(const __tz::__continuation& __continuation) { |
| |
| if (__continuation.__year == chrono::year::min()) |
| return sys_seconds::max(); |
|
|
| year_month_day __ymd = chrono::__to_year_month_day(__continuation.__year, __continuation.__in, __continuation.__on); |
| return chrono::__to_sys_seconds(__ymd, chrono::__at_to_sys_seconds(__continuation)); |
| } |
|
|
| |
| |
| |
| |
| |
| class __named_rule_until { |
| public: |
| explicit __named_rule_until(const __tz::__continuation& __continuation) |
| : __until_{chrono::__until_to_sys_seconds(__continuation)}, |
| __needs_adjustment_{ |
| |
| |
| |
| |
| |
| |
| __until_ != sys_seconds::max() && __continuation.__at.__clock == __tz::__clock::__local} {} |
|
|
| |
| |
| sys_seconds __until() const noexcept { return __until_; } |
|
|
| bool __needs_adjustment() const noexcept { return __needs_adjustment_; } |
|
|
| |
| sys_seconds operator()(seconds __save) const noexcept { return __until_ - __needs_adjustment_ * __save; } |
|
|
| private: |
| sys_seconds __until_; |
| bool __needs_adjustment_; |
| }; |
|
|
| [[nodiscard]] static seconds __at_to_seconds(seconds __stdoff, const __tz::__rule& __rule) { |
| switch (__rule.__at.__clock) { |
| case __tz::__clock::__local: |
| |
| |
| |
| |
| |
| return __rule.__at.__time - __stdoff; |
|
|
| case __tz::__clock::__universal: |
| return __rule.__at.__time; |
|
|
| case __tz::__clock::__standard: |
| return __rule.__at.__time - __stdoff; |
| } |
| std::__libcpp_unreachable(); |
| } |
|
|
| [[nodiscard]] static sys_seconds __from_to_sys_seconds(seconds __stdoff, const __tz::__rule& __rule, year __year) { |
| year_month_day __ymd = chrono::__to_year_month_day(__year, __rule.__in, __rule.__on); |
|
|
| seconds __at = chrono::__at_to_seconds(__stdoff, __rule); |
| return chrono::__to_sys_seconds(__ymd, __at); |
| } |
|
|
| [[nodiscard]] static sys_seconds __from_to_sys_seconds(seconds __stdoff, const __tz::__rule& __rule) { |
| return chrono::__from_to_sys_seconds(__stdoff, __rule, __rule.__from); |
| } |
|
|
| [[nodiscard]] static const vector<__tz::__rule>& |
| __get_rules(const __tz::__rules_storage_type& __rules_db, const string& __rule_name) { |
| auto __result = chrono::__binary_find(__rules_db, __rule_name, {}, [](const auto& __p) { return __p.first; }); |
| if (__result == std::end(__rules_db)) |
| std::__throw_runtime_error(("corrupt tzdb: rule '" + __rule_name + " 'does not exist").c_str()); |
|
|
| return __result->second; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| [[nodiscard]] static string __letters_before_first_rule(const vector<__tz::__rule>& __rules) { |
| auto __letters = |
| __rules |
| | views::filter([](const __tz::__rule& __rule) { return __rule.__save.__time == 0s; }) |
| | views::transform([](const __tz::__rule& __rule) { return __rule.__letters; }) |
| | views::take(1); |
|
|
| if (__letters.empty()) |
| std::__throw_runtime_error("corrupt tzdb: rule has zero entries"); |
|
|
| return __letters.front(); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| [[nodiscard]] static sys_info __get_sys_info_before_first_rule( |
| sys_seconds __begin, |
| sys_seconds __end, |
| const __tz::__continuation& __continuation, |
| const vector<__tz::__rule>& __rules) { |
| return sys_info{ |
| __begin, |
| __end, |
| __continuation.__stdoff, |
| chrono::minutes(0), |
| chrono::__format(__continuation, __letters_before_first_rule(__rules), 0s)}; |
| } |
|
|
| |
| |
| |
| [[nodiscard]] static sys_info __get_sys_info_before_first_rule( |
| sys_seconds __begin, |
| sys_seconds __rule_end, |
| sys_seconds __next_end, |
| const __tz::__continuation& __continuation, |
| const vector<__tz::__rule>& __rules, |
| vector<__tz::__rule>::const_iterator __rule) { |
| if (__rule->__save.__time != 0s) |
| return __get_sys_info_before_first_rule(__begin, __rule_end, __continuation, __rules); |
|
|
| return sys_info{ |
| __begin, __next_end, __continuation.__stdoff, 0min, chrono::__format(__continuation, __rule->__letters, 0s)}; |
| } |
|
|
| [[nodiscard]] static seconds __at_to_seconds(seconds __stdoff, seconds __save, const __tz::__rule& __rule) { |
| switch (__rule.__at.__clock) { |
| case __tz::__clock::__local: |
| return __rule.__at.__time - __stdoff - __save; |
|
|
| case __tz::__clock::__universal: |
| return __rule.__at.__time; |
|
|
| case __tz::__clock::__standard: |
| return __rule.__at.__time - __stdoff; |
| } |
| std::__libcpp_unreachable(); |
| } |
|
|
| [[nodiscard]] static sys_seconds |
| __rule_to_sys_seconds(seconds __stdoff, seconds __save, const __tz::__rule& __rule, year __year) { |
| year_month_day __ymd = chrono::__to_year_month_day(__year, __rule.__in, __rule.__on); |
|
|
| seconds __at = chrono::__at_to_seconds(__stdoff, __save, __rule); |
| return chrono::__to_sys_seconds(__ymd, __at); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| [[nodiscard]] static pair<sys_seconds, vector<__tz::__rule>::const_iterator> |
| __next_rule(sys_seconds __time, |
| seconds __stdoff, |
| seconds __save, |
| const vector<__tz::__rule>& __rules, |
| vector<__tz::__rule>::const_iterator __current) { |
| year __year = year_month_day{chrono::floor<days>(__time)}.year(); |
|
|
| |
| |
| map<sys_seconds, vector<__tz::__rule>::const_iterator> __candidates; |
| |
| |
| |
| for (auto __it = __rules.begin(); __it != __rules.end(); ++__it) { |
| for (year __y = __it->__from; __y <= __it->__to; ++__y) { |
| |
| |
| if (__y == __year && __it == __current) |
| continue; |
|
|
| sys_seconds __t = chrono::__rule_to_sys_seconds(__stdoff, __save, *__it, __y); |
| if (__t <= __time) |
| continue; |
|
|
| _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(!__candidates.contains(__t), "duplicated rule"); |
| __candidates[__t] = __it; |
| break; |
| } |
| } |
|
|
| if (!__candidates.empty()) [[likely]] { |
| auto __it = __candidates.begin(); |
|
|
| |
| |
| if (__time == sys_seconds::min()) |
| return *__it; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| while (__it != __candidates.end()) { |
| if (__current->__save.__time != __it->second->__save.__time || __current->__letters != __it->second->__letters) |
| return *__it; |
|
|
| ++__it; |
| } |
| } |
|
|
| return {sys_seconds::max(), __rules.end()}; |
| } |
|
|
| |
| |
| |
| |
| |
| [[nodiscard]] static vector<__tz::__rule>::const_iterator |
| __first_rule(seconds __stdoff, const vector<__tz::__rule>& __rules) { |
| return chrono::__next_rule(sys_seconds::min(), __stdoff, 0s, __rules, __rules.end()).second; |
| } |
|
|
| [[nodiscard]] static __sys_info_result __get_sys_info_rule( |
| sys_seconds __time, |
| sys_seconds __continuation_begin, |
| const __tz::__continuation& __continuation, |
| const vector<__tz::__rule>& __rules) { |
| auto __rule = chrono::__first_rule(__continuation.__stdoff, __rules); |
| _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(__rule != __rules.end(), "the set of rules has no first rule"); |
|
|
| |
| __time = std::max(__time, __continuation_begin); |
|
|
| sys_seconds __rule_begin = chrono::__from_to_sys_seconds(__continuation.__stdoff, *__rule); |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| auto __next = chrono::__next_rule(__rule_begin, __continuation.__stdoff, __rule->__save.__time, __rules, __rule); |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| if (sys_seconds __begin = __rule->__save.__time != 0s ? __rule_begin : __next.first; __time < __begin) { |
| if (__continuation_begin == sys_seconds::min() || __begin - __continuation_begin > 12h) |
| return __sys_info{__get_sys_info_before_first_rule( |
| __continuation_begin, __rule_begin, __next.first, __continuation, __rules, __rule), |
| false}; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| seconds __save = __rule->__save.__time; |
| __named_rule_until __continuation_end{__continuation}; |
| sys_seconds __sys_info_end = std::min(__continuation_end(__save), __next.first); |
|
|
| return __sys_info{ |
| sys_info{__continuation_begin, |
| __sys_info_end, |
| __continuation.__stdoff + __save, |
| chrono::duration_cast<minutes>(__save), |
| chrono::__format(__continuation, __rule->__letters, __save)}, |
| __sys_info_end == __continuation_end(__save)}; |
| } |
|
|
| |
| if (__rule->__save.__time == 0s && __time < __next.first) { |
| return __sys_info{ |
| sys_info{__continuation_begin, |
| __next.first, |
| __continuation.__stdoff, |
| 0min, |
| chrono::__format(__continuation, __rule->__letters, 0s)}, |
| false}; |
| } |
|
|
| if (__rule->__save.__time != 0s) { |
| |
| |
| seconds __save = __rule->__save.__time; |
| if (__continuation_begin >= __rule_begin - __save && __time < __next.first) { |
| return __sys_info{ |
| sys_info{__continuation_begin, |
| __next.first, |
| __continuation.__stdoff + __save, |
| chrono::duration_cast<minutes>(__save), |
| chrono::__format(__continuation, __rule->__letters, __save)}, |
| false}; |
| } |
| } |
|
|
| __named_rule_until __continuation_end{__continuation}; |
| while (__next.second != __rules.end()) { |
| #ifdef PRINT |
| std::print( |
| stderr, |
| "Rule for {}: [{}, {}) off={} save={} duration={}\n", |
| __time, |
| __rule_begin, |
| __next.first, |
| __continuation.__stdoff, |
| __rule->__save.__time, |
| __next.first - __rule_begin); |
| #endif |
|
|
| sys_seconds __end = __continuation_end(__rule->__save.__time); |
|
|
| sys_seconds __sys_info_begin = std::max(__continuation_begin, __rule_begin); |
| sys_seconds __sys_info_end = std::min(__end, __next.first); |
| seconds __diff = chrono::abs(__sys_info_end - __sys_info_begin); |
|
|
| if (__diff < 12h) { |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
|
|
| __rule = __next.second; |
| __next = __next_rule(__next.first, __continuation.__stdoff, __rule->__save.__time, __rules, __rule); |
| __end = __continuation_end(__rule->__save.__time); |
| __sys_info_end = std::min(__end, __next.first); |
| } |
|
|
| if ((__time >= __rule_begin && __time < __next.first) || __next.first >= __end) { |
| __sys_info_begin = std::max(__continuation_begin, __rule_begin); |
| __sys_info_end = std::min(__end, __next.first); |
|
|
| return __sys_info{ |
| sys_info{__sys_info_begin, |
| __sys_info_end, |
| __continuation.__stdoff + __rule->__save.__time, |
| chrono::duration_cast<minutes>(__rule->__save.__time), |
| chrono::__format(__continuation, __rule->__letters, __rule->__save.__time)}, |
| __sys_info_end == __end}; |
| } |
|
|
| __rule_begin = __next.first; |
| __rule = __next.second; |
| __next = __next_rule(__rule_begin, __continuation.__stdoff, __rule->__save.__time, __rules, __rule); |
| } |
|
|
| return __sys_info{ |
| sys_info{std::max(__continuation_begin, __rule_begin), |
| __continuation_end(__rule->__save.__time), |
| __continuation.__stdoff + __rule->__save.__time, |
| chrono::duration_cast<minutes>(__rule->__save.__time), |
| chrono::__format(__continuation, __rule->__letters, __rule->__save.__time)}, |
| true}; |
| } |
|
|
| [[nodiscard]] static __sys_info_result __get_sys_info_basic( |
| sys_seconds __time, sys_seconds __continuation_begin, const __tz::__continuation& __continuation, seconds __save) { |
| sys_seconds __continuation_end = chrono::__until_to_sys_seconds(__continuation); |
| return __sys_info{ |
| sys_info{__continuation_begin, |
| __continuation_end, |
| __continuation.__stdoff + __save, |
| chrono::duration_cast<minutes>(__save), |
| chrono::__format(__continuation, __continuation.__format, __save)}, |
| true}; |
| } |
|
|
| [[nodiscard]] static __sys_info_result |
| __get_sys_info(sys_seconds __time, |
| sys_seconds __continuation_begin, |
| const __tz::__continuation& __continuation, |
| const __tz::__rules_storage_type& __rules_db) { |
| return std::visit( |
| [&](const auto& __value) { |
| using _Tp = decay_t<decltype(__value)>; |
| if constexpr (same_as<_Tp, std::string>) |
| return chrono::__get_sys_info_rule( |
| __time, __continuation_begin, __continuation, __get_rules(__rules_db, __value)); |
| else if constexpr (same_as<_Tp, monostate>) |
| return chrono::__get_sys_info_basic(__time, __continuation_begin, __continuation, chrono::seconds(0)); |
| else if constexpr (same_as<_Tp, __tz::__save>) |
| return chrono::__get_sys_info_basic(__time, __continuation_begin, __continuation, __value.__time); |
| else |
| static_assert(false); |
|
|
| std::__libcpp_unreachable(); |
| }, |
| __continuation.__rules); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| [[nodiscard]] bool __merge_continuation(sys_info& __current, const sys_info& __next) { |
| if (__current.end != __next.begin) |
| return false; |
|
|
| if (__current.offset != __next.offset || __current.abbrev != __next.abbrev || __current.save != __next.save) |
| return false; |
|
|
| __current.end = __next.end; |
| return true; |
| } |
|
|
| |
| |
| |
|
|
| [[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI time_zone time_zone::__create(unique_ptr<time_zone::__impl>&& __p) { |
| _LIBCPP_ASSERT_NON_NULL(__p != nullptr, "initialized time_zone without a valid pimpl object"); |
| time_zone result; |
| result.__impl_ = std::move(__p); |
| return result; |
| } |
|
|
| _LIBCPP_EXPORTED_FROM_ABI time_zone::~time_zone() = default; |
|
|
| [[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI string_view time_zone::__name() const noexcept { return __impl_->__name(); } |
|
|
| [[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI sys_info |
| time_zone::__get_info(sys_seconds __time) const { |
| optional<sys_info> __result; |
| bool __valid_result = false; |
| |
| bool __can_merge = false; |
| sys_seconds __continuation_begin = sys_seconds::min(); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| const auto& __continuations = __impl_->__continuations(); |
| const __tz::__rules_storage_type& __rules_db = __impl_->__rules_db(); |
| for (auto __it = __continuations.begin(); __it != __continuations.end(); ++__it) { |
| const auto& __continuation = *__it; |
| __sys_info_result __sys_info = chrono::__get_sys_info(__time, __continuation_begin, __continuation, __rules_db); |
|
|
| if (__sys_info) { |
| _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN( |
| __sys_info->__info.begin < __sys_info->__info.end, "invalid sys_info range"); |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| if (std::holds_alternative<string>(__continuation.__rules) && __sys_info->__can_merge && |
| __sys_info->__info.begin + 12h > __sys_info->__info.end) { |
| __continuation_begin = __sys_info->__info.begin; |
| continue; |
| } |
|
|
| if (!__result) { |
| |
| __result = __sys_info->__info; |
|
|
| __valid_result = __time >= __result->begin && __time < __result->end; |
| __can_merge = __sys_info->__can_merge; |
| } else if (__can_merge && chrono::__merge_continuation(*__result, __sys_info->__info)) { |
| |
| |
| |
| __valid_result = __time >= __result->begin && __time < __result->end; |
| __can_merge = __sys_info->__can_merge; |
| } else { |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| if (__valid_result) { |
| return *__result; |
| } else { |
| _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN( |
| __it != __continuations.begin(), "the first rule should always seed the result"); |
| const auto& __last = *(__it - 1); |
| if (std::holds_alternative<string>(__last.__rules)) { |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| if (__result->end != __sys_info->__info.begin) { |
| |
| |
| sys_seconds __end = __result->end - __result->offset; |
| sys_seconds __begin = __sys_info->__info.begin - __sys_info->__info.offset; |
| if (__end == __begin) { |
| __sys_info->__info.begin = __result->end; |
| } |
| } |
| } |
|
|
| __result = __sys_info->__info; |
| __valid_result = __time >= __result->begin && __time < __result->end; |
| __can_merge = __sys_info->__can_merge; |
| } |
| } |
| __continuation_begin = __result->end; |
| } else { |
| __continuation_begin = __sys_info.error(); |
| } |
| } |
| if (__valid_result) |
| return *__result; |
|
|
| std::__throw_runtime_error("tzdb: corrupt db"); |
| } |
|
|
| |
| |
| [[nodiscard]] static bool |
| __is_ambiguous(local_seconds __local_time, const sys_info& __first, const sys_info& __second) { |
| std::chrono::local_seconds __end_first{__first.end.time_since_epoch() + __first.offset}; |
| std::chrono::local_seconds __begin_second{__second.begin.time_since_epoch() + __second.offset}; |
|
|
| return __local_time < __end_first && __local_time >= __begin_second; |
| } |
|
|
| |
| |
| [[nodiscard]] static local_info |
| __get_info(local_seconds __local_time, const sys_info& __first, const sys_info& __second) { |
| std::chrono::local_seconds __end_first{__first.end.time_since_epoch() + __first.offset}; |
| std::chrono::local_seconds __begin_second{__second.begin.time_since_epoch() + __second.offset}; |
|
|
| if (__local_time < __end_first) { |
| if (__local_time >= __begin_second) |
| |
| |
| |
| return {local_info::ambiguous, __first, __second}; |
|
|
| |
| |
| |
| return {local_info::unique, __first, sys_info{}}; |
| } |
|
|
| if (__local_time < __begin_second) |
| |
| |
| |
| return {local_info::nonexistent, __first, __second}; |
|
|
| |
| |
| |
| return {local_info::unique, __second, sys_info{}}; |
| } |
|
|
| [[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI local_info |
| time_zone::__get_info(local_seconds __local_time) const { |
| seconds __local_seconds = __local_time.time_since_epoch(); |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| sys_seconds __guess{__local_seconds}; |
| sys_info __info = __get_info(__guess); |
|
|
| |
| |
| |
| |
| if (__local_seconds < 0s && __info.offset > 0s) |
| if (__local_seconds - chrono::local_seconds::min().time_since_epoch() < __info.offset) |
| return {-1, __info, {}}; |
|
|
| if (__local_seconds > 0s && __info.offset < 0s) |
| if (chrono::local_seconds::max().time_since_epoch() - __local_seconds < -__info.offset) |
| return {-2, __info, {}}; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| sys_seconds __sys_time{__local_seconds - __info.offset}; |
| if (__sys_time < __info.begin) |
| |
| return chrono::__get_info(__local_time, __get_info(__info.begin - 1s), __info); |
|
|
| if (__sys_time >= __info.end) |
| |
| return chrono::__get_info(__local_time, __info, __get_info(__info.end)); |
|
|
| |
| if (__info.begin != sys_seconds::min()) { |
| |
| |
| sys_info __prev = __get_info(__info.begin - 1s); |
| if (__is_ambiguous(__local_time, __prev, __info)) |
| return {local_info::ambiguous, __prev, __info}; |
| } |
|
|
| if (__info.end == sys_seconds::max()) |
| |
| return {local_info::unique, __info, sys_info{}}; |
|
|
| |
| return chrono::__get_info(__local_time, __info, __get_info(__info.end)); |
| } |
|
|
| } |
|
|
| _LIBCPP_END_NAMESPACE_STD |
|
|