summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorlouiz’ <louiz@louiz.org>2017-05-23 18:09:00 +0200
committerlouiz’ <louiz@louiz.org>2017-05-23 11:46:14 +0200
commit19ed2e7f5f182570c894a0a89d154f973fb01906 (patch)
treebeddd8d4aa0c87296d53c12d093882325108523f /src/utils
parentd1dc7882797ae40c818d0cf397580aefad263296 (diff)
downloadbiboumi-19ed2e7f5f182570c894a0a89d154f973fb01906.tar.gz
biboumi-19ed2e7f5f182570c894a0a89d154f973fb01906.tar.bz2
biboumi-19ed2e7f5f182570c894a0a89d154f973fb01906.tar.xz
biboumi-19ed2e7f5f182570c894a0a89d154f973fb01906.zip
Fix the datetime parsing to handle optional fractions of seconds
fix #3266
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/time.cpp18
1 files changed, 14 insertions, 4 deletions
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;