diff options
author | Max Kellermann <mk@cm4all.com> | 2019-09-02 17:13:54 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2019-12-16 23:24:43 +0100 |
commit | 63c5d6601626285e32456eebb26ee898dd968f0c (patch) | |
tree | 8cc52ced99f5374125263e4c38da1ee1d45e2514 | |
parent | d09bd9178f30e9e8bb1034efec7d713f53e924df (diff) |
time/ISO8601: support omitting minutes
-rw-r--r-- | src/time/ISO8601.cxx | 2 | ||||
-rw-r--r-- | test/TestISO8601.cxx | 4 |
2 files changed, 6 insertions, 0 deletions
diff --git a/src/time/ISO8601.cxx b/src/time/ISO8601.cxx index f4d0d5d38..b92a0e743 100644 --- a/src/time/ISO8601.cxx +++ b/src/time/ISO8601.cxx @@ -138,6 +138,8 @@ ParseISO8601(const char *s) precision = std::chrono::seconds(1); else if ((end = strptime(s, "%H:%M", &tm)) != nullptr) precision = std::chrono::minutes(1); + else if ((end = strptime(s, "%H", &tm)) != nullptr) + precision = std::chrono::hours(1); else throw std::runtime_error("Failed to parse time of day"); diff --git a/test/TestISO8601.cxx b/test/TestISO8601.cxx index 6b2506cce..3305b47de 100644 --- a/test/TestISO8601.cxx +++ b/test/TestISO8601.cxx @@ -62,6 +62,10 @@ static constexpr struct { { "2019-02-04T16:46", 1549298760, std::chrono::minutes(1) }, { "2019-02-04T16:46Z", 1549298760, std::chrono::minutes(1) }, + /* without minutes */ + { "2019-02-04T16", 1549296000, std::chrono::hours(1) }, + { "2019-02-04T16Z", 1549296000, std::chrono::hours(1) }, + /* with time zone */ { "2019-02-04T16:46:41+02", 1549291601, std::chrono::seconds(1) }, { "2019-02-04T16:46:41+0200", 1549291601, std::chrono::seconds(1) }, |