40#if defined(__GLIBCXX__) && (_GLIBCXX_RELEASE < 13 || __cplusplus < 202002L)
42 "hegel/extras/chrono_tzdb.h needs a standard library that implements std::chrono::get_tzdb(): libstdc++ has it from GCC 13 on, in C++20 mode"
45#include "hegel/generators/zone_source.h"
63 oracle(
const std::chrono::time_zone& zone, int32_t first_year = 1800,
64 int32_t last_year = 2100) {
65 const std::chrono::time_zone* tz = &zone;
67 result.
offset_at = [tz](int64_t instant) {
68 std::chrono::sys_info info = tz->get_info(
69 std::chrono::sys_seconds(std::chrono::seconds(instant)));
71 static_cast<int32_t
>(info.offset.count()),
72 info.save != std::chrono::minutes(0), info.abbrev};
74 result.
next_transition = [tz](int64_t after) -> std::optional<int64_t> {
75 std::chrono::sys_info info = tz->get_info(
76 std::chrono::sys_seconds(std::chrono::seconds(after)));
77 constexpr std::chrono::sys_seconds last_day = std::chrono::sys_days{
78 std::chrono::year::max() / std::chrono::December / 31};
79 if (info.end >= last_day) {
82 return info.end.time_since_epoch().count();
106 const std::chrono::tzdb& db = std::chrono::get_tzdb();
107 std::vector<std::string> names;
108 names.reserve(db.zones.size());
109 for (
const std::chrono::time_zone& zone : db.zones) {
110 names.emplace_back(zone.name());
114 for (
const std::chrono::time_zone_link& link : db.links) {
115 source.
add_link(link.name(), link.target());
119 const std::chrono::time_zone* zone =
nullptr;
121 zone = std::chrono::locate_zone(name);
122 }
catch (
const std::runtime_error&) {
A source of time zone data: the database the zone and zoned datetime generators classify,...
Definition zone_source.h:290
ZoneSource & add_link(std::string_view name, std::string_view target)
ZoneSource & add_oracle(std::string_view name, const ZoneOracle &oracle)
ZoneSource & set_version(std::string_view version)
ZoneSource & declare(const std::vector< std::string > &names)
ZoneSource & set_loader(ZoneLoader loader)
@ Infer
Definition zone_source.h:185
A library that answers offset lookups but does not expose its zone data, probed into explicit transit...
Definition zone_source.h:202
int32_t last_year
Definition zone_source.h:213
AfterProbe after
What is in force after last_year.
Definition zone_source.h:215
std::function< std::optional< int64_t >(int64_t after)> next_transition
Definition zone_source.h:208
int32_t first_year
The first year probed.
Definition zone_source.h:210
std::function< ZoneType(int64_t instant)> offset_at
Definition zone_source.h:205
A local time type of a zone: an offset, its daylight-saving flag and its abbreviation.
Definition zone_source.h:21