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.
This commit is contained in:
Max Kellermann 2019-12-16 23:28:47 +01:00
parent 63c5d66016
commit b7744be208
1 changed files with 12 additions and 7 deletions

View File

@ -113,14 +113,19 @@ ParseTimeStamp(const char *s)
{
assert(s != nullptr);
char *endptr;
unsigned long long value = strtoull(s, &endptr, 10);
if (*endptr == 0 && endptr > s)
/* it's an integral UNIX time stamp */
return std::chrono::system_clock::from_time_t((time_t)value);
try {
/* try ISO 8601 */
return ParseISO8601(s).first;
} catch (...) {
char *endptr;
unsigned long long value = strtoull(s, &endptr, 10);
if (*endptr == 0 && endptr > s)
/* it's an integral UNIX time stamp */
return std::chrono::system_clock::from_time_t((time_t)value);
/* try ISO 8601 */
return ParseISO8601(s).first;
/* rethrow the ParseISO8601() error */
throw;
}
}
static constexpr bool