Date and Time

Date and Time Types

Introduction

The time namespace provides types for working with civil dates, wall-clock times, and time spans. The calendar helper structs are small aggregate result types for APIs that return more than one calendar component. They keep call sites readable by naming the returned values.

const auto parts = date.parts();
const auto year = parts.year;
const auto month = parts.month;
const auto day = parts.day;

const auto next = el::Month::december().next(el::Year{2026});
const auto nextMonth = next.month;

Date

Date stores a civil date in the proleptic Gregorian calendar. The internal epoch is 0000-01-01 and raw day zero is that date. The supported range is 0000-01-01 through 9999-12-31. Use parts() when you need named DateParts instead of separate accessor calls.

Date arithmetic saturates at the supported range. For example, adding a negative day count to the first supported date keeps the result at 0000-01-01. Use wouldAddSaturate() to test for this condition and addedOrThrow() or addOrThrow() to reject it with OverflowError.

Date Time

DateTime represents an instant as UTC date and time plus display offset information. It converts to and from ISO text, std::time_t, exact typed ticks from the Core, POSIX, Windows, and RFC 868 epochs, fixed offsets, and supported named time zones. Tick conversion accepts nanoseconds, microseconds, milliseconds, or seconds; a conversion fails when it would lose fractional precision, precedes the selected epoch, or exceeds the selected unit’s range. Use the split seconds-and-nanoseconds conversion for external formats that need their own fractional representation, such as Windows FILETIME. The value is stored internally as a UTC instant; local accessors and parts() use the display offset or named time zone.

Date-time arithmetic is performed on the UTC instant and saturates at DateTime::first() or DateTime::last() when the result would leave the supported range. Use wouldAddSaturate() or wouldSubtractSaturate() to test for this condition, and use the ...OrThrow() variants to reject it with OverflowError.

A TimeWithZone combines a wall-clock Time with a TimeZone. It does not represent an instant until it is combined with a date. Named zones therefore render using their IANA name instead of inventing a numeric offset. Constructing a DateTime from a date and TimeWithZone resolves the exact offset for the civil date and time, converts the value to internally stored UTC, and retains the display zone.

Time

Time stores a wall-clock time of day with nanosecond precision. Arithmetic that crosses midnight returns the day wrap separately.

Use TimeParts and TimeWrapResult as named aggregate results:

const auto parts = time.parts();
const auto hour = parts.hour;

const auto wrapped = time.addedWithWrap(el::Duration{el::Hours{3}});
const auto dayCarry = wrapped.days;
const auto newTime = wrapped.time;

Time Zone

TimeZone represents UTC, a fixed offset, or a supported named IANA zone. Lookup factories return std::optional for tolerant lookup and OrThrow variants for explicit failure. Fixed offsets are normalized only by complete 24-hour rotations, so offsets such as UTC+13 and UTC+14 retain their direction.

TimeZone::local() identifies and caches the operating system’s base time zone for the process lifetime. POSIX systems use TZ and canonical zoneinfo paths; Windows names are mapped to IANA names using generated Unicode CLDR data. Resolution failures produce UTC with the local-origin marker set. Combining the zone with a civil date and time always resolves the bundled database again, retaining historical shifts, daylight-saving state, abbreviations, gaps, and folds.

The local-origin marker records that the current display zone came from the system setting. Copies, arithmetic, and UTC normalization preserve it. Explicit zone conversion replaces it with the target zone’s marker: conversion to UTC or an explicit zone clears it, while conversion to TimeZone::local() sets it. Default string formatting omits the zone for local-origin values. DateTime::toIsoString() with IsoTimeFormat::TimeShift still forces the resolved numeric offset.

Duration and Time Amounts

Introduction

Duration and time span types store signed time intervals at different resolutions.

Duration stores a signed span with second resolution. Conversions to coarser parts truncate toward zero. Conversions to nanosecond precision, such as toTimeDelta(), saturate if the represented nanoseconds exceed the target type. Use wouldConvertToTimeDeltaSaturate() or toTimeDeltaOrThrow() when saturation must be detected or rejected.

TimeDelta stores a signed span with nanosecond resolution. Conversion to Duration truncates sub-second nanoseconds toward zero. toSecondsWithFractions() and toDaysWithFractions() return approximate floating-point values and do not treat rounding as an error. The unit factories from nanoseconds() through weeks() saturate when conversion exceeds the stored nanosecond range. Use the corresponding ...OrThrow() factory, including weeksOrThrow(), when overflow must be rejected.

CalendarDelta stores nanoseconds through years as independent signed components. It deliberately does not normalize its stored parts: one month remains one month, and mixed positive and negative components remain visible through the typed accessors. Conversion to TimeDelta is available only when the month and year components are zero and the exact fixed-unit sum fits the nanosecond range.

Applying a CalendarDelta to a DateTime processes nanoseconds, microseconds, milliseconds, seconds, minutes, hours, days, weeks, months, and years in that order. Month and year steps use the same end-of-month clamping semantics as Date. Arithmetic is performed on the UTC representation; fixed display offsets are retained and named-zone metadata is refreshed for the final instant.

TimeDeltaFormat controls short or long names, separators, the smallest fixed unit, and fractional output. TimeDeltaFormat::elcl() selects the aliases and separators required for ELCL serialization. Calendar-delta formatting always emits non-zero years and months independently and uses exact signed normalization for the fixed units without first forcing the total into TimeDelta.

Interface

class CalendarDelta

A non-normalized delta composed from independent fixed and calendar amounts.

See: Date and Time

Public Types

using Parts = CalendarDeltaParts

Alias for all independently stored delta parts.

Public Functions

inline explicit CalendarDelta(const Parts &parts) noexcept

Create a calendar delta from all parts.

template<typename tAmount>
inline CalendarDelta(tAmount amount) noexcept

Create a calendar delta containing one amount.

CalendarDelta operator+(CalendarDelta other) const noexcept

Add other to this delta.

CalendarDelta &operator+=(CalendarDelta other) noexcept

Add other to this delta in place.

CalendarDelta operator-(CalendarDelta other) const noexcept

Subtract other from this delta.

CalendarDelta &operator-=(CalendarDelta other) noexcept

Subtract other from this delta in place.

CalendarDelta operator-() const noexcept

Negate every part of this delta.

bool isZero() const noexcept

Test whether every part is zero.

bool isValidTimeDelta() const noexcept

Test whether this delta contains no calendar-dependent units.

inline constexpr Parts parts() const noexcept

Access all independently stored parts.

inline constexpr Nanoseconds nanoseconds() const noexcept

Access the nanosecond part.

CalendarDelta &setNanoseconds(Nanoseconds value) noexcept

Set the nanosecond part.

inline constexpr Microseconds microseconds() const noexcept

Access the microsecond part.

CalendarDelta &setMicroseconds(Microseconds value) noexcept

Set the microsecond part.

inline constexpr Milliseconds milliseconds() const noexcept

Access the millisecond part.

CalendarDelta &setMilliseconds(Milliseconds value) noexcept

Set the millisecond part.

inline constexpr Seconds seconds() const noexcept

Access the second part.

CalendarDelta &setSeconds(Seconds value) noexcept

Set the second part.

inline constexpr Minutes minutes() const noexcept

Access the minute part.

CalendarDelta &setMinutes(Minutes value) noexcept

Set the minute part.

inline constexpr Hours hours() const noexcept

Access the hour part.

CalendarDelta &setHours(Hours value) noexcept

Set the hour part.

inline constexpr Days days() const noexcept

Access the day part.

CalendarDelta &setDays(Days value) noexcept

Set the day part.

inline constexpr Weeks weeks() const noexcept

Access the week part.

CalendarDelta &setWeeks(Weeks value) noexcept

Set the week part.

inline constexpr Months months() const noexcept

Access the month part.

CalendarDelta &setMonths(Months value) noexcept

Set the month part.

inline constexpr Years years() const noexcept

Access the year part.

CalendarDelta &setYears(Years value) noexcept

Set the year part.

std::optional<TimeDelta> toTimeDelta() const noexcept

Convert to a fixed TimeDelta if all parts can be represented exactly.

TimeDelta toTimeDeltaOrThrow() const

Convert to a fixed TimeDelta.

Throws:

err::OverflowError – if calendar units are present or the fixed sum exceeds TimeDelta bounds.

text::String toString(const TimeDeltaFormat &format = {}) const

Convert this value to text.

struct CalendarDeltaParts

Store all independently configurable calendar-delta parts.

Public Members

Nanoseconds nanoseconds

The nanosecond part.

Microseconds microseconds

The microsecond part.

Milliseconds milliseconds

The millisecond part.

Seconds seconds

The second part.

Minutes minutes

The minute part.

Hours hours

The hour part.

Days days

The day part.

Weeks weeks

The week part.

Months months

The month part.

Years years

The year part.

struct YearDayOfYearParts

A year and a zero-based day-of-year amount.

Used by calendar extraction helpers that split an epoch day count into the containing year and the remaining day offset within that year.

Public Members

Year year

The extracted year.

Days dayOfYear

The zero-based day offset within year.

struct YearMonthParts

A year and month pair.

Used by month navigation helpers that may cross a year boundary.

Public Members

Year year

The year of the month.

Month month

The month in year.

struct MonthDayParts

A month and day pair.

Used by calendar extraction helpers that resolve a day-of-year value into month and day components.

Public Members

Month month

The extracted month.

Day day

The day within month.

struct DateParts

A calendar date split into named parts.

Public Members

Year year

The year component.

Month month

The month component.

Day day

The day component.

class Date

A date in the proleptic Gregorian calendar using 0000-01-01 as epoch.

Supports years 0-9999. Invalid dates are represented by a special internal value and sort before all valid dates in comparisons.

See: Date and Time

Public Functions

Date() noexcept = default

Create an invalid date.

Date(Year year, Month month, Day day) noexcept

Create a date from parts, or an invalid date if the parts do not exist.

The year, month and day part types clamp their raw construction input first. The resulting combination is then checked as a real calendar date; for example, February 31st becomes an invalid date.

Parameters:
  • year – The year.

  • month – The month.

  • day – The day.

Date(Day day, Month month, Year year) noexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Date(Year year, Day day, Month month) noexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

std::strong_ordering operator<=>(const Date &other) const noexcept = default

Compare dates. Invalid dates sort before valid dates.

inline constexpr bool isValid() const noexcept

Test if this date is valid.

Returns:

true if the date represents a real calendar date.

bool isFirst() const noexcept

Test if this is the first valid date (epoch).

Returns:

true if this is 0000-01-01.

bool isLast() const noexcept

Test if this is the last valid date (9999-12-31).

Returns:

true if this is the maximum supported date.

bool wouldAddSaturate(Days days) const

Test if adding the given number of days would saturate the date to the first/last valid date.

The method only returns true if the date is clamped to the first or last valid date, not if it ends naturally on the first or last day of the year. Returns false for invalid dates.

Parameters:

days – The number of days to add.

Returns:

true if the date would saturate to the first or last valid date.

bool wouldAddSaturate(Months months) const

Test if adding months would saturate the date to the first/last valid date.

Returns false for invalid dates.

Parameters:

months – The number of months to add.

Returns:

true if the date would saturate to the first or last valid date.

bool wouldAddSaturate(Years years) const

Test if adding years would saturate the date to the first/last valid date.

Returns false for invalid dates.

Parameters:

years – The number of years to add.

Returns:

true if the date would saturate to the first or last valid date.

Year year() const noexcept

Get the year, or zero for invalid dates.

Returns:

The year component.

Month month() const noexcept

Get the month, or January for invalid dates.

Returns:

The month component.

Day day() const noexcept

Get the day, or one for invalid dates.

Returns:

The day component.

DayOfYear dayOfYear() const noexcept

Get the one-based day of year.

Returns:

The day of year (1-366).

DayOfWeek dayOfWeek() const noexcept

Get the day of week.

Returns:

The day of week (Monday - Sunday).

DateParts parts() const noexcept

Get all date parts.

For invalid dates, returns 0000-01-01, matching the individual accessors.

Returns:

Named year, month, and day parts.

Date added(Days amount) const noexcept

Return this date plus amount days, clamped to valid bounds.

Invalid dates stay invalid.

Parameters:

amount – The number of days to add.

Returns:

The resulting date.

Date addedOrThrow(Days amount) const

Return this date plus amount days.

Invalid dates stay invalid.

Parameters:

amount – The number of days to add.

Throws:

err::OverflowError – if the result would be outside the supported date range.

Returns:

The resulting date.

Date added(Months amount) const noexcept

Return this date plus amount months, clamped to valid bounds.

Invalid dates stay invalid. A day is clamped to the largest possible day of the resulting month.

Parameters:

amount – The number of months to add.

Returns:

The resulting date.

Date addedOrThrow(Months amount) const

Return this date plus amount months.

Invalid dates stay invalid. A day is clamped to the largest possible day of the resulting month.

Parameters:

amount – The number of months to add.

Throws:

err::OverflowError – if the result would be outside the supported date range.

Returns:

The resulting date.

Date added(Years amount) const noexcept

Return this date plus amount years, clamped to valid bounds.

Invalid dates stay invalid.

Parameters:

amount – The number of years to add.

Returns:

The resulting date.

Date addedOrThrow(Years amount) const

Return this date plus amount years.

Invalid dates stay invalid.

Parameters:

amount – The number of years to add.

Throws:

err::OverflowError – if the result would be outside the supported date range.

Returns:

The resulting date.

void add(Days amount) noexcept

Add days in place.

Parameters:

amount – The number of days to add.

void addOrThrow(Days amount)

Add days in place.

Parameters:

amount – The number of days to add.

Throws:

err::OverflowError – if the result would be outside the supported date range.

void add(Months amount) noexcept

Add months in place.

A day is clamped to the largest possible day of the resulting month.

Parameters:

amount – The number of months to add.

void addOrThrow(Months amount)

Add months in place.

A day is clamped to the largest possible day of the resulting month.

Parameters:

amount – The number of months to add.

Throws:

err::OverflowError – if the result would be outside the supported date range.

void add(Years amount) noexcept

Add years in place.

Parameters:

amount – The number of years to add.

void addOrThrow(Years amount)

Add years in place.

Parameters:

amount – The number of years to add.

Throws:

err::OverflowError – if the result would be outside the supported date range.

Date next() const noexcept

Return the following date, or invalid past the supported range.

Returns:

The next calendar day.

Date previous() const noexcept

Return the previous date, or invalid before the supported range.

Returns:

The previous calendar day.

Date next(DayOfWeek dayOfWeek) const noexcept

Return the next requested day of week, or an invalid date if this date is invalid.

Date previous(DayOfWeek dayOfWeek) const noexcept

Return the previous requested day of week, or an invalid date if this date is invalid.

text::String toString() const

Convert this date to its canonical human-readable representation.

Invalid dates return an empty string.

Returns:

The date formatted as YYYY-MM-DD.

inline Days toDaysSinceEpoch() const noexcept

Convert to days since epoch, or -1 for invalid dates.

Days daysTo(Date other) const noexcept

Calculate the number of days to another date.

Returns zero if either date is invalid.

auto toIsoString(IsoTimeFormatFlags flags = cDefaultDateFormat, DateTimePrecision precision = DateTimePrecision::Day) const -> text::String

Convert this date to an ISO 8601 string.

Invalid dates return an empty string.

Parameters:
  • flags – Formatting flags for the output.

  • precision – The largest precision to include.

Returns:

The ISO-formatted date string.

Public Static Functions

static Date fromYearMonthDay(int year, int month, int day) noexcept

Create a date from raw integer parts.

Parameters:
  • year – The year (0-9999).

  • month – The month (1-12).

  • day – The day (1-31).

Returns:

A valid date if the parts form a real calendar date, otherwise invalid.

static Date fromYearMonthDayOrThrow(int year, int month, int day)

Create a date from raw integer parts or throw.

Parameters:
  • year – The year (0-9999).

  • month – The month (1-12).

  • day – The day (1-31).

Throws:

err::OutOfRangeError – if the parts do not form a valid date.

Returns:

A valid date.

static Date fromParts(Year year, Month month = Month{}, Day day = Day{}) noexcept

Create a date from typed parts.

Parameters:
  • year – The year.

  • month – The month, defaults to January.

  • day – The day, defaults to the first.

Returns:

A valid date if the parts form a real calendar date, otherwise invalid.

static Date fromPartsOrThrow(Year year, Month month = Month{}, Day day = Day{})

Create a date from typed parts or throw.

Parameters:
  • year – The year.

  • month – The month, defaults to January.

  • day – The day, defaults to the first.

Throws:

err::OutOfRangeError – if the parts do not form a valid date.

Returns:

A valid date.

static Date fromDaysSinceEpoch(Days days) noexcept

Create a date from days since epoch.

Parameters:

days – The number of days since epoch.

Returns:

A valid date if within range, otherwise invalid.

static bool exists(Year year, Month month, Day day) noexcept

Test if date parts form an existing date.

Parameters:
  • year – The year.

  • month – The month.

  • day – The day.

Returns:

true if the parts form a valid calendar date.

static Date firstDay(Year year) noexcept

Return first day in a year.

Parameters:

year – The year.

Returns:

January 1st of the given year.

static Date firstDay(Year year, Month month) noexcept

Return first day in a month.

Parameters:
  • year – The year.

  • month – The month.

Returns:

The first day of the given month.

static Date lastDay(Year year) noexcept

Return last day in a year.

Parameters:

year – The year.

Returns:

December 31st of the given year.

static Date lastDay(Year year, Month month) noexcept

Return last day in a month.

Parameters:
  • year – The year.

  • month – The month.

Returns:

The last day of the given month.

static Date epoch() noexcept

Return the epoch date.

Returns:

0000-01-01.

static Date first() noexcept

Return first supported date.

static Date last() noexcept

Return the last supported date (9999-12-31).

Returns:

The maximum date.

class DateTime

A point in time represented as UTC date/time plus display offset information.

See: Date and Time

Public Functions

DateTime() noexcept = default

Create an invalid date/time.

inline DateTime(const Date utcDate, const Time utcTime) noexcept

Create a UTC date/time.

If utcDate is invalid, the resulting date/time is invalid and its time and offset are reset.

Parameters:
  • utcDate – The date.

  • utcTime – The time in the UTC timezone.

DateTime(Date localDate, Time localTime, Seconds offset) noexcept

Create a fixed-offset local date/time.

Invalid local dates result in an invalid date/time. Offsets are normalized into the supported UTC offset range.

Parameters:
  • localDate – The local date.

  • localTime – The local time.

  • offset – The UTC offset.

inline DateTime(const Date localDate, const Time localTime, const Duration offset) noexcept

Create a fixed-offset local date/time.

Parameters:
  • localDate – The local date.

  • localTime – The local time.

  • offset – The UTC offset.

DateTime(Date localDate, TimeWithZone localTime, TimeOccurrenceInFold occurrence = TimeOccurrenceInFold::First) noexcept

Create a local date/time from a time with a time zone.

Invalid local dates result in an invalid date/time.

Parameters:
  • localDate – The local date.

  • localTime – The local time and its time zone.

  • occurrence – Which occurrence to use during fold periods.

DateTime(Date localDate, Time localTime, TimeZone timeZone, TimeOccurrenceInFold occurrence = TimeOccurrenceInFold::First) noexcept

Create a named-zone local date/time.

Invalid local dates result in an invalid date/time. During folds, occurrence selects the first or second possible instant; local times in gaps are resolved using the zone database transition rule.

Parameters:
  • localDate – The local date.

  • localTime – The local time.

  • timeZone – The time zone.

  • occurrence – Which occurrence to use during fold periods.

std::strong_ordering operator<=>(const DateTime &other) const noexcept

Compare two date/time values by their instant and display properties.

inline DateTime operator+(const Duration duration) const noexcept

Return this date/time with a duration added.

inline DateTime &operator+=(const Duration duration) noexcept

Add a duration to this date/time.

inline DateTime operator-(const Duration duration) const noexcept

Return this date/time with a duration subtracted.

inline DateTime &operator-=(const Duration duration) noexcept

Subtract a duration from this date/time.

inline Duration operator-(const DateTime &other) const noexcept

Return the signed duration from other to this date/time.

Parameters:

other – The other date/time.

Returns:

The duration from other to this.

inline DateTime operator+(const CalendarDelta &delta) const noexcept

Return this date/time with a calendar delta added.

inline DateTime &operator+=(const CalendarDelta &delta) noexcept

Add a calendar delta to this date/time.

inline DateTime operator-(const CalendarDelta &delta) const noexcept

Return this date/time with a calendar delta subtracted.

inline DateTime &operator-=(const CalendarDelta &delta) noexcept

Subtract a calendar delta from this date/time.

inline constexpr bool isValid() const noexcept

Test if this date/time represents a valid instant.

inline constexpr bool isUtc() const noexcept

Test if this date/time is displayed in UTC.

inline constexpr bool isLocalTime() const noexcept

Test if the display zone originated from the system-local setting.

inline constexpr Date utcDate() const noexcept

Return the stored UTC date, or an invalid date for invalid date/times.

inline constexpr Time utcTime() const noexcept

Return the stored UTC time, or midnight for invalid date/times.

inline Date date() const noexcept

Return the local display date, or an invalid date for invalid date/times.

inline Time time() const noexcept

Return the local display time, or midnight for invalid date/times.

inline Year year() const noexcept

Return the local year, or zero for invalid date/times.

inline Month month() const noexcept

Return the local month, or January for invalid date/times.

inline Day day() const noexcept

Return the local day, or one for invalid date/times.

inline DayOfYear dayOfYear() const noexcept

Return the local day of year, or one for invalid date/times.

inline DayOfWeek dayOfWeek() const noexcept

Return the local day of week, or the epoch weekday for invalid date/times.

inline Hour hour() const noexcept

Return the local hour.

inline Minute minute() const noexcept

Return the local minute.

inline Second second() const noexcept

Return the local second.

inline Milliseconds millisecondFraction() const noexcept

Return the local millisecond fraction.

inline Nanoseconds nanosecondFraction() const noexcept

Return the local nanosecond fraction.

DateTimeParts parts() const noexcept

Return all local date/time parts.

For invalid date/times, returns the same fallback parts as the individual accessors.

inline Duration timeOffset() const noexcept

Return the display offset from UTC.

TimeZone timeZone() const noexcept

Return the display time zone, or UTC for invalid date/times and fixed offsets.

text::String timeZoneAbbreviation() const

Return the display time-zone abbreviation, or an empty string when none is available.

bool wouldAddSaturate(const CalendarDelta &delta) const noexcept

Test if applying a calendar delta would saturate the supported range.

bool wouldSubtractSaturate(const CalendarDelta &delta) const noexcept

Test if subtracting a calendar delta would saturate the supported range.

DateTime added(const CalendarDelta &delta) const noexcept

Apply a calendar delta in ascending unit order and clamp at supported bounds.

DateTime addedOrThrow(const CalendarDelta &delta) const

Apply a calendar delta in ascending unit order.

Throws:

err::OverflowError – if an intermediate result exceeds supported bounds.

inline void add(const CalendarDelta &delta) noexcept

Apply a calendar delta in place and clamp at supported bounds.

inline void addOrThrow(const CalendarDelta &delta)

Apply a calendar delta in place.

Throws:

err::OverflowError – if an intermediate result exceeds supported bounds.

inline DateTime subtracted(const CalendarDelta &delta) const noexcept

Subtract a calendar delta in ascending unit order and clamp at supported bounds.

inline DateTime subtractedOrThrow(const CalendarDelta &delta) const

Subtract a calendar delta in ascending unit order.

Throws:

err::OverflowError – if an intermediate result exceeds supported bounds.

inline void subtract(const CalendarDelta &delta) noexcept

Subtract a calendar delta in place and clamp at supported bounds.

inline void subtractOrThrow(const CalendarDelta &delta)

Subtract a calendar delta in place.

Throws:

err::OverflowError – if an intermediate result exceeds supported bounds.

bool wouldAddSaturate(Duration duration) const noexcept

Test if adding a duration would saturate to the first or last supported date/time.

Returns false for invalid date/times.

Parameters:

duration – The duration to add.

Returns:

true if the result would be clamped to the supported date/time range.

bool wouldSubtractSaturate(Duration duration) const noexcept

Test if subtracting a duration would saturate to the first or last supported date/time.

Returns false for invalid date/times.

Parameters:

duration – The duration to subtract.

Returns:

true if the result would be clamped to the supported date/time range.

DateTime added(Duration duration) const noexcept

Return this date/time plus a duration, clamped to the supported date/time range.

Invalid date/times stay invalid.

DateTime addedOrThrow(Duration duration) const

Return this date/time plus a duration.

Invalid date/times stay invalid.

Parameters:

duration – The duration to add.

Throws:

err::OverflowError – if the result would exceed the supported date/time range.

Returns:

The resulting date/time.

inline void add(const Duration duration) noexcept

Add a duration in place, clamped to the supported date/time range.

Invalid date/times stay invalid.

inline void addOrThrow(const Duration duration)

Add a duration in place.

Invalid date/times stay invalid.

Parameters:

duration – The duration to add.

Throws:

err::OverflowError – if the result would exceed the supported date/time range.

inline DateTime subtracted(const Duration duration) const noexcept

Return this date/time minus a duration, clamped to the supported date/time range.

Invalid date/times stay invalid.

DateTime subtractedOrThrow(Duration duration) const

Return this date/time minus a duration.

Invalid date/times stay invalid.

Parameters:

duration – The duration to subtract.

Throws:

err::OverflowError – if the result would exceed the supported date/time range.

Returns:

The resulting date/time.

inline void subtract(const Duration duration) noexcept

Subtract a duration in place, clamped to the supported date/time range.

Invalid date/times stay invalid.

inline void subtractOrThrow(const Duration duration)

Subtract a duration in place.

Invalid date/times stay invalid.

Parameters:

duration – The duration to subtract.

Throws:

err::OverflowError – if the result would exceed the supported date/time range.

Duration durationTo(const DateTime &other) const noexcept

Calculate the signed duration from this date/time to other.

Invalid date/times participate as -1 seconds since epoch.

Parameters:

other – The other date/time.

Returns:

The duration from this to other.

TimeDelta timeDeltaTo(const DateTime &other) const noexcept

Calculate the signed nanosecond time delta from this date/time to other.

Invalid date/times participate as -1 seconds since epoch.

text::String toString() const

Convert this date/time to a compact human-readable representation.

Invalid date/times return an empty string.

Returns:

The displayed date/time followed by its resolved offset.

DateTime toUtc() const noexcept

Convert to UTC, or return an invalid date/time if this date/time is invalid.

DateTime toTimeZone(TimeZone timeZone) const noexcept

Convert the display time zone, or return an invalid date/time if this date/time is invalid.

std::time_t toTimeT() const noexcept

Convert to std::time_t using the POSIX epoch.

Fractions of seconds are discarded. Invalid date/times convert from the internal -1 seconds sentinel.

std::optional<std::pair<Seconds, Nanoseconds>> toSecondsAndFractions(TimeEpoch epoch = TimeEpoch::Core) const noexcept

Convert to complete seconds and a nanosecond fraction from an epoch.

This is the only method that returns the full precision of a date/time value.

Parameters:

epoch – The epoch.

Returns:

The non-negative seconds and fraction, or no value if this date/time precedes the epoch or is invalid.

std::pair<Seconds, Nanoseconds> toSecondsAndFractionsOrThrow(TimeEpoch epoch = TimeEpoch::Core) const

Convert to complete seconds and a nanosecond fraction from an epoch.

This is the only method that returns the full precision of a date/time value.

Parameters:

epoch – The epoch.

Throws:

err::OutOfRangeError – If this date/time precedes the epoch or is invalid.

Returns:

The non-negative seconds and fraction.

template<typename tUnit>
std::optional<tUnit> toTicks(TimeEpoch epoch = TimeEpoch::Core) const noexcept

Convert to exact ticks in seconds, milliseconds, microseconds or nanoseconds from an epoch.

Fractions outside the precision of the tick unit are discarded.

Template Parameters:

tUnit – The tick unit: Nanoseconds, Microseconds, Milliseconds, or Seconds.

Parameters:

epoch – The epoch.

Returns:

Exact non-negative ticks, or no value if they cannot represent this date/time.

inline std::optional<Seconds> toSeconds(const TimeEpoch epoch = TimeEpoch::Core) const noexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

inline std::optional<Nanoseconds> toNanoseconds(const TimeEpoch epoch = TimeEpoch::Core) const noexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<typename tUnit>
tUnit toTicksOrThrow(TimeEpoch epoch = TimeEpoch::Core) const

Convert to exact ticks in seconds, milliseconds, microseconds or nanoseconds from an epoch.

Fractions outside the precision of the tick unit are discarded.

Template Parameters:

tUnit – The tick unit: Nanoseconds, Microseconds, Milliseconds, or Seconds.

Parameters:

epoch – The epoch.

Throws:

err::OutOfRangeError – If the ticks cannot represent this date/time.

Returns:

Exact non-negative ticks.

inline Seconds toSecondsOrThrow(const TimeEpoch epoch = TimeEpoch::Core) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

inline Nanoseconds toNanosecondsOrThrow(const TimeEpoch epoch = TimeEpoch::Core) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

auto toIsoString(IsoTimeFormatFlags flags = cDefaultDateTimeFormat, DateTimePrecision precision = DateTimePrecision::Second) const -> text::String

Convert this date/time to an ISO 8601 string.

Invalid date/times return an empty string.

Parameters:
  • flags – Formatting flags for date, time, and offset output.

  • precision – The largest precision to include in the text.

Returns:

The ISO-formatted string.

Public Static Functions

static DateTime now() noexcept

Return the current UTC date/time with nanosecond precision when supported by the platform clock.

static DateTime fromTimeT(std::time_t posixTime) noexcept

Create a UTC date/time from a POSIX time value.

Returns an invalid date/time if the value is outside the supported date/time range.

template<typename tUnit>
static std::optional<DateTime> fromTicks(tUnit ticks, TimeEpoch epoch = TimeEpoch::Core) noexcept

Create a UTC date/time from exact ticks in seconds, milliseconds, microseconds or nanoseconds since an epoch.

Fractions outside the precision of the tick unit are discarded.

Template Parameters:

tUnit – The tick unit: Nanoseconds, Microseconds, Milliseconds, or Seconds.

Parameters:
  • ticks – The non-negative ticks.

  • epoch – The epoch.

Returns:

A date/time, or no value if the ticks cannot be represented.

static inline std::optional<DateTime> fromSeconds(const Seconds ticks, const TimeEpoch epoch = TimeEpoch::Core) noexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

static inline std::optional<DateTime> fromNanoseconds(const Nanoseconds ticks, const TimeEpoch epoch = TimeEpoch::Core) noexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<typename tUnit>
static DateTime fromTicksOrThrow(tUnit ticks, TimeEpoch epoch = TimeEpoch::Core)

Create a UTC date/time from exact ticks in seconds, milliseconds, microseconds or nanoseconds since an epoch.

Fractions outside the precision of the tick unit are discarded.

Template Parameters:

tUnit – The tick unit: Nanoseconds, Microseconds, Milliseconds, or Seconds.

Parameters:
  • ticks – The non-negative ticks.

  • epoch – The epoch.

Throws:

err::OutOfRangeError – If the ticks cannot be represented.

Returns:

A date/time.

static inline DateTime fromSecondsOrThrow(const Seconds ticks, const TimeEpoch epoch = TimeEpoch::Core)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

static inline DateTime fromNanosecondsOrThrow(const Nanoseconds ticks, const TimeEpoch epoch = TimeEpoch::Core)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

static auto fromTicks(Seconds seconds, Nanoseconds fractions, TimeEpoch epoch = TimeEpoch::Core) noexcept -> std::optional<DateTime>

Create a UTC date/time from complete seconds and a nanosecond fraction since an epoch.

This is the only method that allows to construct a date/time at it’s full range and precision.

Parameters:
  • seconds – The non-negative complete seconds.

  • fractions – The nanosecond fraction in the range 0 to 999999999.

  • epoch – The epoch.

Returns:

A date/time, or no value if the values cannot be represented.

static auto fromTicksOrThrow(Seconds seconds, Nanoseconds fractions, TimeEpoch epoch = TimeEpoch::Core) -> DateTime

Create a UTC date/time from complete seconds and a nanosecond fraction since an epoch.

This is the only method that allows to construct a date/time at it’s full range and precision.

Parameters:
  • seconds – The non-negative complete seconds.

  • fractions – The nanosecond fraction in the range 0 to 999999999.

  • epoch – The epoch.

Throws:

err::OutOfRangeError – If the values cannot be represented.

Returns:

A date/time.

static auto fromIsoString(const text::String &text, DateTimePrecision requiredPrecision = DateTimePrecision::Second) noexcept -> DateTime

Parse an ISO date/time string.

Parameters:
  • text – The text to parse.

  • requiredPrecision – The minimum precision required.

Returns:

The date-time or an invalid date/time if parsing fails.

static auto fromIsoStringOrThrow(const text::String &text, DateTimePrecision requiredPrecision = DateTimePrecision::Second) -> DateTime

Parse an ISO date/time string or throw on errors.

Parameters:
  • text – The text to parse.

  • requiredPrecision – The minimum precision required.

Throws:

err::ParseError – If parsing fails.

Returns:

A valid date/time.

static auto fromIsoString(const text::String &text, TimeZone timeZone, DateTimePrecision requiredPrecision = DateTimePrecision::Second) noexcept -> DateTime

Parse an ISO local date/time string in the given time zone.

Parameters:
  • text – The text to parse.

  • timeZone – The time zone to interpret the local time.

  • requiredPrecision – The minimum precision required.

Returns:

The date-time or an invalid date/time if parsing fails.

static auto fromIsoStringOrThrow(const text::String &text, TimeZone timeZone, DateTimePrecision requiredPrecision = DateTimePrecision::Second) -> DateTime

Parse an ISO local date/time string in the given time zone or throw on errors.

Parameters:
  • text – The text to parse.

  • timeZone – The time zone to interpret the local time.

  • requiredPrecision – The minimum precision required.

Throws:

err::ParseError – If parsing fails.

Returns:

A valid date/time.

static DateTime epoch(TimeEpoch epoch = TimeEpoch::Core) noexcept

Get an epoch date-time.

Parameters:

epoch – The epoch.

Returns:

The epoch date-time.

static inline DateTime first() noexcept

Get the first possible date-time.

static inline DateTime last() noexcept

Get the last possible date-time.

struct DateTimeParts

A local date/time split into named parts.

Public Members

Year year

The local year component.

Month month

The local month component.

Day day

The local day component.

Hour hour

The local hour component.

Minute minute

The local minute component.

Second second

The local second component.

Nanoseconds nanosecondFraction

The local nanosecond fraction.

enum class erbsland::time::DateTimePrecision : uint8_t

Precision levels for ISO date/time parsing and formatting.

Controls how much detail is required when parsing or how much is emitted when formatting.

Values:

enumerator Year

Year only (e.g. 2025).

enumerator Month

Year and month (e.g. 2025-06).

enumerator Day

Full date (e.g. 2025-06-15).

enumerator Hour

Full date and hour (e.g. 2025-06-15T14).

enumerator Minute

Full date and minute (e.g. 2025-06-15T14:30).

enumerator Second

Full date and second (e.g. 2025-06-15T14:30:45).

enumerator Millisecond

Full date and time with a millisecond fraction (e.g. 2025-06-15T14:30:45.123).

enumerator Microsecond

Full date and time with a microsecond fraction (e.g. 2025-06-15T14:30:45.123456).

enumerator Nanosecond

Full date and time with a nanosecond fraction (e.g. 2025-06-15T14:30:45.123456789).

class Day : public erbsland::time::impl::TimePartWithAmount<Day, Days, int8_t, 1, 31>

A day within a month, range 1..31.

Provides clamped arithmetic and month-aware navigation methods like next() and previous().

Public Functions

bool exists(Year year, Month month) const noexcept

Test if this day exists in the given month.

Parameters:
  • year – The year to check.

  • month – The month to check.

Returns:

true if this day is valid in the given month and year.

bool isLast(Year year, Month month) const noexcept

Test if this is the last day in the given month.

Parameters:
  • year – The year to check.

  • month – The month to check.

Returns:

true if this day equals the last day of the month.

bool hasNext(Year year, Month month) const noexcept

Test if this day has a following date in the supported date range.

Parameters:
  • year – The year to check.

  • month – The month to check.

Returns:

true if advancing this day does not exceed the supported range.

bool hasPrevious(Year year, Month month) const noexcept

Test if this day has a previous date in the supported date range.

Parameters:
  • year – The year to check.

  • month – The month to check.

Returns:

true if retreating this day does not go below the supported range.

Day clamped(Year year, Month month) const noexcept

Return the day, clamped to the valid range of the given year and month.

Parameters:
  • year – The year.

  • month – The month.

Returns:

The clamped day.

DateParts next(Year year, Month month) const noexcept

Return the next calendar day parts, clamped at the valid date range.

If this is the last supported date, the result stays at the same date.

Parameters:
  • year – The current year.

  • month – The current month.

Returns:

The next calendar date parts.

DateParts previous(Year year, Month month) const noexcept

Return the previous calendar day parts, clamped at the valid date range.

If this is the first supported date, the result stays at the same date.

Parameters:
  • year – The current year.

  • month – The current month.

Returns:

The previous calendar date parts.

Public Static Functions

static Day last(Year year, Month month) noexcept

Return the last day for the given month.

Parameters:
  • year – The year to check.

  • month – The month to check.

Returns:

The last valid day of the month (28-31).

static inline Day lastMinimum() noexcept

Return the shortest possible last day of a month.

Returns:

Day{28}, the minimum last day across all months.

static inline Day lastMaximum() noexcept

Return the longest possible last day of a month.

Returns:

Day{31}, the maximum last day across all months.

class DayOfWeek : public erbsland::time::impl::TimePartWithAmount<DayOfWeek, Days, int8_t, 0, 6>

A day of week, Monday (0) through Sunday (6).

Provides clamped arithmetic.

Public Functions

Days daysToNext(DayOfWeek dayOfWeek) const noexcept

Days to the next occurrence, excluding today unless equal.

Parameters:

dayOfWeek – The target day of week.

Returns:

The signed number of days to the next occurrence.

Days daysToPrevious(DayOfWeek dayOfWeek) const noexcept

Days to the previous occurrence, excluding today unless equal.

Parameters:

dayOfWeek – The target day of week.

Returns:

The signed number of days to the previous occurrence.

text::String toString(DayOfWeekFormat format = DayOfWeekFormat::Long) const

Convert this day to a display string.

Parameters:

format – The formatting style (short or long name).

Returns:

A read-only string of the day name.

Public Static Functions

static inline DayOfWeek monday() noexcept

Monday.

static inline DayOfWeek tuesday() noexcept

Tuesday.

static inline DayOfWeek wednesday() noexcept

Wednesday.

static inline DayOfWeek thursday() noexcept

Thursday.

static inline DayOfWeek friday() noexcept

Friday.

static inline DayOfWeek saturday() noexcept

Saturday.

static inline DayOfWeek sunday() noexcept

Sunday.

static inline DayOfWeek atEpoch() noexcept

Epoch day (Saturday)

enum class erbsland::time::DayOfWeekFormat : uint8_t

Formatting style for day-of-week names.

Used by DayOfWeek::toString() to control the output format.

Values:

enumerator Short
enumerator Long
class DayOfYear : public erbsland::time::impl::TimePartWithAmount<DayOfYear, Days, int16_t, 1, 366>

A one-based day of year, range 1..365 (or 1..366 in leap years).

Provides clamped arithmetic.

Public Functions

bool isLast(Year year) const noexcept

Test if this is the last day in year.

Parameters:

year – The year to check against.

Returns:

true if this is the last day of the year.

Public Static Functions

static DayOfYear last(Year year) noexcept

Return the last day of year for year.

Parameters:

year – The year to query.

Returns:

365 for common years, 366 for leap years.

static inline DayOfYear lastMinimum() noexcept

Return the shortest possible last day-of-year (365, for common years).

Returns:

The minimum last day-of-year.

static inline DayOfYear lastMaximum() noexcept

Return the longest possible last day-of-year (366, for leap years).

Returns:

The maximum last day-of-year.

class Duration

A signed duration with a resolution of seconds.

Represents a span of time measured in seconds, with helper methods to split into days, hours, minutes, and seconds components. Arithmetic uses the saturating behavior of the underlying second amount.

Public Functions

Duration() noexcept = default

Create a zero duration.

inline explicit Duration(const Seconds seconds) noexcept

Create a duration from seconds.

Parameters:

seconds – The second value.

template<typename tAmount>
inline explicit Duration(tAmount amount) noexcept

Create a duration from any seconds-based amount.

Template Parameters:

tAmount – The amount type with a SecondsUnitTag.

Parameters:

amount – The amount to convert.

template<typename tRep, typename tPeriod>
inline explicit Duration(std::chrono::duration<tRep, tPeriod> duration) noexcept

Create a duration from a std::chrono::duration, truncating to seconds.

Template Parameters:
  • tRep – The representation type.

  • tPeriod – The period type.

Parameters:

duration – The chrono duration to convert.

explicit Duration(Parts parts) noexcept

Create a duration from split parts.

Parameters:

parts – The parts to combine.

Duration operator+(Duration other) const noexcept

Return the sum of this duration and another duration.

Duration &operator+=(Duration other) noexcept

Add another duration to this duration.

Duration operator-(Duration other) const noexcept

Return the difference between this duration and another duration.

Duration &operator-=(Duration other) noexcept

Subtract another duration from this duration.

Duration operator-() const noexcept

Return this duration with its sign reversed.

inline constexpr bool isZero() const noexcept

Test if this duration is zero.

inline constexpr bool isPositive() const noexcept

Test if the duration is positive.

inline constexpr bool isNegative() const noexcept

Test if the duration is negative.

Seconds seconds() const noexcept

Return the seconds component (0-59).

Returns:

The seconds component within the minute.

Minutes minutes() const noexcept

Return the minutes component (0-59).

Returns:

The minutes component within the hour.

Hours hours() const noexcept

Return the hours component (0-23).

Returns:

The hours component within the day.

Days days() const noexcept

Return the days component.

Returns:

The total number of days.

Parts parts(DurationPart largestPart = DurationPart::Days) const noexcept

Split this duration into day/hour/minute/second parts.

The largestPart parameter controls which unit is used as the top-level component. For example, DurationPart::Weeks includes weeks in the result. Negative durations keep negative signs in their extracted components.

Parameters:

largestPart – The largest unit to include.

Returns:

Named weeks, days, hours, minutes, and seconds parts.

inline constexpr Seconds toSeconds() const noexcept

Return the total seconds.

Returns:

The total second value.

std::chrono::seconds toStdSeconds() const noexcept

Convert to std::chrono::seconds.

Returns:

The equivalent chrono duration.

DaysAndNanoseconds toDaysAndNanoseconds() const noexcept

Split into whole days and a signed sub-day nanosecond remainder.

Returns:

Whole days and remaining nanoseconds.

double toDaysWithFractions() const noexcept

Convert to days with fractions.

Returns:

The total signed duration in days.

bool wouldConvertToTimeDeltaSaturate() const noexcept

Test if conversion to TimeDelta would saturate.

Returns:

true if toTimeDelta() would return a saturated nanosecond value.

TimeDelta toTimeDelta() const noexcept

Convert to a time delta with nanosecond precision, saturating if outside nanosecond bounds.

Returns:

The saturated time delta.

TimeDelta toTimeDeltaOrThrow() const

Convert to a time delta with nanosecond precision.

Throws:

err::OverflowError – if the conversion would saturate.

Returns:

The time delta.

Public Static Functions

static inline Duration zero() noexcept

Return a zero duration.

Returns:

A zero-valued Duration.

struct DaysAndNanoseconds

Split duration into whole days and a signed sub-day nanosecond remainder.

Public Members

Days days

Whole days, truncated toward zero.

Nanoseconds nanoseconds

Signed sub-day nanosecond remainder.

struct Parts

Split duration parts.

Public Members

Seconds seconds

The seconds component.

Minutes minutes

The minutes component.

Hours hours

The hours component.

Days days

The days component.

Weeks weeks

The weeks component.

enum class erbsland::time::DurationPart : uint8_t

Controls which part is used as the largest unit when splitting a duration into parts.

For example, DurationPart::Days causes Duration::parts() to return days as the largest unit, with weeks zeroed out.

Values:

enumerator Seconds

The seconds part.

enumerator Minutes

The minutes part.

enumerator Hours

The hours part.

enumerator Days

The days part.

enumerator Weeks

The weeks part.

class ElapsedTimer

A small helper for measuring elapsed monotonic time.

Starts timing on construction and provides elapsed time queries.

Public Functions

inline ElapsedTimer() noexcept

Start the timer at the current time.

inline void restart() noexcept

Restart the timer, resetting the elapsed time to zero.

inline TimeDelta elapsed() const noexcept

Return elapsed time since construction or last restart.

Returns:

The elapsed duration.

class Hour : public erbsland::time::impl::TimePartWithAmount<Hour, Hours, int8_t, 0, 23>

An hour within a day, range 0..23.

Provides clamped arithmetic.

enum class erbsland::time::IsoTimeFormat : uint8_t

Flags for ISO date/time formatting.

Values:

enumerator Extended

Use separators such as -, :, and extended offsets.

enumerator TimePrefix

Prefix standalone time output with T.

enumerator TimeShift

Append the UTC offset for date/time output.

enumerator TimeShiftAlwaysComplete

Format zero offset numerically instead of Z.

enumerator TimeShiftUpToSeconds

Include offset seconds when needed.

enumerator UseDotFraction

Use . instead of , before fractional seconds.

enumerator All
using erbsland::time::IsoTimeFormatFlags = util::EnumFlags<IsoTimeFormat>

A set of ISO date/time formatting flags.

inline Nanoseconds erbsland::time::literals::operator""_ns(const unsigned long long value)

Literal for nanoseconds.

inline Microseconds erbsland::time::literals::operator""_us(const unsigned long long value)

Literal for microseconds.

inline Milliseconds erbsland::time::literals::operator""_ms(const unsigned long long value)

Literal for milliseconds.

inline Seconds erbsland::time::literals::operator""_s(const unsigned long long value)

Literal for seconds.

inline Minutes erbsland::time::literals::operator""_m(const unsigned long long value)

Literal for minutes.

inline Hours erbsland::time::literals::operator""_h(const unsigned long long value)

Literal for hours.

class Minute : public erbsland::time::impl::TimePartWithAmount<Minute, Minutes, int8_t, 0, 59>

A minute within an hour, range 0..59.

Provides clamped arithmetic.

class Month : public erbsland::time::impl::TimePartWithAmount<Month, Months, int8_t, 1, 12>

A month in the Gregorian calendar, range 1..12.

Provides clamped arithmetic, month-aware navigation and calendar computation methods.

Public Functions

Days dayCount(Year year) const noexcept

Return the number of days in this month of year.

Parameters:

year – The year to check.

Returns:

The day count (28-31).

Day lastDay(Year year) const noexcept

Return the last day in this month of year.

Parameters:

year – The year to check.

Returns:

The last valid day.

DayOfYear firstDayOfYear(Year year) const noexcept

Return the first day-of-year for this month of year.

Parameters:

year – The year to check.

Returns:

The one-based day-of-year of the first day.

DayOfYear lastDayOfYear(Year year) const noexcept

Return the last day-of-year for this month of year.

Parameters:

year – The year to check.

Returns:

The one-based day-of-year of the last day.

Days minimumDayCount() const noexcept

Return the minimum number of days this month can have.

Returns:

28 for February, 30 for April/June/September/November, 31 otherwise.

Days maximumDayCount() const noexcept

Return the maximum number of days this month can have.

Returns:

Same as minimumDayCount(), except February returns 29 in leap years.

inline bool hasFixedLength() const noexcept

Test if the month has a fixed length in every year.

Returns:

true for all months except February.

YearMonthParts next(Year year) const noexcept

Return the next month parts, clamped at the supported date range.

If this is December of the last supported year, the result stays at the same year and month.

Parameters:

year – The current year.

Returns:

The next year and month.

YearMonthParts previous(Year year) const noexcept

Return the previous month parts, clamped at the supported date range.

If this is January of the first supported year, the result stays at the same year and month.

Parameters:

year – The current year.

Returns:

The previous year and month.

bool hasNext(Year year) const noexcept

Test if this month has a following month in the supported date range.

Parameters:

year – The current year.

Returns:

true if this month is less than December or the year is less than 9999.

bool hasPrevious(Year year) const noexcept

Test if this month has a previous month in the supported date range.

Parameters:

year – The current year.

Returns:

true if this month is greater than January or the year is greater than 0.

Public Static Functions

static MonthDayParts extractMonthAndDay(Year year, Days days) noexcept

Extract the month and day from a zero-based day-of-year amount.

Values outside the year are clamped by DayOfYear::fromAmount() before extraction.

Parameters:
  • year – The year to use for leap year calculation.

  • days – The zero-based day-of-year amount.

Returns:

The extracted month and day.

static MonthDayParts extractMonthAndDay(Year year, DayOfYear dayOfYear) noexcept

Extract the month and day from a one-based day-of-year.

Out-of-range day-of-year values are already clamped by DayOfYear.

Parameters:
  • year – The year to use for leap year calculation.

  • dayOfYear – The one-based day-of-year.

Returns:

The extracted month and day.

static inline Month january() noexcept

January.

static inline Month february() noexcept

February.

static inline Month march() noexcept

March.

static inline Month april() noexcept

April.

static inline Month may() noexcept

May.

static inline Month june() noexcept

June.

static inline Month july() noexcept

July.

static inline Month august() noexcept

August.

static inline Month september() noexcept

September.

static inline Month october() noexcept

October.

static inline Month november() noexcept

November.

static inline Month december() noexcept

December.

class Second : public erbsland::time::impl::TimePartWithAmount<Second, Seconds, int8_t, 0, 59>

A second within a minute, range 0..59.

Provides clamped arithmetic.

class Time

A wall-clock time of day with nanosecond precision.

Represents a time within a day from midnight to just before the next midnight. Stored internally as nanoseconds since midnight for sub-second precision.

See: Date and Time

Public Functions

Time() noexcept = default

Create midnight (zero time).

Time(Hour hour, Minute minute, Second second = Second{}, Nanoseconds nsFraction = Nanoseconds{}) noexcept

Create a time from parts.

The hour, minute and second part types clamp their construction input to their valid ranges. The nanosecond fraction is additionally clamped to the range 0..999999999.

Parameters:
  • hour – The hour (0-23).

  • minute – The minute (0-59).

  • second – The second (0-59), defaults to zero.

  • nsFraction – The nanosecond fraction (0-999999999), defaults to zero.

inline constexpr bool isZero() const noexcept

Test if this time is exactly midnight.

Hour hour() const noexcept

Return the hour component.

Returns:

The hour (0-23).

Minute minute() const noexcept

Return the minute component.

Returns:

The minute (0-59).

Second second() const noexcept

Return the second component.

Returns:

The second (0-59).

Milliseconds millisecondFraction() const noexcept

Return the millisecond fraction of the second.

Returns:

The millisecond component (0-999).

Nanoseconds nanosecondFraction() const noexcept

Return the nanosecond fraction of the second.

Returns:

The nanosecond component (0-999999999).

TimeParts parts() const noexcept

Return all time parts.

Returns:

Named hour, minute, second, and nanosecond fraction parts.

Duration durationSinceMidnight() const noexcept

Return the duration since midnight.

Returns:

The duration from midnight, truncated to seconds.

TimeDelta timeDeltaSinceMidnight() const noexcept

Return the time delta since midnight with nanosecond precision.

Returns:

The time delta from midnight.

text::String toString() const

Convert this time to a compact human-readable string.

The result always contains hours, minutes and seconds. A non-zero nanosecond fraction is appended without trailing zeroes.

Returns:

The formatted time.

Seconds toSecondsSinceMidnight() const noexcept

Return the total seconds since midnight.

Returns:

The seconds since midnight.

Nanoseconds toNanosecondsSinceMidnight() const noexcept

Return the total nanoseconds since midnight.

Returns:

The nanoseconds since midnight.

auto toIsoString(IsoTimeFormatFlags flags = cDefaultTimeFormat, DateTimePrecision precision = DateTimePrecision::Second) const -> text::String

Convert this time to an ISO 8601 string.

Parameters:
  • flags – Formatting flags for the output.

  • precision – The largest precision to include.

Returns:

The ISO-formatted time string.

Days addWithWrap(TimeDelta delta) noexcept

Add a time delta, wrapping past midnight.

Any positive or negative delta is accepted. If the addition crosses midnight, the time wraps and the number of days crossed is returned. Negative deltas return a negative day count.

Parameters:

delta – The delta to add.

Returns:

The number of days crossed (positive or negative).

Days addWithWrap(Duration duration) noexcept

Add a duration, wrapping past midnight.

Any positive or negative duration is accepted. Negative durations return a negative day count.

Parameters:

duration – The duration to add.

Returns:

The number of days crossed (positive or negative).

TimeWrapResult addedWithWrap(TimeDelta delta) const noexcept

Return this time plus a delta, wrapping past midnight.

Parameters:

delta – The delta to add.

Returns:

The wrapped time and the number of days crossed.

TimeWrapResult addedWithWrap(Duration duration) const noexcept

Return this time plus a duration, wrapping past midnight.

Parameters:

duration – The duration to add.

Returns:

The wrapped time and the number of days crossed.

Public Static Functions

static Time fromDurationSinceMidnight(TimeDelta duration) noexcept

Create a time from a duration since midnight.

Negative and over-day values wrap into the 24-hour range.

Parameters:

duration – The duration since midnight.

Returns:

The resulting time, wrapped if necessary.

static Time fromDurationSinceMidnight(Duration duration) noexcept

Create a time from a duration since midnight.

Negative and over-day values wrap into the 24-hour range.

Parameters:

duration – The duration since midnight.

Returns:

The resulting time, wrapped if necessary.

static Time first() noexcept

Return the first possible time of day.

Returns:

00:00:00.000000000.

static Time last() noexcept

Return the last possible time of day.

Returns:

23:59:59.999999999.

using erbsland::time::Nanoseconds = unit::IntegerAmount<SecondsUnitTag, std::nano>

Nanosecond amount.

using erbsland::time::Microseconds = unit::IntegerAmount<SecondsUnitTag, std::micro>

Microsecond amount.

using erbsland::time::Milliseconds = unit::IntegerAmount<SecondsUnitTag, std::milli>

Millisecond amount.

using erbsland::time::Seconds = unit::IntegerAmount<SecondsUnitTag, std::ratio<1>>

Second amount.

using erbsland::time::Minutes = unit::IntegerAmount<SecondsUnitTag, std::ratio<60>>

Minute amount.

using erbsland::time::Hours = unit::IntegerAmount<SecondsUnitTag, std::ratio<3600>>

Hour amount.

using erbsland::time::Days = unit::IntegerAmount<SecondsUnitTag, std::ratio<86400>>

Day amount.

using erbsland::time::Weeks = unit::IntegerAmount<SecondsUnitTag, std::ratio<604800>>

Week amount.

using erbsland::time::Months = unit::IntegerAmount<MonthsUnitTag, std::ratio<1>>

Month amount.

using erbsland::time::Years = unit::IntegerAmount<YearsUnitTag, std::ratio<1>>

Year amount.

class TimeDelta

A signed time delta with nanosecond resolution.

Represents a duration between two points in time with full nanosecond precision. Arithmetic uses the saturating behavior of the underlying nanosecond amount.

Public Types

using IntegerValue = Nanoseconds::Value

The native integer type this delta is based on.

Public Functions

TimeDelta() noexcept = default

Create a zero delta.

inline explicit TimeDelta(const Nanoseconds nanoseconds) noexcept

Create a delta from nanoseconds.

Parameters:

nanoseconds – The nanosecond value.

template<typename tAmount>
inline constexpr TimeDelta(tAmount amount) noexcept

Create a delta from any seconds-based amount.

Saturates if the value exceeds the maximum representable value.

Template Parameters:

tAmount – The amount type with a SecondsUnitTag.

Parameters:

amount – The amount to convert.

template<typename tRep, typename tPeriod>
inline explicit TimeDelta(std::chrono::duration<tRep, tPeriod> duration) noexcept

Create a delta from a std::chrono::duration.

Template Parameters:
  • tRep – The representation type.

  • tPeriod – The period type.

Parameters:

duration – The chrono duration to convert.

TimeDelta operator+(TimeDelta other) const noexcept

Add two time deltas.

TimeDelta &operator+=(TimeDelta other) noexcept

Add a time delta.

TimeDelta operator-(TimeDelta other) const noexcept

Subtract two time deltas.

TimeDelta &operator-=(TimeDelta other) noexcept

Subtract a time delta.

TimeDelta operator-() const noexcept

Negate this time delta.

TimeDelta operator/(IntegerValue divisor) const noexcept

Divide this time delta.

By dividing the time-delta with regular integer, the result is a time-delta.

TimeDelta &operator/=(IntegerValue divisor) noexcept

Divide this time delta.

IntegerValue operator/(TimeDelta divisor) const noexcept

By dividing the time-delta with another time-delta, the result is a regular integer.

TimeDelta operator*(IntegerValue factor) const noexcept

Multiply this time delta.

TimeDelta &operator*=(IntegerValue factor) noexcept

Multiply this time delta.

inline constexpr bool isZero() const noexcept

Test if this delta is zero.

inline constexpr bool isPositive() const noexcept

Test if this delta is positive.

inline constexpr bool isNegative() const noexcept

Test if this delta is negative.

inline TimeDelta toAbsolute() const noexcept

Get the absolute value of this delta.

template<typename tAmount>
inline TimeDelta minimum(tAmount amount) const noexcept

Return a time delta that is at minimum the given value.

text::String toString(const TimeDeltaFormat &format = {}) const

Convert this delta to a human-readable string.

inline constexpr Nanoseconds toNanoseconds() const noexcept

Return the total nanoseconds.

Milliseconds toMilliseconds() const noexcept

Return the total milliseconds, truncating sub-milliseconds nanoseconds toward zero.

Seconds toSeconds() const noexcept

Return the total seconds, truncating sub-second nanoseconds toward zero.

double toSecondsWithFractions() const noexcept

Return the total seconds as a floating-point value.

double toDaysWithFractions() const noexcept

Return the total days as a floating-point value.

std::chrono::nanoseconds toStdNanoseconds() const noexcept

Convert to std::chrono::nanoseconds.

Duration toDuration() const noexcept

Convert to a duration, truncating sub-second nanoseconds toward zero.

Public Static Functions

static inline TimeDelta zero() noexcept

Return a zero delta.

static TimeDelta nanoseconds(int64_t ticks) noexcept

Return a time delta in nanoseconds.

static TimeDelta microseconds(int64_t ticks) noexcept

Return a time delta in microseconds.

If the value exceeds the maximum representable value, it saturates to the maximum.

static TimeDelta milliseconds(int64_t ticks) noexcept

Return a time delta in milliseconds.

If the value exceeds the maximum representable value, it saturates to the maximum.

static TimeDelta seconds(int64_t ticks) noexcept

Return a time delta in seconds.

If the value exceeds the maximum representable value, it saturates to the maximum.

static TimeDelta minutes(int64_t ticks) noexcept

Return a time delta in minutes.

If the value exceeds the maximum representable value, it saturates to the maximum.

static TimeDelta hours(int64_t ticks) noexcept

Return a time delta in hours.

If the value exceeds the maximum representable value, it saturates to the maximum.

static TimeDelta days(int64_t ticks) noexcept

Return a time delta in days.

If the value exceeds the maximum representable value, it saturates to the maximum.

static TimeDelta weeks(int64_t ticks) noexcept

Return a time delta in weeks.

If the value exceeds the maximum representable value, it saturates to the maximum.

static TimeDelta microsecondsOrThrow(int64_t ticks)

Return a time delta in microseconds.

Throws:

err::OverflowError – If the value exceeds the maximum representable value.

static TimeDelta millisecondsOrThrow(int64_t ticks)

Return a time delta in milliseconds.

Throws:

err::OverflowError – If the value exceeds the maximum representable value.

static TimeDelta secondsOrThrow(int64_t ticks)

Return a time delta in seconds.

Throws:

err::OverflowError – If the value exceeds the maximum representable value.

static TimeDelta minutesOrThrow(int64_t ticks)

Return a time delta in minutes.

Throws:

err::OverflowError – If the value exceeds the maximum representable value.

static TimeDelta hoursOrThrow(int64_t ticks)

Return a time delta in hours.

Throws:

err::OverflowError – If the value exceeds the maximum representable value.

static TimeDelta daysOrThrow(int64_t ticks)

Return a time delta in days.

Throws:

err::OverflowError – If the value exceeds the maximum representable value.

static TimeDelta weeksOrThrow(int64_t ticks)

Return a time delta in weeks.

Throws:

err::OverflowError – If the value exceeds the maximum representable value.

class TimeDeltaFormat

Options for formatting fixed and calendar time deltas.

See: Date and Time

Public Types

enum class UnitStyle : uint8_t

Style used for unit names.

Values:

enumerator Short
enumerator Long

Public Functions

TimeDeltaFormat()

Create the default compact human-readable format.

inline UnitStyle unitStyle() const noexcept

Get the style used to render unit names.

inline TimeDeltaFormat &setUnitStyle(UnitStyle value) noexcept

Set the style used to render unit names.

inline const text::String &valueSeparator() const noexcept

Get the separator placed between a value and its unit name.

inline TimeDeltaFormat &setValueSeparator(text::String value) noexcept

Set the separator placed between a value and its unit name.

inline const text::String &unitSeparator() const noexcept

Get the separator placed between formatted time-delta components.

inline TimeDeltaFormat &setUnitSeparator(text::String value) noexcept

Set the separator placed between formatted time-delta components.

inline TimeDeltaUnit smallestUnit() const noexcept

Get the smallest unit included in the formatted result.

inline TimeDeltaFormat &setSmallestUnit(TimeDeltaUnit value) noexcept

Set the smallest unit included in the formatted result.

inline bool showFractions() const noexcept

Test if fractional values are included in the formatted result.

inline TimeDeltaFormat &setShowFractions(bool value) noexcept

Set whether fractional values are included in the formatted result.

inline uint8_t maximumFractionDigits() const noexcept

Get the maximum number of fractional digits.

TimeDeltaFormat &setMaximumFractionDigits(uint8_t value) noexcept

Set the maximum number of fractional digits, limited to nine.

inline bool usesElclUnitNames() const noexcept

Test if ELCL-specific short aliases are selected.

Public Static Functions

static TimeDeltaFormat shortUnits()

Create the default short-unit format.

static TimeDeltaFormat longUnits()

Create the long-unit format.

static TimeDeltaFormat elcl()

Create an ELCL-compatible format.

enum class erbsland::time::TimeDeltaUnit : uint8_t

A fixed unit available for time-delta formatting.

Values:

enumerator Nanoseconds
enumerator Microseconds
enumerator Milliseconds
enumerator Seconds
enumerator Minutes
enumerator Hours
enumerator Days
enumerator Weeks
enum class erbsland::time::TimeEpoch : uint8_t

A well-known time epoch.

Values:

enumerator Core

The Erbsland Core epoch, 0000-01-01 00:00:00 UTC.

enumerator Posix

The POSIX epoch, 1970-01-01 00:00:00 UTC.

enumerator Windows

The Windows FILETIME epoch, 1601-01-01 00:00:00 UTC.

enumerator Rfc868

The RFC 868 epoch, 1900-01-01 00:00:00 UTC.

enum class erbsland::time::TimeOccurrenceInFold : uint8_t

Which local occurrence to choose when a wall clock time appears twice (during the fall-back gap when daylight saving time ends).

When clocks are set back, the same local time occurs twice. This enum disambiguates which occurrence to use.

Values:

enumerator First
enumerator Second
struct TimeParts

A wall-clock time split into named parts.

Public Members

Hour hour

The hour component, range 0..23.

Minute minute

The minute component, range 0..59.

Second second

The second component, range 0..59.

Nanoseconds nanosecondFraction

The nanosecond fraction, range 0..999999999.

class TimePoint

A monotonic time point for measuring elapsed time.

Wraps std::chrono::steady_clock::time_point and provides nanosecond-resolution arithmetic for measuring intervals.

Public Functions

TimePoint() noexcept = default

Create the clock epoch (zero time point).

inline explicit TimePoint(std::chrono::steady_clock::time_point value) noexcept

Create from a std::chrono::steady_clock::time_point.

Parameters:

value – The steady clock time point.

inline std::strong_ordering operator<=>(const TimePoint &other) const noexcept

Compare two monotonic time points.

inline TimeDelta operator-(const TimePoint &other) const noexcept

Calculate the delta between two time points.

inline TimePoint operator+(TimeDelta delta) const noexcept

Return a time point offset by a delta.

inline TimePoint &operator+=(TimeDelta delta) noexcept

Offset this time point by a delta.

inline TimePoint operator-(TimeDelta delta) const noexcept

Return a time point offset backwards by a delta.

inline TimePoint &operator-=(TimeDelta delta) noexcept

Offset this time point backwards by a delta.

inline TimeDelta timeDeltaTo(const TimePoint &timePoint) const noexcept

Return the time delta to another time point.

Parameters:

timePoint – The target time point.

Returns:

The duration from this point to the target.

inline TimeDelta timeDeltaToNow() const noexcept

Return the time delta to the current time.

Returns:

The duration from this point to now.

inline std::chrono::steady_clock::time_point toStdTimePoint() const noexcept

Convert to a standard-library steady-clock time point.

Public Static Functions

static inline TimePoint now() noexcept

Return the current steady clock time.

Returns:

The current time point.

static inline TimePoint inFuture(TimeDelta delta) noexcept

Create a time point in the future.

Parameters:

delta – The duration to add to the current time.

Returns:

A time point delta from now.

struct SecondsUnitTag

Unit tag for time amounts measured in seconds and fractions/multiples of seconds.

struct MonthsUnitTag

Unit tag for calendar month amounts.

struct YearsUnitTag

Unit tag for calendar year amounts.

class TimeWithZone

A wall-clock time accompanied by a time zone.

Without a date, a named zone cannot be resolved to a unique UTC offset. Combine this value with a Date to construct a DateTime when an exact instant is required.

See: Date and Time

Public Functions

TimeWithZone() noexcept = default

Create midnight UTC.

inline TimeWithZone(Time time, TimeZone timeZone = {}) noexcept

Create a time with a zone.

Parameters:
  • time – The wall-clock time.

  • timeZone – The accompanying time zone.

inline constexpr Time time() const noexcept

Return the wall-clock time.

inline constexpr TimeZone timeZone() const noexcept

Return the accompanying time zone.

inline Hour hour() const noexcept

Return the hour component.

inline Minute minute() const noexcept

Return the minute component.

inline Second second() const noexcept

Return the second component.

inline Milliseconds millisecondFraction() const noexcept

Return the millisecond fraction.

inline Nanoseconds nanosecondFraction() const noexcept

Return the nanosecond fraction.

text::String toString() const

Convert this value to a compact human-readable representation.

Local-origin zones are omitted. UTC and fixed zones use ISO suffixes; other named zones use brackets.

Returns:

The formatted wall-clock time and zone.

struct TimeWrapResult

The result of adding to a wall-clock time with wrapping.

Public Members

Time time

The wrapped time of day.

Days days

The number of day boundaries crossed.

class TimeZone

A UTC, fixed-offset, or named IANA time zone.

See: Date and Time

Public Functions

TimeZone() noexcept = default

Create UTC.

explicit TimeZone(Hours hours, Minutes minutes = Minutes{}, Seconds seconds = Seconds{}) noexcept

Create a fixed offset from parts.

The resulting offset is clamped into the range -23:59:59..+23:59:59. A zero offset creates UTC.

Parameters:
  • hours – The offset hours. Clamped into the range -23..+23.

  • minutes – The offset minutes. Clamped into the range -59..+59.

  • seconds – The offset seconds. Clamped into the range -59..+59.

explicit TimeZone(Duration offset) noexcept

Create a fixed offset.

The offset is normalized into the range -23:59:59..+23:59:59. A zero offset creates UTC.

Parameters:

offset – The total offset duration.

explicit TimeZone(TimeZoneId id) noexcept

Create a named time zone from a transient id.

The UTC and not-found identifiers create UTC.

Parameters:

id – The time zone identifier.

bool operator==(const TimeZone &other) const noexcept = default

Compare time zones.

bool isUtc() const noexcept

Test if this zone is UTC.

Returns:

true if this is the UTC time zone.

bool isStaticOffset() const noexcept

Test if this zone is a fixed non-zero UTC offset.

Returns:

true if this is a fixed offset other than UTC.

bool isNamed() const noexcept

Test if this zone is a named IANA time zone.

Returns:

true if this is a named zone.

inline constexpr bool isLocalTime() const noexcept

Test if this zone originated from the system-local setting.

Returns:

true if this is the system-local zone.

Duration staticOffset() const noexcept

Return the fixed offset, or zero for UTC and named zones.

Returns:

The fixed offset duration.

text::String name() const

Return the primary IANA zone name, or an empty string for UTC and fixed offsets.

Returns:

The zone name (e.g. America/New_York).

TimeZoneId id() const noexcept

Return the transient time-zone identifier, or the UTC identifier for UTC and fixed offsets.

Returns:

The zone identifier.

Public Static Functions

static bool isValidName(const text::String &name) noexcept

Test if a name is known.

Parameters:

name – The zone name to check.

Returns:

true if the zone is supported.

static std::optional<TimeZone> fromName(const text::String &name) noexcept

Create a named zone from a name.

Also accepts special UTC names such as UTC, GMT, Z, and fixed-offset names such as UTC+02:00.

Parameters:

name – The zone name.

Returns:

The time zone, or std::nullopt if unknown.

static TimeZone fromNameOrThrow(const text::String &name)

Create a named zone from a name or throw.

Also accepts special UTC names such as UTC, GMT, Z, and fixed-offset names such as UTC+02:00.

Parameters:

name – The zone name.

Throws:

err::ParseError – if the zone name is unknown.

Returns:

The time zone.

static text::StringList names()

Return all supported zone names.

Returns:

A list of all IANA zone names in the bundled database.

static unit::Version databaseVersion() noexcept

Return the bundled IANA database version.

Returns:

The version of the bundled time zone database.

static inline TimeZone utc() noexcept

Return UTC.

static TimeZone local() noexcept

Return the process-cached system-local base time zone.

Unknown or unavailable platform settings produce local-marked UTC.

Returns:

The system-local zone.

class TimeZoneId

A transient identifier for a named time zone.

Used internally to reference time zones without storing full name strings.

Public Functions

constexpr TimeZoneId() noexcept = default

Create the UTC identifier.

inline explicit constexpr TimeZoneId(uint16_t value) noexcept

Create an identifier from its raw value.

Parameters:

value – The raw identifier value.

constexpr std::strong_ordering operator<=>(const TimeZoneId &other) const noexcept = default

Compare identifiers.

inline constexpr uint16_t toRawValue() const noexcept

Return the raw identifier.

Returns:

The underlying identifier value.

inline constexpr bool isUtc() const noexcept

Test if this is the UTC/no-zone identifier.

Returns:

true if this represents UTC.

class TimeOffset

Offset details stored with a date/time value.

Holds the UTC offset, zone identifier, and daylight saving information for a specific point in time.

Public Functions

TimeOffset() noexcept = default

Create UTC offset.

inline explicit TimeOffset(Seconds offset, bool isLocalTime = false) noexcept

Create a fixed offset.

Parameters:
  • offset – The UTC offset.

  • isLocalTime – Whether the offset originated from the system-local zone.

inline TimeOffset(Seconds offset, bool isDst, TimeZoneId zoneId, uint8_t abbreviationId, bool isLocalTime = false) noexcept

Create a named-zone offset.

Parameters:
  • offset – The UTC offset.

  • isDst – Whether daylight saving time is active.

  • zoneId – The time zone identifier.

  • abbreviationId – The abbreviation index.

  • isLocalTime – Whether the offset originated from the system-local zone.

inline constexpr bool isUtc() const noexcept

Test if this offset represents UTC without a named zone.

inline constexpr bool isStaticOffset() const noexcept

Test if this offset is a fixed non-zero UTC offset.

inline constexpr bool isZone() const noexcept

Test if this offset is associated with a named time zone.

inline constexpr bool isDst() const noexcept

Test if daylight saving time is active for this offset.

inline constexpr bool isLocalTime() const noexcept

Test if this offset originated from the system-local zone.

inline constexpr Seconds offset() const noexcept

Return the UTC offset in seconds.

inline constexpr TimeZoneId zoneId() const noexcept

Return the time zone identifier.

inline constexpr uint8_t abbreviationId() const noexcept

Return the time zone abbreviation table index.

class Year : public erbsland::time::impl::TimePartWithAmount<Year, Years, int16_t, 0, 9999>

A Gregorian calendar year in the supported range 0...9999.

Public Functions

bool isLeapYear() const noexcept

Test if this is a leap year in the proleptic Gregorian calendar.

Days dayCount() const noexcept

Return the number of days in this year.

Returns:

366 for leap years, 365 otherwise.

Days daysSinceEpoch() const noexcept

Return the number of days from epoch to the first day of this year.

Returns:

The number of days since the epoch.

Days daysBeforeMonth(Month month) const noexcept

Return the number of days before a given month in this year.

Parameters:

month – The month (1-12).

Returns:

The cumulative day count before the month starts.

Month monthOfDay(DayOfYear dayOfYear) const noexcept

Return the month of the day of year.

Parameters:

dayOfYear – The day of the year.

Returns:

The month of that day.

Year next() const noexcept

Return the next year, clamped at the supported range.

Returns:

The following year, or the current year if already at maximum.

Year previous() const noexcept

Return the previous year, clamped at the supported range.

Returns:

The preceding year, or the current year if already at minimum.

inline constexpr bool hasNext() const noexcept

Test if this year has a following year in the supported range.

Returns:

true if this year is less than 9999.

inline constexpr bool hasPrevious() const noexcept

Test if this year has a previous year in the supported range.

Returns:

true if this year is greater than 0.

Public Static Functions

static YearDayOfYearParts extractFromEpoch(Days days) noexcept

Extract a year and zero-based day-of-year from days since epoch.

Values before the epoch are clamped to 0000-01-01; values after the supported range are clamped to 9999-12-31.

Parameters:

days – The number of days since the epoch.

Returns:

The extracted year and zero-based day-of-year.