scn::datetime_components struct

An alternative to std::tm, with support for subsecond precision, and clear distinction between the value 0 and an unset field.

Public functions

auto to_tm() const →  std::tm

Public variables

std::optional<double> subsec
Fractions of a second, [0.0-1.0)
std::optional<signed char> sec
Seconds, [0-60].
std::optional<signed char> min
Minutes, [0-59].
std::optional<signed char> hour
Hours, [0-23].
std::optional<signed char> mday
Day (in a month), [1-31].
std::optional<month> mon
Month (strongly typed)
std::optional<int> year
std::optional<weekday> wday
Day of week (strongly typed)
std::optional<short> yday
Day of year (offset from Jan 1st), [0-365].
std::optional<std::chrono::minutes> tz_offset
Timezone offset from UTC.
std::optional<std::string> tz_name
Timezone name.

Function documentation

std::tm scn::datetime_components::to_tm() const

Returns a std::tm object corresponding to *this. Unset fields have a value of 0, with tm_isdst having a value of -1. The fields subsec and tz_name are discarded. tz_offset is set to tm_gmtoff, if it's available.

Variable documentation

std::optional<int> scn::datetime_components::year

Year, without an offset Note, std::tm stores years since 1900