Commit b7744be2 authored by Max Kellermann's avatar Max Kellermann

song/Filter: try ParseISO8601() first

Prepare for allowing ISO8601 time stamps without delimiters, such as 20191216, and prevent them from being interpreted as numeric UNIX time stamps.
parent 63c5d660
...@@ -113,14 +113,19 @@ ParseTimeStamp(const char *s) ...@@ -113,14 +113,19 @@ ParseTimeStamp(const char *s)
{ {
assert(s != nullptr); assert(s != nullptr);
char *endptr; try {
unsigned long long value = strtoull(s, &endptr, 10); /* try ISO 8601 */
if (*endptr == 0 && endptr > s) return ParseISO8601(s).first;
/* it's an integral UNIX time stamp */ } catch (...) {
return std::chrono::system_clock::from_time_t((time_t)value); char *endptr;
unsigned long long value = strtoull(s, &endptr, 10);
/* try ISO 8601 */ if (*endptr == 0 && endptr > s)
return ParseISO8601(s).first; /* it's an integral UNIX time stamp */
return std::chrono::system_clock::from_time_t((time_t)value);
/* rethrow the ParseISO8601() error */
throw;
}
} }
static constexpr bool static constexpr bool
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment