|
Hegel 0.18.3
Property-based testing for C++
|
A source of time zone data: the database the zone and zoned datetime generators classify, target and resolve wall times against. More...
#include <zone_source.h>
Public Member Functions | |
| ZoneSource () | |
| An empty source, to be filled with the add_* functions. | |
| ZoneSource & | add_tzif (std::string_view name, const std::vector< uint8_t > &bytes) |
| ZoneSource & | add_tzif (std::string_view name, const uint8_t *data, size_t size) |
| ZoneSource & | add_zone (std::string_view name, const ZoneData &data) |
| ZoneSource & | add_oracle (std::string_view name, const ZoneOracle &oracle) |
| ZoneSource & | add_link (std::string_view name, std::string_view target) |
| ZoneSource & | declare (const std::vector< std::string > &names) |
| ZoneSource & | set_loader (ZoneLoader loader) |
| ZoneSource & | set_version (std::string_view version) |
| std::string | version () const |
| std::optional< ZoneInfo > | info (std::string_view name) const |
| ZonedDateTime | resolve (std::string_view name, const DateTime &civil) const |
| ZoneOffset | offset_at (std::string_view name, const Instant &instant) const |
Static Public Member Functions | |
| static ZoneSource | bundled () |
A source of time zone data: the database the zone and zoned datetime generators classify, target and resolve wall times against.
By default every draw and query uses the engine's bundled IANA database, ZoneSource::bundled(). When the code under test uses another database, give its data to a ZoneSource and either pass it to a generator (zones({.source = source}) or zoned_datetimes({.source = source})) or make it the default with set_default_zone_source(). The zone names, their link and legacy flags and the order they shrink in always come from the bundled catalogue, so a stored failure shrinks the same way everywhere; only what a wall time means in a zone comes from the source. A name the catalogue lacks is drawn too, after every catalogued name, and is never a legacy name, whatever its area (such as Mars/Olympus).
A source takes data in three shapes: TZif files (add_tzif()), fields (add_zone()) and an offset oracle (add_oracle()), plus links (add_link()) and names whose data a loader supplies on first use (declare() and set_loader()).
Build a source once, outside the test body, and share it between test cases: a source built in the body is built again for each one.
Copies share one source: data added through one copy is visible through every other. A source may be used and filled from any number of threads. Add or declare names before building generators that draw from them: a generator reads the names a source knows when it is built.
| ZoneSource & hegel::generators::temporal::ZoneSource::add_link | ( | std::string_view | name, |
| std::string_view | target ) |
Make name a link to target, whose data then applies to both. The target need not be known yet.
| name | The link's name. |
| target | The name it links to. |
| std::invalid_argument | for a bad name or a link to itself. |
| ZoneSource & hegel::generators::temporal::ZoneSource::add_oracle | ( | std::string_view | name, |
| const ZoneOracle & | oracle ) |
Add a zone by probing an offset oracle; see ZoneOracle.
| name | As for add_tzif(). |
| oracle | The callbacks and the probe range. |
| std::invalid_argument | for a missing offset_at, a probe range out of order or outside the engine's years, a callback that throws or answers an invalid type, a next transition that is not later than the instant asked about, more than 100000 transitions or a bad name. |
| ZoneSource & hegel::generators::temporal::ZoneSource::add_tzif | ( | std::string_view | name, |
| const std::vector< uint8_t > & | bytes ) |
Add a zone from a TZif file (RFC 9636, version 2 or later), such as one under /usr/share/zoneinfo. Its 64-bit block and its footer are read.
| name | The name the zone is drawn and queried by: not empty, without NUL bytes and not Etc/Unknown. |
| bytes | The file's contents. |
| std::invalid_argument | for a malformed file, an offset of two days or more or a bad name. |
| ZoneSource & hegel::generators::temporal::ZoneSource::add_tzif | ( | std::string_view | name, |
| const uint8_t * | data, | ||
| size_t | size ) |
Add a zone from a TZif file held in a buffer; see the other add_tzif().
| name | The name the zone is drawn and queried by. |
| data | The first byte of the file's contents, read during the call only. |
| size | The number of bytes. |
| std::invalid_argument | as the other add_tzif() does. |
| ZoneSource & hegel::generators::temporal::ZoneSource::add_zone | ( | std::string_view | name, |
| const ZoneData & | data ) |
Add a zone from its data given as fields.
| name | As for add_tzif(). |
| data | The zone's data. |
| std::invalid_argument | for transitions out of order, an offset of two days or more, a field out of range or a bad name. |
|
static |
The engine's bundled IANA database. It cannot be changed: each add_* and set_* function on it throws std::invalid_argument.
| ZoneSource & hegel::generators::temporal::ZoneSource::declare | ( | const std::vector< std::string > & | names | ) |
Declare names whose data comes later: from the loader the first time a draw or query needs it, or from an add_* call before a zoned datetime is drawn in that zone. A name the source already has keeps what it has.
| names | The names, each as for add_tzif(). |
| std::invalid_argument | for a bad name. |
| std::optional< ZoneInfo > hegel::generators::temporal::ZoneSource::info | ( | std::string_view | name | ) | const |
What this source knows about name, as info() does for the default source. A name the catalogue lacks reports the source's link target, the rank after every catalogued name and the tags of its data and spelling.
| name | The zone name to look up. |
| std::invalid_argument | when loading the name's data fails. |
| ZoneOffset hegel::generators::temporal::ZoneSource::offset_at | ( | std::string_view | name, |
| const Instant & | instant ) const |
The offset a zone of this source has in force at an instant, as offset_at() does for the default source.
| name | The zone name. |
| instant | The instant to look up. |
| std::invalid_argument | as offset_at() does, or when the source has no data for name. |
| ZonedDateTime hegel::generators::temporal::ZoneSource::resolve | ( | std::string_view | name, |
| const DateTime & | civil ) const |
| ZoneSource & hegel::generators::temporal::ZoneSource::set_loader | ( | ZoneLoader | loader | ) |
Set the loader asked for the data of a name the source lacks; see ZoneLoader. It replaces the loader set before, which is destroyed once no call of it is running, and an empty function removes it. A name the loader adds nothing for is unknown from then on.
| loader | The loader. |
| std::invalid_argument | for the bundled source. |
| ZoneSource & hegel::generators::temporal::ZoneSource::set_version | ( | std::string_view | version | ) |
Record which release of its database the source holds. Failure output does not report it.
| version | The release, such as "2026e". |
| std::string hegel::generators::temporal::ZoneSource::version | ( | ) | const |