From 4859ea468f37dcfe6cac2a70b6867146911b673e Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 19 Aug 2019 22:26:43 +0200 Subject: [PATCH] time/ISO8601: implement with strptime(), without ParseTimePoint() Prepare for adding more flexible parsing. --- src/time/ISO8601.cxx | 20 ++++++++++++++++++-- 1 file 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 + +#include + 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 */ }