Hegel 0.18.3
Property-based testing for C++
Loading...
Searching...
No Matches
hegel::generators::temporal Namespace Reference

Date and time generators, and the plain values they draw. More...

Classes

struct  DatesParams
 Parameters for dates() generator. More...
struct  TimesParams
 Parameters for times() generator. More...
struct  DatetimesParams
 Parameters for datetimes() generator. More...
struct  InstantsParams
 Parameters for instants() generator over a std::chrono::system_clock time point. More...
struct  InstantsParams< Instant >
 Parameters for instants() generator over Instant. More...
struct  OffsetsParams
 Parameters for offsets() generator. More...
struct  ZonesParams
 Parameters for zones() generator. More...
struct  ZonedDatetimesParams
 Parameters for zoned_datetimes() generator. More...
struct  UnitBounds
 Inclusive bounds on one unit of a span, for SpansParams. More...
struct  SpansParams
 Parameters for spans() generator. More...
struct  DurationsParams
 Parameters for durations() generator over a std::chrono::duration. More...
struct  DurationsParams< SignedDuration >
 Parameters for durations() generator over SignedDuration. More...
struct  Date
 A proleptic Gregorian calendar date. More...
struct  Time
 A time of day from 00:00:00 to 23:59:59.999999999. More...
struct  DateTime
 A wall-clock date and time with no zone or offset, in the range of Date and Time. Prints as 2024-03-10T02:30:00. More...
struct  Instant
 An instant. More...
struct  UtcOffset
 A UTC offset: a known number of seconds east of UTC within ±25:59:59 (MAX_OFFSET), or the unknown offset of RFC 3339's -00:00, which the offset and zone draws yield only when asked to. More...
struct  TimeZone
 A time zone of a zone source, or UNKNOWN_ZONE. More...
struct  ZonedDateTime
 A wall-clock time in a time zone, resolved to an instant. More...
struct  SignedDuration
 A signed duration: seconds plus nanoseconds of the same sign, the latter within ±999999999, so -1.5 s is {-1, -500000000}. More...
struct  Span
 A calendar span: a signed count of each unit from years to nanoseconds, never normalised (90 minutes is not an hour and a half, and a month is not a number of days). More...
struct  ZoneInfo
 What a zone source knows about a time zone name; see info(). More...
struct  ZoneOffset
 The offset a time zone has in force at an instant; see offset_at(). More...
struct  ZoneType
 A local time type of a zone: an offset, its daylight-saving flag and its abbreviation. More...
struct  ZoneTransition
 An explicit transition: from instant on, type is in force. More...
struct  RuleDate
 The day and time of day a yearly rule changes the clocks on, as a POSIX TZ string names them (RFC 9636 §3.3.1). More...
struct  DaylightRule
 Daylight-saving time of a yearly rule: its type, and the dates it starts and ends on each year. More...
struct  ZoneRule
 A yearly rule in force after a zone's explicit transitions: the footer of a TZif file. More...
struct  HoldLast
 The last type in force, held for ever after the explicit transitions. More...
struct  InferRule
 A yearly rule the engine infers from the transitions of last_year and the year before it. More...
struct  ZoneData
 A zone's data given as fields: the TZif model of RFC 9636. More...
struct  ZoneOracle
 A library that answers offset lookups but does not expose its zone data, probed into explicit transitions over the years first_year to last_year. More...
class  ZoneSource
 A source of time zone data: the database the zone and zoned datetime generators classify, target and resolve wall times against. More...

Typedefs

using ZoneLoader
 Supplies a zone source's data for a name the first time a draw or a query needs it.

Enumerations

enum class  TransitionKind { Unique , Gap , Fold }
 How a wall-clock time maps to instants in its zone. More...
enum class  SpanUnit {
  Years , Months , Weeks , Days ,
  Hours , Minutes , Seconds , Milliseconds ,
  Microseconds , Nanoseconds
}
 A unit of a Span, largest first. More...
enum class  Precision {
  Nanoseconds , Microseconds , Milliseconds , Seconds ,
  Minutes , Hours
}
enum class  Granularity { Hours , QuarterHours , Minutes , Seconds }
 The values a UTC offset draw restricts itself to. More...
enum class  Weekday {
  Monday , Tuesday , Wednesday , Thursday ,
  Friday , Saturday , Sunday
}
 A day of the week, for restricting a date draw. More...
enum class  Month {
  January , February , March , April ,
  May , June , July , August ,
  September , October , November , December
}
 A month of the year, for restricting a date draw. More...
enum class  Ambiguous { Both , Earlier , Later }
enum class  SpanSign { Uniform , Mixed , NonNegative }
 How the signs of a span's units are drawn. More...
enum class  Tag {
  Fixed , WholeHour , Fractional , Seconds ,
  Dst , DstOther , Multi , BaseChange ,
  Midnight , SpansMidnight , WholeDay , SameOffset ,
  Undefined , Link , Legacy , InvertedSign
}
 A feature of a time zone, derived from its offsets and name. More...
enum class  AfterProbe { Hold , Infer }

Functions

Generator< Date > dates (const DatesParams &params={})
 Generate Date values.
Generator< Time > times (TimesParams params={})
 Generate Time values.
Generator< DateTime > datetimes (DatetimesParams params={})
 Generate DateTime values.
Generator< UtcOffset > offsets (OffsetsParams params={})
 Generate UtcOffset values.
Generator< TimeZone > zones (const ZonesParams &params={})
 Generate TimeZone values.
Generator< ZonedDateTime > zoned_datetimes (const ZonedDatetimesParams &params={})
 Generate ZonedDateTime values: a zone, a wall-clock time in it and, when the clocks repeated that time, which repeat is meant.
Generator< Span > spans (SpansParams params={})
 Generate Span values.
template<typename TimePoint = Instant>
Generator< TimePoint > instants (InstantsParams< TimePoint > params={})
 Generate Instant values, or std::chrono::system_clock time points when TimePoint is one.
template<typename Duration = SignedDuration>
Generator< Duration > durations (DurationsParams< Duration > params={})
 Generate SignedDuration values, or std::chrono::duration values when Duration is one.
std::string tzdb_version ()
 The IANA release of the time zone database bundled in the engine, such as "2026e".
std::optional< ZoneInfo > info (std::string_view name)
 What the default zone source knows about name, matched exactly as the source spells it, or std::nullopt for a name it lacks.
ZonedDateTime resolve (std::string_view name, const DateTime &civil)
 Classify the wall-clock time civil in the zone name and resolve it to an instant, meaning the earlier instant of a repeated wall time (fold false); the later is the wall time read with offset_after.
ZoneOffset offset_at (std::string_view name, const Instant &instant)
 The offset the zone name has in force at instant.
ZoneSource default_zone_source ()
 The process-wide default zone source: the one zones(), zoned_datetimes() and the info(), resolve() and offset_at() queries use when given no source.
ZoneSource set_default_zone_source (const ZoneSource &source)
 Replace the process-wide default zone source.
Comparison

Date, Time, DateTime, Instant, UtcOffset, TimeZone, ZonedDateTime, SignedDuration and Span each compare for equality and have a total order, so they work as keys of std::set and std::map and in sets(); each also has a std::hash, for the unordered containers.

Date, Time, DateTime and Instant order from earlier to later and SignedDuration from shorter to longer. UtcOffset orders the unknown offset before every known one, then from west to east. TimeZone orders by name, then primary_name. ZonedDateTime orders by instant, then by its other fields. Span orders by its units, largest first, which is not an order by length: a span has no length without a date to start from.

template<typename T>
constexpr detail::if_value< T, bool > operator== (const T &a, const T &b)
template<typename T>
constexpr detail::if_value< T, bool > operator!= (const T &a, const T &b)
template<typename T>
constexpr detail::if_value< T, bool > operator< (const T &a, const T &b)
template<typename T>
constexpr detail::if_value< T, bool > operator> (const T &a, const T &b)
template<typename T>
constexpr detail::if_value< T, bool > operator<= (const T &a, const T &b)
template<typename T>
constexpr detail::if_value< T, bool > operator>= (const T &a, const T &b)
Text

The text of a value is the text the engine defines for it. No value is refused: a value outside the range of its type prints its fields as they are.

std::string to_string (const Date &date)
std::string to_string (const Time &time)
std::string to_string (const DateTime &datetime)
std::string to_string (const Instant &instant)
std::string to_string (const UtcOffset &offset)
std::string to_string (const TimeZone &zone)
std::string to_string (const ZonedDateTime &zoned)
std::string to_string (const SignedDuration &duration)
std::string to_string (const Span &span)
template<typename T>
detail::if_value< T, std::ostream & > operator<< (std::ostream &os, const T &value)
ZoneInfo comparison
bool operator== (const ZoneInfo &a, const ZoneInfo &b)
bool operator!= (const ZoneInfo &a, const ZoneInfo &b)
ZoneOffset comparison
bool operator== (const ZoneOffset &a, const ZoneOffset &b)
bool operator!= (const ZoneOffset &a, const ZoneOffset &b)

Variables

constexpr int32_t MIN_YEAR = -999'999
 The lowest year of a Date.
constexpr int32_t MAX_YEAR = 999'999
 The highest year of a Date.
constexpr int64_t MIN_INSTANT = -31'619'087'596'800
 The first second of MIN_YEAR, the lowest second of an Instant.
constexpr int64_t MAX_INSTANT = 31'494'784'780'799
 The last second of MAX_YEAR, the highest second of an Instant.
constexpr int32_t MAX_OFFSET = 93'599
 The largest magnitude of a known UtcOffset in seconds, 25:59:59.
constexpr std::string_view UNKNOWN_ZONE = "Etc/Unknown"
constexpr UtcOffset UNKNOWN_OFFSET {0, false}
 The unknown offset, RFC 3339's -00:00.
constexpr std::array< SpanUnit, 10 > ALL_SPAN_UNITS
 Every SpanUnit, largest first.
constexpr std::array< Tag, 16 > ALL_TAGS
 Every Tag, in the order of the engine's bit set.

Detailed Description

Date and time generators, and the plain values they draw.

Every value type here is an aggregate of public fields mirroring the engine's value model one to one, with no arithmetic and no parsing: a test that uses a date library wraps the value it draws with map, and nothing here competes with that library. The generators over these types are dates(), times(), datetimes(), instants(), offsets(), zones(), zoned_datetimes(), durations() and spans(), and the parameter structs and option enums they take. instants<TimePoint>() and durations<Duration>() draw std::chrono::system_clock time points and std::chrono durations.

Each value type compares, orders and hashes, and to_string() and operator<< give the text the engine defines for it, in the form of RFC 9557: 2024-03-10T01:30:00-05:00[America/New_York], with [gap] or [fold=0]/[fold=1] appended to a skipped or repeated wall time (2024-03-10T02:30:00-04:00[America/New_York][gap]), -00:00 for an unknown offset and Z[Etc/Unknown] for the unknown zone. A failure report shows a drawn value as its type and that text, such as hegel::generators::temporal::Date{"2024-03-10"}.

The functions resolve(), offset_at() and info() query the default zone source directly, outside any test: the engine's bundled IANA database unless set_default_zone_source() set another. A ZoneSource answers the same queries for its own data, and tzdb_version() names the bundled release.

Every zone draw resolves wall times against a zone source. C++ has no time zone database that every toolchain ships, so the default is the engine's bundled one. To draw against the database the code under test uses, build a ZoneSource from it (hegel/extras/boost_date_time.h does this for Boost.DateTime, and hegel/extras/chrono_tzdb.h for a standard library with std::chrono::tzdb) and pass it to zones() and zoned_datetimes(), or make it the default with set_default_zone_source(). A generator reads the default when it is built, and a query when it is called.

Typedef Documentation

◆ ZoneLoader

Initial value:
std::function<void(ZoneSource& source, const std::string& name)>
A source of time zone data: the database the zone and zoned datetime generators classify,...
Definition zone_source.h:290

Supplies a zone source's data for a name the first time a draw or a query needs it.

It adds that name's zone (or a link) to source with the ZoneSource::add_* functions, or adds nothing when it does not know the name. It is called from whichever thread draws or queries, so it must be safe to call from any thread, possibly concurrently and more than once for one name. It must not draw. An exception it throws fails the draw or query with std::invalid_argument carrying its message.

The source keeps the loader, and what it captures, until ZoneSource::set_loader() replaces it or the last generator and the last ZoneSource that use the source are gone; a source that is still the default when the process exits keeps it. Use the source argument rather than a captured copy of the source: a copy would keep the source alive for as long as the loader is set.

Enumeration Type Documentation

◆ AfterProbe

What an oracle's zone has in force after the last year it was probed over; see ZoneOracle.

Enumerator
Hold 

The last type, for ever. Right for a library that itself holds the last offset after its table ends.

Infer 

A yearly rule inferred from the last two probed years, as for InferRule. Closer for a library that applies the current rule for ever.

◆ Ambiguous

Which instant a zoned datetime draw means by a wall time the clocks repeated.

Enumerator
Both 

Either, decided by a drawn fold that shrinks to the earlier.

Earlier 

The earlier instant, with no fold drawn.

Later 

The later instant, with no fold drawn.

◆ Granularity

The values a UTC offset draw restricts itself to.

Enumerator
Hours 

Whole hours.

QuarterHours 

Whole quarter hours.

Minutes 

Whole minutes.

Seconds 

Whole seconds.

◆ Month

A month of the year, for restricting a date draw.

Enumerator
January 

January.

February 

February.

March 

March.

April 

April.

May 

May.

June 

June.

July 

July.

August 

August.

September 

September.

October 

October.

November 

November.

December 

December.

◆ Precision

The unit the time part of a drawn value is counted in: the drawn value is a whole number of these units and shrinks in them.

Enumerator
Nanoseconds 

Whole nanoseconds.

Microseconds 

Whole microseconds.

Milliseconds 

Whole milliseconds.

Seconds 

Whole seconds.

Minutes 

Whole minutes.

Hours 

Whole hours.

◆ SpanSign

How the signs of a span's units are drawn.

Enumerator
Uniform 

One sign for every unit.

Mixed 

Each unit signed on its own.

NonNegative 

Magnitudes only; every enabled unit's lower bound must be at least 0.

◆ SpanUnit

A unit of a Span, largest first.

Enumerator
Years 

Calendar years.

Months 

Calendar months.

Weeks 

Weeks.

Days 

Days.

Hours 

Hours.

Minutes 

Minutes.

Seconds 

Seconds.

Milliseconds 

Milliseconds.

Microseconds 

Microseconds.

Nanoseconds 

Nanoseconds.

◆ Tag

A feature of a time zone, derived from its offsets and name.

"After 1970" means at any instant from 1970-01-01T00:00:00Z on, the rule in force after the last explicit transition included.

Enumerator
Fixed 

No transition after 1970.

WholeHour 

Every offset after 1970 is a whole number of hours.

Fractional 

Some offset after 1970 is a whole number of minutes but not of hours (+05:30, +05:45, -03:30).

Seconds 

Some offset in the zone's history is not a whole number of minutes (local mean time, Monrovia's -00:44:30 until 1972).

Dst 

The current rule has a DST offset exactly one hour from the standard one.

DstOther 

The current rule has a DST offset of another size (Lord Howe's 30 minutes, Troll's two hours).

Multi 

Some calendar year has more than two offset changes.

BaseChange 

The lowest offset in force during some year after 1970 differs from the previous year's.

Midnight 

A transition after 1970 whose wall time before or after it is midnight.

SpansMidnight 

A transition after 1970 whose wall times before and after it fall on different dates.

WholeDay 

A transition that skips or repeats a whole day (Pacific/Apia 2011).

SameOffset 

A transition after 1970 that changes the abbreviation but not the offset.

Undefined 

The zone uses the -00 undefined-offset abbreviation.

Link 

The name is a link to another zone.

Legacy 

The name is not Area/Location for a current area (EST5EDT, US/Eastern).

InvertedSign 

The name is one of the Etc/GMT+5 family, whose sign is POSIX's: Etc/GMT+5 is five hours behind UTC.

◆ TransitionKind

How a wall-clock time maps to instants in its zone.

Enumerator
Unique 

Exactly one instant.

Gap 

None: the clocks skipped it.

Fold 

Two: the clocks repeated it.

◆ Weekday

A day of the week, for restricting a date draw.

Enumerator
Monday 

Monday.

Tuesday 

Tuesday.

Wednesday 

Wednesday.

Thursday 

Thursday.

Friday 

Friday.

Saturday 

Saturday.

Sunday 

Sunday.

Function Documentation

◆ dates()

Generator< Date > hegel::generators::temporal::dates ( const DatesParams & params = {})

Generate Date values.

By default any date of the engine's range, years ±999,999, on any weekday and in any month; shrinks toward 2000-01-01 or the nearest bound. One draw in twenty on average targets an interesting date in the bounds: a bound, the nearest leap day or year boundary, the Unix epoch, the 32-bit and 64-bit boundaries or the Gregorian cutover.

auto d = tc.draw(gs::temporal::dates(
{.min_value = Date{2024, 1, 1},
.weekdays = {{Weekday::Saturday, Weekday::Sunday}}}));
@ Saturday
Saturday.
Definition temporal_types.h:742
@ Sunday
Sunday.
Definition temporal_types.h:743
A proleptic Gregorian calendar date.
Definition temporal_types.h:205
Parameters
paramsBounds and weekday / month restrictions.
Returns
Generator producing dates.
Exceptions
std::invalid_argumentfor an invalid or inverted bound, an empty weekday or month list, or bounds holding no day the lists allow.

◆ datetimes()

Generator< DateTime > hegel::generators::temporal::datetimes ( DatetimesParams params = {})

Generate DateTime values.

By default any wall-clock time of the engine's range, years ±999,999, at nanosecond precision; shrinks toward 2000-01-01T00:00:00 or the nearest bound.

Parameters
paramsBounds and precision.
Returns
Generator producing naive datetimes.
Exceptions
std::invalid_argumentfor an invalid or inverted bound, or bounds holding no value at the precision.

◆ default_zone_source()

ZoneSource hegel::generators::temporal::default_zone_source ( )

The process-wide default zone source: the one zones(), zoned_datetimes() and the info(), resolve() and offset_at() queries use when given no source.

It is ZoneSource::bundled() until set_default_zone_source() sets another. A generator reads it when it is built, and a query when it is called.

Returns
The default source.

◆ durations()

template<typename Duration = SignedDuration>
Generator< Duration > hegel::generators::temporal::durations ( DurationsParams< Duration > params = {})

Generate SignedDuration values, or std::chrono::duration values when Duration is one.

For SignedDuration, the default: by default any duration of ±int64_t seconds at nanosecond precision; shrinks toward zero. One draw in twenty on average targets a bound or a duration such as one unit, 24 hours or the int32_t seconds limit.

For a std::chrono::duration, the precision follows the duration's period, so durations<std::chrono::seconds>() draws whole seconds, and the default bounds are the widest both the type and the engine (±int64_t seconds) hold; shrinks toward zero. The period must be one of the standard units from nanoseconds to hours; for another period map durations().

auto d = tc.draw(
gs::temporal::durations({.precision = Precision::Seconds}));
auto ms = tc.draw(gs::temporal::durations<std::chrono::milliseconds>(
{.min_value = std::chrono::milliseconds{0}}));
@ Seconds
Whole seconds.
Definition temporal_types.h:722
Template Parameters
DurationSignedDuration (the default) or a std::chrono::duration type.
Parameters
paramsBounds and, for SignedDuration, the precision.
Returns
Generator producing durations.
Exceptions
std::invalid_argumentfor an invalid or inverted bound, a bound the engine does not hold, or bounds holding no value at the precision.

◆ info()

std::optional< ZoneInfo > hegel::generators::temporal::info ( std::string_view name)

What the default zone source knows about name, matched exactly as the source spells it, or std::nullopt for a name it lacks.

UNKNOWN_ZONE is known, with itself as primary name, Tag::Undefined and the highest rank.

Parameters
nameThe zone name to look up.
Returns
The description, or std::nullopt.

◆ instants()

template<typename TimePoint = Instant>
Generator< TimePoint > hegel::generators::temporal::instants ( InstantsParams< TimePoint > params = {})

Generate Instant values, or std::chrono::system_clock time points when TimePoint is one.

For Instant, the default: by default any instant of the engine's range, years ±999,999, at nanosecond precision; shrinks toward 2000-01-01T00:00:00Z or the nearest bound. One draw in twenty on average targets an interesting instant: the Unix epoch, the 32-bit and 64-bit boundaries, a leap second's or a time zone transition's.

For a std::chrono::time_point of std::chrono::system_clock, the same draw at the precision and within the range of the type, so that the type holds every drawn instant exactly. The precision is the finest of the engine's (Precision) that is a whole number of the duration's ticks: std::chrono::milliseconds draws whole milliseconds, and a tick of 100 nanoseconds whole microseconds. The default bounds are the widest both the type and the engine hold: a 64-bit count of nanoseconds gives the years 1678 to 2262, and one of seconds the engine's range. A failure report shows a drawn time point as its type and the text of the instant: std::chrono::sys_time<std::chrono::milliseconds>{"2024-03-10T02:30:00.5Z"}.

The duration must have an integer count of at most 64 bits and a tick that is a whole number of nanoseconds and divides a second, or a whole number of seconds that divides an hour. Any other duration, such as std::chrono::days or one finer than nanoseconds, does not compile: draw std::chrono::hours and convert. Only std::chrono::system_clock is supported, the one clock whose epoch every toolchain fixes at the Unix epoch; convert to another clock with std::chrono::clock_cast where the standard library has it.

auto at = tc.draw(
gs::temporal::instants({.precision = Precision::Seconds}));
using sys_ms = std::chrono::sys_time<std::chrono::milliseconds>;
auto ms = tc.draw(gs::temporal::instants<sys_ms>(
{.min_value = sys_ms{std::chrono::milliseconds{0}}}));
auto now = tc.draw(
gs::temporal::instants<std::chrono::system_clock::time_point>());
Template Parameters
TimePointInstant (the default) or a std::chrono::time_point of std::chrono::system_clock.
Parameters
paramsBounds and, for Instant, the precision.
Returns
Generator producing instants.
Exceptions
std::invalid_argumentfor an invalid or inverted bound, a bound outside the engine's range, or bounds holding no value at the precision.

◆ offset_at()

ZoneOffset hegel::generators::temporal::offset_at ( std::string_view name,
const Instant & instant )

The offset the zone name has in force at instant.

Parameters
nameThe zone name.
instantThe instant to look up.
Returns
The offset in force.
Exceptions
std::invalid_argumentfor a zone the default source lacks or an instant out of range.

◆ offsets()

Generator< UtcOffset > hegel::generators::temporal::offsets ( OffsetsParams params = {})

Generate UtcOffset values.

By default any known offset within ±25:59:59 at second granularity; shrinks toward +00:00. One draw in twenty on average targets an offset some time zone has used, so +05:45 and -00:44:30 appear.

Parameters
paramsBounds, granularity and the unknown switch.
Returns
Generator producing UTC offsets.
Exceptions
std::invalid_argumentfor an unknown, out-of-range or inverted bound, or bounds holding no value at the granularity.

◆ operator!=() [1/3]

template<typename T>
detail::if_value< T, bool > hegel::generators::temporal::operator!= ( const T & a,
const T & b )
constexpr

Compares two values of one value type for inequality.

Template Parameters
TA value type of this namespace.
Parameters
aThe left operand.
bThe right operand.
Returns
true when a and b differ.

◆ operator!=() [2/3]

bool hegel::generators::temporal::operator!= ( const ZoneInfo & a,
const ZoneInfo & b )
inline

Compares two zone descriptions for inequality.

Parameters
aThe left operand.
bThe right operand.
Returns
true when a and b differ.

◆ operator!=() [3/3]

bool hegel::generators::temporal::operator!= ( const ZoneOffset & a,
const ZoneOffset & b )
inline

Compares two zone offsets for inequality.

Parameters
aThe left operand.
bThe right operand.
Returns
true when a and b differ.

◆ operator<()

template<typename T>
detail::if_value< T, bool > hegel::generators::temporal::operator< ( const T & a,
const T & b )
constexpr

Compares two values of one value type for ordering.

Template Parameters
TA value type of this namespace.
Parameters
aThe left operand.
bThe right operand.
Returns
true when a is before b.

◆ operator<<()

template<typename T>
detail::if_value< T, std::ostream & > hegel::generators::temporal::operator<< ( std::ostream & os,
const T & value )

Prints a value of a value type as to_string() gives it.

Template Parameters
TA value type of this namespace.
Parameters
osThe stream to print to.
valueThe value to print.
Returns
os.

◆ operator<=()

template<typename T>
detail::if_value< T, bool > hegel::generators::temporal::operator<= ( const T & a,
const T & b )
constexpr

Compares two values of one value type for ordering.

Template Parameters
TA value type of this namespace.
Parameters
aThe left operand.
bThe right operand.
Returns
true when a is not after b.

◆ operator==() [1/3]

template<typename T>
detail::if_value< T, bool > hegel::generators::temporal::operator== ( const T & a,
const T & b )
constexpr

Compares two values of one value type for equality.

Template Parameters
TA value type of this namespace.
Parameters
aThe left operand.
bThe right operand.
Returns
true when a and b are equal.

◆ operator==() [2/3]

bool hegel::generators::temporal::operator== ( const ZoneInfo & a,
const ZoneInfo & b )
inline

Compares two zone descriptions for equality.

Parameters
aThe left operand.
bThe right operand.
Returns
true when a and b are equal.

◆ operator==() [3/3]

bool hegel::generators::temporal::operator== ( const ZoneOffset & a,
const ZoneOffset & b )
inline

Compares two zone offsets for equality.

Parameters
aThe left operand.
bThe right operand.
Returns
true when a and b are equal.

◆ operator>()

template<typename T>
detail::if_value< T, bool > hegel::generators::temporal::operator> ( const T & a,
const T & b )
constexpr

Compares two values of one value type for ordering.

Template Parameters
TA value type of this namespace.
Parameters
aThe left operand.
bThe right operand.
Returns
true when a is after b.

◆ operator>=()

template<typename T>
detail::if_value< T, bool > hegel::generators::temporal::operator>= ( const T & a,
const T & b )
constexpr

Compares two values of one value type for ordering.

Template Parameters
TA value type of this namespace.
Parameters
aThe left operand.
bThe right operand.
Returns
true when a is not before b.

◆ resolve()

ZonedDateTime hegel::generators::temporal::resolve ( std::string_view name,
const DateTime & civil )

Classify the wall-clock time civil in the zone name and resolve it to an instant, meaning the earlier instant of a repeated wall time (fold false); the later is the wall time read with offset_after.

Parameters
nameThe zone name.
civilThe wall-clock time to resolve.
Returns
The resolved zoned datetime.
Exceptions
std::invalid_argumentfor a zone the default source lacks, a civil out of range, or one whose instant in the zone lies outside the range of Instant, which a wall time within an offset's width of the civil range's ends can do.

◆ set_default_zone_source()

ZoneSource hegel::generators::temporal::set_default_zone_source ( const ZoneSource & source)

Replace the process-wide default zone source.

A generator reads the default when it is built, so generators built before the call keep the source they read. Set it once, before any test builds a generator; to set it for a time, restore the source this returns:

// ...
ZoneSource set_default_zone_source(const ZoneSource &source)
Replace the process-wide default zone source.
Parameters
sourceThe new default; ZoneSource::bundled() restores the engine's database.
Returns
The default source before the call.

◆ spans()

Generator< Span > hegel::generators::temporal::spans ( SpansParams params = {})

Generate Span values.

By default every unit from years to nanoseconds within ±INT64_MAX (or [0, INT64_MAX] under SpanSign::NonNegative), all of one drawn sign; shrinks toward the zero span.

auto s = tc.draw(
gs::temporal::spans({.days = {{0, 30}}, .hours = {{0, 23}}}));
Parameters
paramsPer-unit bounds and the sign policy.
Returns
Generator producing calendar spans.
Exceptions
std::invalid_argumentfor inverted bounds or bounds the sign policy does not admit.

◆ times()

Generator< Time > hegel::generators::temporal::times ( TimesParams params = {})

Generate Time values.

By default any time of day at nanosecond precision; shrinks toward midnight or the lower bound.

Parameters
paramsBounds and precision.
Returns
Generator producing times of day.
Exceptions
std::invalid_argumentfor an invalid or inverted bound, or bounds holding no value at the precision.

◆ to_string() [1/9]

std::string hegel::generators::temporal::to_string ( const Date & date)

The text of a date: 2024-03-10 or, outside years 0000 to 9999, +010000-01-01.

Parameters
dateThe value to print.
Returns
The text.

◆ to_string() [2/9]

std::string hegel::generators::temporal::to_string ( const DateTime & datetime)

The text of a datetime: 2024-03-10T02:30:00.

Parameters
datetimeThe value to print.
Returns
The text.

◆ to_string() [3/9]

std::string hegel::generators::temporal::to_string ( const Instant & instant)

The text of an instant: 2000-01-01T00:00:00Z.

Parameters
instantThe value to print.
Returns
The text.

◆ to_string() [4/9]

std::string hegel::generators::temporal::to_string ( const SignedDuration & duration)

The text of a duration: PT1H30M5.5S, -PT1.5S or PT0S.

Parameters
durationThe value to print.
Returns
The text.

◆ to_string() [5/9]

std::string hegel::generators::temporal::to_string ( const Span & span)

The text of a span: 1y 2mo 3d, -1y 2mo, +1y -2mo or 0s.

Parameters
spanThe value to print.
Returns
The text.

◆ to_string() [6/9]

std::string hegel::generators::temporal::to_string ( const Time & time)

The text of a time of day: 02:30:00 or 02:30:00.5.

Parameters
timeThe value to print.
Returns
The text.

◆ to_string() [7/9]

std::string hegel::generators::temporal::to_string ( const TimeZone & zone)

The text of a time zone: its name.

Parameters
zoneThe value to print.
Returns
The text.

◆ to_string() [8/9]

std::string hegel::generators::temporal::to_string ( const UtcOffset & offset)

The text of an offset: +05:30, -00:44:30 or -00:00.

Parameters
offsetThe value to print.
Returns
The text.

◆ to_string() [9/9]

std::string hegel::generators::temporal::to_string ( const ZonedDateTime & zoned)

The text of a zoned datetime: 2024-03-10T02:30:00-04:00[America/New_York][gap].

Parameters
zonedThe value to print.
Returns
The text.
Exceptions
std::invalid_argumentfor a zone name that is not UTF-8.

◆ tzdb_version()

std::string hegel::generators::temporal::tzdb_version ( )

The IANA release of the time zone database bundled in the engine, such as "2026e".

A test that resolves zones with its own database can compare the two and warn when they differ: the engine decides what to generate, the other database what the value means.

Returns
The release name.

◆ zoned_datetimes()

Generator< ZonedDateTime > hegel::generators::temporal::zoned_datetimes ( const ZonedDatetimesParams & params = {})

Generate ZonedDateTime values: a zone, a wall-clock time in it and, when the clocks repeated that time, which repeat is meant.

By default any zone zones() draws and any wall-clock time of the engine's range at nanosecond precision, with skipped wall times reported as TransitionKind::Gap and both repeats of a fold drawn; shrinks down the zone ladder, then toward 2000-01-01T00:00, preferring a unique wall time to a repeated one. One draw in twenty on average targets a transition of the zone, which is how gaps, folds and the exact boundary instants are reached. Build a native value from civil, the zone name and fold (or, for a gap, from instant), never from the offsets, so that a newer database on your side changes what a value means but never makes it invalid.

auto z = tc.draw(gs::temporal::zoned_datetimes(
{.zones = gs::temporal::zones({.names = {{"America/New_York"}}}),
.precision = Precision::Seconds,
.allow_imaginary = false}));

Any generator of zones works, such as one of your own zones. Its names are resolved against source, or against the default zone source when there is none, and a name that source does not know makes the draw throw std::invalid_argument:

auto local = tc.draw(gs::temporal::zoned_datetimes(
{.zones = gs::just(TimeZone{"Europe/Paris", "Europe/Paris"})}));
auto mine = tc.draw(gs::temporal::zoned_datetimes(
{.zones = gs::temporal::zones({.source = my_source})
.filter([](const TimeZone& zone) {
return zone.name != "Etc/Skipped";
}),
.source = my_source}));
A time zone of a zone source, or UNKNOWN_ZONE.
Definition temporal_types.h:375

To draw every zone of a ZoneSource, pass it alone:

auto theirs =
tc.draw(gs::temporal::zoned_datetimes({.source = my_source}));
Parameters
paramsZones, their source, bounds and the gap and fold policies.
Returns
Generator producing zoned datetimes.
Exceptions
std::invalid_argumentfor both wall-clock and instant bounds, an invalid or inverted bound, bounds holding no value at the precision, or a source next to a zones generator that zones() returned.

◆ zones()

Generator< TimeZone > hegel::generators::temporal::zones ( const ZonesParams & params = {})

Generate TimeZone values.

By default any name of the default zone source (the engine's bundled IANA database unless set_default_zone_source() set another), link names in and legacy names out; shrinks down a ladder of names to UTC when it is allowed, otherwise to the lowest-ranked allowed name. Half the draws are uniform over the allowed names and half weighted by the zones' features, so a zone with a rare feature (a fractional offset, a skipped day, negative DST) is drawn at a rate a short run reaches.

auto zone = tc.draw(gs::temporal::zones(
{.names = {{"Europe/London", "Asia/Calcutta"}}}));

With a ZoneSource, the names come from it, and zoned_datetimes() over this generator resolves wall times against its data:

auto zone = tc.draw(gs::temporal::zones({.source = my_source}));
Parameters
paramsThe allowed names and their source.
Returns
Generator producing time zones.
Exceptions
std::invalid_argumentfor an empty list, a name the source does not know and allow_opaque does not admit, or a source with no name the allow_links and allow_legacy flags allow.

Variable Documentation

◆ ALL_SPAN_UNITS

std::array<SpanUnit, 10> hegel::generators::temporal::ALL_SPAN_UNITS
inlineconstexpr
Initial value:
= {
}
@ Milliseconds
Milliseconds.
Definition temporal_types.h:467
@ Microseconds
Microseconds.
Definition temporal_types.h:468
@ Hours
Hours.
Definition temporal_types.h:464
@ Seconds
Seconds.
Definition temporal_types.h:466
@ Weeks
Weeks.
Definition temporal_types.h:462
@ Years
Calendar years.
Definition temporal_types.h:460
@ Days
Days.
Definition temporal_types.h:463
@ Months
Calendar months.
Definition temporal_types.h:461
@ Minutes
Minutes.
Definition temporal_types.h:465
@ Nanoseconds
Nanoseconds.
Definition temporal_types.h:469

Every SpanUnit, largest first.

◆ ALL_TAGS

std::array<Tag, 16> hegel::generators::temporal::ALL_TAGS
inlineconstexpr
Initial value:
= {
}
@ Legacy
Definition temporal_types.h:811
@ InvertedSign
Definition temporal_types.h:813
@ Dst
Definition temporal_types.h:793
@ Fixed
No transition after 1970.
Definition temporal_types.h:786
@ SameOffset
Definition temporal_types.h:806
@ DstOther
Definition temporal_types.h:795
@ Fractional
Definition temporal_types.h:788
@ Seconds
Definition temporal_types.h:790
@ WholeDay
Definition temporal_types.h:804
@ Link
The name is a link to another zone.
Definition temporal_types.h:810
@ BaseChange
Definition temporal_types.h:798
@ Midnight
Definition temporal_types.h:800
@ Multi
Some calendar year has more than two offset changes.
Definition temporal_types.h:797
@ Undefined
Definition temporal_types.h:808
@ SpansMidnight
Definition temporal_types.h:802
@ WholeHour
Every offset after 1970 is a whole number of hours.
Definition temporal_types.h:787

Every Tag, in the order of the engine's bit set.

◆ UNKNOWN_ZONE

std::string_view hegel::generators::temporal::UNKNOWN_ZONE = "Etc/Unknown"
inlineconstexpr

The name of the unknown time zone, whose instants are known and whose offset is not.