diff options
author | Max Kellermann <max@musicpd.org> | 2019-08-19 22:26:43 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2019-12-16 23:24:43 +0100 |
commit | 4859ea468f37dcfe6cac2a70b6867146911b673e (patch) | |
tree | ab501305a8b4e385294c3edfd08abf9f162ccc1e /src/time | |
parent | 2a8830db70e2c5513803b52ad4a95092f8ec17f7 (diff) |
time/ISO8601: implement with strptime(), without ParseTimePoint()
Prepare for adding more flexible parsing.
Diffstat (limited to 'src/time')
-rw-r--r-- | src/time/ISO8601.cxx | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/time/ISO8601.cxx b/src/time/ISO8601.cxx index fb6d32899..3aaa40eab 100644 --- a/src/time/ISO8601.cxx +++ b/src/time/ISO8601.cxx @@ -32,9 +32,12 @@ #include "ISO8601.hxx" #include "Convert.hxx" -#include "Parser.hxx" #include "util/StringBuffer.hxx" +#include <stdexcept> + +#include <assert.h> + StringBuffer<64> FormatISO8601(const struct tm &tm) noexcept { @@ -58,5 +61,18 @@ FormatISO8601(std::chrono::system_clock::time_point tp) std::chrono::system_clock::time_point ParseISO8601(const char *s) { - return ParseTimePoint(s, "%FT%TZ"); + assert(s != nullptr); + +#ifdef _WIN32 + /* TODO: emulate strptime()? */ + (void)s; + throw std::runtime_error("Time parsing not implemented on Windows"); +#else + struct tm tm{}; + const char *end = strptime(s, "%FT%TZ", &tm); + if (end == nullptr || *end != 0) + throw std::runtime_error("Failed to parse time stamp"); + + return TimeGm(tm); +#endif /* !_WIN32 */ } |