diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-09-19 19:55:14 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-09-19 19:55:14 +0100 |
commit | b16d51e7d108c50e960d4598cb7cd47854c76f3e (patch) | |
tree | 8b3ef10ee888eaaf52b46f343fa6b02968a623e7 /lib/chronology.cpp | |
parent | Add new mathematical constants to lib (diff) | |
download | ilt-b16d51e7d108c50e960d4598cb7cd47854c76f3e.tar.bz2 ilt-b16d51e7d108c50e960d4598cb7cd47854c76f3e.tar.xz ilt-b16d51e7d108c50e960d4598cb7cd47854c76f3e.zip |
Add helper to quickly parse an ISO date/time
Diffstat (limited to 'lib/chronology.cpp')
-rw-r--r-- | lib/chronology.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/chronology.cpp b/lib/chronology.cpp new file mode 100644 index 0000000..8707bba --- /dev/null +++ b/lib/chronology.cpp @@ -0,0 +1,12 @@ +#include "chronology.h" + +time_t +operator""_time_t(const char * iso, size_t) +{ + struct tm tm {}; + + if (const auto end = strptime(iso, "%FT%T", &tm); !end || *end) { + throw std::invalid_argument("Invalid date"); + } + return mktime(&tm); +} |