summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2019-12-16 23:28:47 +0100
committerMax Kellermann <max@musicpd.org>2019-12-16 23:31:29 +0100
commitb7744be20806a9cc3697f0806eb452012e7180be (patch)
tree4eeb1c01c6eb25c332ff3de0999ec7164e676521
parent63c5d6601626285e32456eebb26ee898dd968f0c (diff)
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.
-rw-r--r--src/song/Filter.cxx21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/song/Filter.cxx b/src/song/Filter.cxx
index 9c0583845..e369c8c93 100644
--- a/src/song/Filter.cxx
+++ b/src/song/Filter.cxx
@@ -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 ISO 8601 */
- return ParseISO8601(s).first;
+ 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);
+
+ /* rethrow the ParseISO8601() error */
+ throw;
+ }
}
static constexpr bool