xentara-utils v1.2.1
Xentara utilities library
Loading...
Searching...
No Matches
xentara::utils::chrono Namespace Reference

std::chrono compatibility More...

Classes

class  DecomposedDate
 A date, decomposed into its components. More...
 
class  DecomposedTimePoint
 A time point, decomposed into its components. More...
 

Functions

constexpr auto maxDateLength () -> std::size_t
 Returns the maximum length needed to hold a date string.
 
constexpr auto maxTimeStringSize (int secondsPrecision=9) -> std::size_t
 Returns the maximum length needed to hold a time string.
 
constexpr auto maxDateTimeStringSize (int secondsPrecision=9) -> std::size_t
 Returns the maximum length needed to hold a date and time string.
 
template<tools::CharType Char, typename CharTraits = std::char_traits<Char>>
auto toBasicString (std::chrono::system_clock::time_point timePoint, const std::optional< std::chrono::minutes > &utcOffset=std::nullopt) -> string::BasicStaticString< Char, maxDateTimeStringSize(), CharTraits >
 Converts a time point to a string.
 
auto toString (std::chrono::system_clock::time_point timePoint, const std::optional< std::chrono::minutes > &utcOffset=std::nullopt) -> string::StaticString< maxDateTimeStringSize()>
 Converts a time point to a string of type char
 
auto toWString (std::chrono::system_clock::time_point timePoint, const std::optional< std::chrono::minutes > &utcOffset=std::nullopt) -> string::StaticWString< maxDateTimeStringSize()>
 Converts a time point to a string of type wchar_t
 
auto toU8String (std::chrono::system_clock::time_point timePoint, const std::optional< std::chrono::minutes > &utcOffset=std::nullopt) -> string::StaticU8String< maxDateTimeStringSize()>
 Converts a time point to a string of type char8_t
 
auto toU16String (std::chrono::system_clock::time_point timePoint, const std::optional< std::chrono::minutes > &utcOffset=std::nullopt) -> string::StaticU16String< maxDateTimeStringSize()>
 Converts a time point to a string of type char16_t
 
auto toU32String (std::chrono::system_clock::time_point timePoint, const std::optional< std::chrono::minutes > &utcOffset=std::nullopt) -> string::StaticU32String< maxDateTimeStringSize()>
 Converts a number to a string of type char32_t
 
template<tools::CharType Char, typename CharTraits = std::char_traits<Char>>
auto toCompactBasicString (std::chrono::system_clock::time_point timePoint, const std::optional< std::chrono::minutes > &utcOffset=std::nullopt) -> string::BasicStaticString< Char, maxDateTimeStringSize(), CharTraits >
 Converts a time point to a string without unecessary seconds or fractions of a second.
 
auto toCompactString (std::chrono::system_clock::time_point timePoint, const std::optional< std::chrono::minutes > &utcOffset=std::nullopt) -> string::StaticString< maxDateTimeStringSize()>
 Converts a time point to a string of type char without unecessary seconds or fractions of a second.
 
auto toCompactWString (std::chrono::system_clock::time_point timePoint, const std::optional< std::chrono::minutes > &utcOffset=std::nullopt) -> string::StaticWString< maxDateTimeStringSize()>
 Converts a time point to a string of type wchar_t without unecessary seconds or fractions of a second.
 
auto toCompactU8String (std::chrono::system_clock::time_point timePoint, const std::optional< std::chrono::minutes > &utcOffset=std::nullopt) -> string::StaticU8String< maxDateTimeStringSize()>
 Converts a time point to a string of type char8_t without unecessary seconds or fractions of a second.
 
auto toCompactU16String (std::chrono::system_clock::time_point timePoint, const std::optional< std::chrono::minutes > &utcOffset=std::nullopt) -> string::StaticU16String< maxDateTimeStringSize()>
 Converts a time point to a string of type char16_t without unecessary seconds or fractions of a second.
 
auto toCompactU32String (std::chrono::system_clock::time_point timePoint, const std::optional< std::chrono::minutes > &utcOffset=std::nullopt) -> string::StaticU32String< maxDateTimeStringSize()>
 Converts a number to a string of type char32_t without unecessary seconds or fractions of a second.
 
template<tools::CharType Char, typename CharTraits = std::char_traits<Char>>
auto toIsoBasicString (std::chrono::system_clock::time_point timePoint, const std::optional< std::chrono::minutes > &utcOffset=std::nullopt) -> string::BasicStaticString< Char, maxDateTimeStringSize(), CharTraits >
 Converts a time point to a string in ISO 8601/RFC 3999 format.
 
auto toIsoString (std::chrono::system_clock::time_point timePoint, const std::optional< std::chrono::minutes > &utcOffset=std::nullopt) -> string::StaticString< maxDateTimeStringSize()>
 Converts a time point to a string of type char in ISO 8601/RFC 3999 format.
 
auto toIsoWString (std::chrono::system_clock::time_point timePoint, const std::optional< std::chrono::minutes > &utcOffset=std::nullopt) -> string::StaticWString< maxDateTimeStringSize()>
 Converts a time point to a string of type wchar_t in ISO 8601/RFC 3999 format.
 
auto toIsoU8String (std::chrono::system_clock::time_point timePoint, const std::optional< std::chrono::minutes > &utcOffset=std::nullopt) -> string::StaticU8String< maxDateTimeStringSize()>
 Converts a time point to a string of type char8_t in ISO 8601/RFC 3999 format.
 
auto toIsoU16String (std::chrono::system_clock::time_point timePoint, const std::optional< std::chrono::minutes > &utcOffset=std::nullopt) -> string::StaticU16String< maxDateTimeStringSize()>
 Converts a time point to a string of type char16_t in ISO 8601/RFC 3999 format.
 
auto toIsoU32String (std::chrono::system_clock::time_point timePoint, const std::optional< std::chrono::minutes > &utcOffset=std::nullopt) -> string::StaticU32String< maxDateTimeStringSize()>
 Converts a number to a string of type char32_t in ISO 8601/RFC 3999 format.
 
template<typename Rep , typename Period >
auto toTimeSpec (const std::chrono::duration< Rep, Period > &duration) -> eh::expected< std::timespec, std::error_code >
 Converts a duration to an std::timespec value.
 
template<typename Clock , typename Duration >
auto toTimeSpec (const std::chrono::time_point< Clock, Duration > &timePoint) -> eh::expected< std::timespec, std::error_code >
 Converts a time point to an std::timespec value.
 

Variables

constexpr std::chrono::system_clock::time_point kReferenceTime
 Standard reference time.
 

Detailed Description

std::chrono compatibility

This namespace contains date and time facilities.

Function Documentation

◆ maxDateLength()

constexpr auto xentara::utils::chrono::maxDateLength ( ) -> std::size_t
constexpr

Returns the maximum length needed to hold a date string.

This function can be used to preallocate buffers used to format date strings.

Returns
The buffer size required to format a date string.

◆ maxDateTimeStringSize()

constexpr auto xentara::utils::chrono::maxDateTimeStringSize ( int  secondsPrecision = 9) -> std::size_t
constexpr

Returns the maximum length needed to hold a date and time string.

This function can be used to preallocate buffers used to format time and date strings.

Parameters
secondsPrecisionThe precision for the seconds. If secondsPrecision is negative, then the space needed for a string without seconds is returned.
Returns
The buffer size required to format a date and time string, with time zone.

◆ maxTimeStringSize()

constexpr auto xentara::utils::chrono::maxTimeStringSize ( int  secondsPrecision = 9) -> std::size_t
constexpr

Returns the maximum length needed to hold a time string.

This function can be used to preallocate buffers used to format time strings.

Parameters
secondsPrecisionThe precision for the seconds. If secondsPrecision is negative, then the space needed for a string without seconds is returned.
Returns
The buffer size required to format a time string, with time zone.

◆ toBasicString()

template<tools::CharType Char, typename CharTraits = std::char_traits<Char>>
auto xentara::utils::chrono::toBasicString ( std::chrono::system_clock::time_point  timePoint,
const std::optional< std::chrono::minutes > &  utcOffset = std::nullopt 
) -> string::BasicStaticString<Char, maxDateTimeStringSize(), CharTraits>

Converts a time point to a string.

Parameters
timePointThe time point
utcOffsetThe UTC offset to represent the time in, or std::nullopt to use local time. The UTC offset only influences how the time is represented in the constructed object: timePoint must always be a regular UTC time without any offset. If you pass a time of 1 January 2001, 00:00:00.000 UTC and a UTC offset of +1 hours, the time will decomposed to 2001-01-01 01:00:00 UTC+01:00, for example.
Returns
A string containing the time point

◆ toCompactBasicString()

template<tools::CharType Char, typename CharTraits = std::char_traits<Char>>
auto xentara::utils::chrono::toCompactBasicString ( std::chrono::system_clock::time_point  timePoint,
const std::optional< std::chrono::minutes > &  utcOffset = std::nullopt 
) -> string::BasicStaticString<Char, maxDateTimeStringSize(), CharTraits>

Converts a time point to a string without unecessary seconds or fractions of a second.

The returned string only shows as much of seconds and fractions of a second as necessary

Parameters
timePointThe time point
utcOffsetThe UTC offset to represent the time in, or std::nullopt to use local time. The UTC offset only influences how the time is represented in the constructed object: timePoint must always be a regular UTC time without any offset. If you pass a time of 1 January 2001, 00:00:00.000 UTC and a UTC offset of +1 hours, the time will decomposed to 2001-01-01 01:00:00 UTC+01:00, for example.
Returns
A string containing the time point

◆ toCompactString()

auto xentara::utils::chrono::toCompactString ( std::chrono::system_clock::time_point  timePoint,
const std::optional< std::chrono::minutes > &  utcOffset = std::nullopt 
) -> string::StaticString<maxDateTimeStringSize()>

Converts a time point to a string of type char without unecessary seconds or fractions of a second.

The returned string only shows as much of seconds and fractions of a second as necessary

Parameters
timePointThe time point
utcOffsetThe UTC offset to represent the time in, or std::nullopt to use local time. The UTC offset only influences how the time is represented in the constructed object: timePoint must always be a regular UTC time without any offset. If you pass a time of 1 January 2001, 00:00:00.000 UTC and a UTC offset of +1 hours, the time will decomposed to 2001-01-01 01:00:00 UTC+01:00, for example.
Returns
A string containing the time point

◆ toCompactU16String()

auto xentara::utils::chrono::toCompactU16String ( std::chrono::system_clock::time_point  timePoint,
const std::optional< std::chrono::minutes > &  utcOffset = std::nullopt 
) -> string::StaticU16String<maxDateTimeStringSize()>

Converts a time point to a string of type char16_t without unecessary seconds or fractions of a second.

The returned string only shows as much of seconds and fractions of a second as necessary

Parameters
timePointThe time point
utcOffsetThe UTC offset to represent the time in, or std::nullopt to use local time. The UTC offset only influences how the time is represented in the constructed object: timePoint must always be a regular UTC time without any offset. If you pass a time of 1 January 2001, 00:00:00.000 UTC and a UTC offset of +1 hours, the time will decomposed to 2001-01-01 01:00:00 UTC+01:00, for example.
Returns
A string containing the time point

◆ toCompactU32String()

auto xentara::utils::chrono::toCompactU32String ( std::chrono::system_clock::time_point  timePoint,
const std::optional< std::chrono::minutes > &  utcOffset = std::nullopt 
) -> string::StaticU32String<maxDateTimeStringSize()>

Converts a number to a string of type char32_t without unecessary seconds or fractions of a second.

The returned string only shows as much of seconds and fractions of a second as necessary

Parameters
timePointThe time point
utcOffsetThe UTC offset to represent the time in, or std::nullopt to use local time. The UTC offset only influences how the time is represented in the constructed object: timePoint must always be a regular UTC time without any offset. If you pass a time of 1 January 2001, 00:00:00.000 UTC and a UTC offset of +1 hours, the time will decomposed to 2001-01-01 01:00:00 UTC+01:00, for example.
Returns
A string containing the time point

◆ toCompactU8String()

auto xentara::utils::chrono::toCompactU8String ( std::chrono::system_clock::time_point  timePoint,
const std::optional< std::chrono::minutes > &  utcOffset = std::nullopt 
) -> string::StaticU8String<maxDateTimeStringSize()>

Converts a time point to a string of type char8_t without unecessary seconds or fractions of a second.

The returned string only shows as much of seconds and fractions of a second as necessary

Parameters
timePointThe time point
utcOffsetThe UTC offset to represent the time in, or std::nullopt to use local time. The UTC offset only influences how the time is represented in the constructed object: timePoint must always be a regular UTC time without any offset. If you pass a time of 1 January 2001, 00:00:00.000 UTC and a UTC offset of +1 hours, the time will decomposed to 2001-01-01 01:00:00 UTC+01:00, for example.
Returns
A string containing the time point

◆ toCompactWString()

auto xentara::utils::chrono::toCompactWString ( std::chrono::system_clock::time_point  timePoint,
const std::optional< std::chrono::minutes > &  utcOffset = std::nullopt 
) -> string::StaticWString<maxDateTimeStringSize()>

Converts a time point to a string of type wchar_t without unecessary seconds or fractions of a second.

The returned string only shows as much of seconds and fractions of a second as necessary

Parameters
timePointThe time point
utcOffsetThe UTC offset to represent the time in, or std::nullopt to use local time. The UTC offset only influences how the time is represented in the constructed object: timePoint must always be a regular UTC time without any offset. If you pass a time of 1 January 2001, 00:00:00.000 UTC and a UTC offset of +1 hours, the time will decomposed to 2001-01-01 01:00:00 UTC+01:00, for example.
Returns
A string containing the time point

◆ toIsoBasicString()

template<tools::CharType Char, typename CharTraits = std::char_traits<Char>>
auto xentara::utils::chrono::toIsoBasicString ( std::chrono::system_clock::time_point  timePoint,
const std::optional< std::chrono::minutes > &  utcOffset = std::nullopt 
) -> string::BasicStaticString<Char, maxDateTimeStringSize(), CharTraits>

Converts a time point to a string in ISO 8601/RFC 3999 format.

The returned string has the format YYYY-MM-DDThh:mm:ss.zzzzzzzzz±HH:MM. For a utcOffset of 0, ±HH:MM is replaced with the character “Z”.

Parameters
timePointThe time point
utcOffsetThe UTC offset to represent the time in, or std::nullopt to use local time. The UTC offset only influences how the time is represented in the constructed object: timePoint must always be a regular UTC time without any offset. If you pass a time of 1 January 2001, 00:00:00.000 UTC and a UTC offset of +1 hours, the time will decomposed to 2001-01-01 01:00:00 UTC+01:00, for example.
Returns
A string containing the time point

◆ toIsoString()

auto xentara::utils::chrono::toIsoString ( std::chrono::system_clock::time_point  timePoint,
const std::optional< std::chrono::minutes > &  utcOffset = std::nullopt 
) -> string::StaticString<maxDateTimeStringSize()>

Converts a time point to a string of type char in ISO 8601/RFC 3999 format.

The returned string has the format YYYY-MM-DDThh:mm:ss.zzzzzzzzz±HH:MM. For a utcOffset of 0, ±HH:MM is replaced with the character “Z”.

Parameters
timePointThe time point
utcOffsetThe UTC offset to represent the time in, or std::nullopt to use local time. The UTC offset only influences how the time is represented in the constructed object: timePoint must always be a regular UTC time without any offset. If you pass a time of 1 January 2001, 00:00:00.000 UTC and a UTC offset of +1 hours, the time will decomposed to 2001-01-01 01:00:00 UTC+01:00, for example.
Returns
A string containing the time point

◆ toIsoU16String()

auto xentara::utils::chrono::toIsoU16String ( std::chrono::system_clock::time_point  timePoint,
const std::optional< std::chrono::minutes > &  utcOffset = std::nullopt 
) -> string::StaticU16String<maxDateTimeStringSize()>

Converts a time point to a string of type char16_t in ISO 8601/RFC 3999 format.

The returned string has the format YYYY-MM-DDThh:mm:ss.zzzzzzzzz±HH:MM. For a utcOffset of 0, ±HH:MM is replaced with the character “Z”.

Parameters
timePointThe time point
utcOffsetThe UTC offset to represent the time in, or std::nullopt to use local time. The UTC offset only influences how the time is represented in the constructed object: timePoint must always be a regular UTC time without any offset. If you pass a time of 1 January 2001, 00:00:00.000 UTC and a UTC offset of +1 hours, the time will decomposed to 2001-01-01 01:00:00 UTC+01:00, for example.
Returns
A string containing the time point

◆ toIsoU32String()

auto xentara::utils::chrono::toIsoU32String ( std::chrono::system_clock::time_point  timePoint,
const std::optional< std::chrono::minutes > &  utcOffset = std::nullopt 
) -> string::StaticU32String<maxDateTimeStringSize()>

Converts a number to a string of type char32_t in ISO 8601/RFC 3999 format.

The returned string has the format YYYY-MM-DDThh:mm:ss.zzzzzzzzz±HH:MM. For a utcOffset of 0, ±HH:MM is replaced with the character “Z”.

Parameters
timePointThe time point
utcOffsetThe UTC offset to represent the time in, or std::nullopt to use local time. The UTC offset only influences how the time is represented in the constructed object: timePoint must always be a regular UTC time without any offset. If you pass a time of 1 January 2001, 00:00:00.000 UTC and a UTC offset of +1 hours, the time will decomposed to 2001-01-01 01:00:00 UTC+01:00, for example.
Returns
A string containing the time point

◆ toIsoU8String()

auto xentara::utils::chrono::toIsoU8String ( std::chrono::system_clock::time_point  timePoint,
const std::optional< std::chrono::minutes > &  utcOffset = std::nullopt 
) -> string::StaticU8String<maxDateTimeStringSize()>

Converts a time point to a string of type char8_t in ISO 8601/RFC 3999 format.

The returned string has the format YYYY-MM-DDThh:mm:ss.zzzzzzzzz±HH:MM. For a utcOffset of 0, ±HH:MM is replaced with the character “Z”.

Parameters
timePointThe time point
utcOffsetThe UTC offset to represent the time in, or std::nullopt to use local time. The UTC offset only influences how the time is represented in the constructed object: timePoint must always be a regular UTC time without any offset. If you pass a time of 1 January 2001, 00:00:00.000 UTC and a UTC offset of +1 hours, the time will decomposed to 2001-01-01 01:00:00 UTC+01:00, for example.
Returns
A string containing the time point

◆ toIsoWString()

auto xentara::utils::chrono::toIsoWString ( std::chrono::system_clock::time_point  timePoint,
const std::optional< std::chrono::minutes > &  utcOffset = std::nullopt 
) -> string::StaticWString<maxDateTimeStringSize()>

Converts a time point to a string of type wchar_t in ISO 8601/RFC 3999 format.

The returned string has the format YYYY-MM-DDThh:mm:ss.zzzzzzzzz±HH:MM. For a utcOffset of 0, ±HH:MM is replaced with the character “Z”.

Parameters
timePointThe time point
utcOffsetThe UTC offset to represent the time in, or std::nullopt to use local time. The UTC offset only influences how the time is represented in the constructed object: timePoint must always be a regular UTC time without any offset. If you pass a time of 1 January 2001, 00:00:00.000 UTC and a UTC offset of +1 hours, the time will decomposed to 2001-01-01 01:00:00 UTC+01:00, for example.
Returns
A string containing the time point

◆ toString()

auto xentara::utils::chrono::toString ( std::chrono::system_clock::time_point  timePoint,
const std::optional< std::chrono::minutes > &  utcOffset = std::nullopt 
) -> string::StaticString<maxDateTimeStringSize()>

Converts a time point to a string of type char

Parameters
timePointThe time point
utcOffsetThe UTC offset to represent the time in, or std::nullopt to use local time. The UTC offset only influences how the time is represented in the constructed object: timePoint must always be a regular UTC time without any offset. If you pass a time of 1 January 2001, 00:00:00.000 UTC and a UTC offset of +1 hours, the time will decomposed to 2001-01-01 01:00:00 UTC+01:00, for example.
Returns
A string containing the time point

◆ toTimeSpec() [1/2]

template<typename Rep , typename Period >
auto xentara::utils::chrono::toTimeSpec ( const std::chrono::duration< Rep, Period > &  duration) -> eh::expected<std::timespec, std::error_code>

Converts a duration to an std::timespec value.

◆ toTimeSpec() [2/2]

template<typename Clock , typename Duration >
auto xentara::utils::chrono::toTimeSpec ( const std::chrono::time_point< Clock, Duration > &  timePoint) -> eh::expected<std::timespec, std::error_code>

Converts a time point to an std::timespec value.

◆ toU16String()

auto xentara::utils::chrono::toU16String ( std::chrono::system_clock::time_point  timePoint,
const std::optional< std::chrono::minutes > &  utcOffset = std::nullopt 
) -> string::StaticU16String<maxDateTimeStringSize()>

Converts a time point to a string of type char16_t

Parameters
timePointThe time point
utcOffsetThe UTC offset to represent the time in, or std::nullopt to use local time. The UTC offset only influences how the time is represented in the constructed object: timePoint must always be a regular UTC time without any offset. If you pass a time of 1 January 2001, 00:00:00.000 UTC and a UTC offset of +1 hours, the time will decomposed to 2001-01-01 01:00:00 UTC+01:00, for example.
Returns
A string containing the time point

◆ toU32String()

auto xentara::utils::chrono::toU32String ( std::chrono::system_clock::time_point  timePoint,
const std::optional< std::chrono::minutes > &  utcOffset = std::nullopt 
) -> string::StaticU32String<maxDateTimeStringSize()>

Converts a number to a string of type char32_t

Parameters
timePointThe time point
utcOffsetThe UTC offset to represent the time in, or std::nullopt to use local time. The UTC offset only influences how the time is represented in the constructed object: timePoint must always be a regular UTC time without any offset. If you pass a time of 1 January 2001, 00:00:00.000 UTC and a UTC offset of +1 hours, the time will decomposed to 2001-01-01 01:00:00 UTC+01:00, for example.
Returns
A string containing the time point

◆ toU8String()

auto xentara::utils::chrono::toU8String ( std::chrono::system_clock::time_point  timePoint,
const std::optional< std::chrono::minutes > &  utcOffset = std::nullopt 
) -> string::StaticU8String<maxDateTimeStringSize()>

Converts a time point to a string of type char8_t

Parameters
timePointThe time point
utcOffsetThe UTC offset to represent the time in, or std::nullopt to use local time. The UTC offset only influences how the time is represented in the constructed object: timePoint must always be a regular UTC time without any offset. If you pass a time of 1 January 2001, 00:00:00.000 UTC and a UTC offset of +1 hours, the time will decomposed to 2001-01-01 01:00:00 UTC+01:00, for example.
Returns
A string containing the time point

◆ toWString()

auto xentara::utils::chrono::toWString ( std::chrono::system_clock::time_point  timePoint,
const std::optional< std::chrono::minutes > &  utcOffset = std::nullopt 
) -> string::StaticWString<maxDateTimeStringSize()>

Converts a time point to a string of type wchar_t

Parameters
timePointThe time point
utcOffsetThe UTC offset to represent the time in, or std::nullopt to use local time. The UTC offset only influences how the time is represented in the constructed object: timePoint must always be a regular UTC time without any offset. If you pass a time of 1 January 2001, 00:00:00.000 UTC and a UTC offset of +1 hours, the time will decomposed to 2001-01-01 01:00:00 UTC+01:00, for example.
Returns
A string containing the time point

Variable Documentation

◆ kReferenceTime

constexpr std::chrono::system_clock::time_point xentara::utils::chrono::kReferenceTime
constexpr

Standard reference time.

This time point can be used as referenece time for calculating phase offsets in function generators and timers. A phase offset of 0 should be aligned such that the wave form or timer is aligned with this time point.

The time point is January 1, 2001, 00:00:00 UTC.