From 19ed2e7f5f182570c894a0a89d154f973fb01906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Tue, 23 May 2017 18:09:00 +0200 Subject: Fix the datetime parsing to handle optional fractions of seconds fix #3266 --- src/utils/time.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/utils') diff --git a/src/utils/time.cpp b/src/utils/time.cpp index 88b3de3..bc2c18d 100644 --- a/src/utils/time.cpp +++ b/src/utils/time.cpp @@ -26,8 +26,8 @@ std::time_t parse_datetime(const std::string& stamp) std::istringstream ss(stamp); ss.imbue(std::locale("C")); - std::string timezone; - ss >> std::get_time(&t, format) >> timezone; + std::string remainings; + ss >> std::get_time(&t, format) >> remainings; if (ss.fail()) return -1; #else @@ -36,12 +36,22 @@ std::time_t parse_datetime(const std::string& stamp) if (!strptime(stamp.data(), format, &t)) { return -1; } - const std::string timezone(stamp.data() + stamp_size_without_tz); + const std::string remainings(stamp.data() + stamp_size_without_tz); #endif - if (timezone.empty()) + if (remainings.empty()) return -1; + std::string timezone; + // Skip optional fractions of seconds + if (remainings[0] == '.') + { + const auto pos = remainings.find_first_not_of(".0123456789"); + timezone = remainings.substr(pos); + } + else + timezone = std::move(remainings); + if (timezone.compare(0, 1, "Z") != 0) { std::stringstream tz_ss; -- cgit v1.2.3