summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2019-08-19 22:30:31 +0200
committerMax Kellermann <max@musicpd.org>2019-12-16 23:24:43 +0100
commitba4cd47fd8cb853f1b4e04c7dcb5221bb0c05150 (patch)
tree04e1332b4c63472b59636af05eaed5810c0c41b9 /src
parentbbe403f141f8d37cc3776d72891ffe4523e59b26 (diff)
time/ISO8601: allow omitting the time of day
Diffstat (limited to 'src')
-rw-r--r--src/time/ISO8601.cxx26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/time/ISO8601.cxx b/src/time/ISO8601.cxx
index a7435630a..4811813fb 100644
--- a/src/time/ISO8601.cxx
+++ b/src/time/ISO8601.cxx
@@ -70,14 +70,32 @@ ParseISO8601(const char *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");
- std::chrono::system_clock::duration precision = std::chrono::seconds(1);
+ /* parse the date */
+ const char *end = strptime(s, "%F", &tm);
+ if (end == nullptr)
+ throw std::runtime_error("Failed to parse date");
+
+ s = end;
+
+ std::chrono::system_clock::duration precision = std::chrono::hours(24);
+
+ /* parse the time of day */
+ if (*s == 'T') {
+ ++s;
+ end = strptime(s, "%TZ", &tm);
+ if (end == nullptr)
+ throw std::runtime_error("Failed to parse time of day");
+
+ s = end;
+ precision = std::chrono::seconds(1);
+ }
auto tp = TimeGm(tm);
+ if (*s != 0)
+ throw std::runtime_error("Garbage at end of time stamp");
+
return std::make_pair(tp, precision);
#endif /* !_WIN32 */
}