From e5b392ece8c90605b86d0d93f0ca6989048bc1c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Mon, 3 Oct 2016 23:30:20 +0200 Subject: [PATCH] Fix parse_datetime by always using a 'z' as the timezone MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Because some plateform accept Z and z, but some only accept z… --- louloulibs/utils/time.cpp | 3 ++- tests/utils.cpp | 7 ++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/louloulibs/utils/time.cpp b/louloulibs/utils/time.cpp index bc8b3f8..abf0a84 100644 --- a/louloulibs/utils/time.cpp +++ b/louloulibs/utils/time.cpp @@ -14,8 +14,9 @@ std::string to_string(const std::time_t& timestamp) std::time_t parse_datetime(const std::string& stamp) { + auto stamp2 = stamp.substr(0, stamp.size() - 1) + "z"; struct tm tm; - if (!::strptime(stamp.data(), "%FT%T%Z", &tm)) + if (!::strptime(stamp2.data(), "%FT%T%Z", &tm)) return -1; auto res = ::timegm(&tm); return res; diff --git a/tests/utils.cpp b/tests/utils.cpp index 5913f8d..a18fc81 100644 --- a/tests/utils.cpp +++ b/tests/utils.cpp @@ -124,10 +124,7 @@ TEST_CASE("time_to_string") TEST_CASE("parse_datetime") { - const auto time = utils::parse_datetime("1970-01-01T00:00:00Z"); - CHECK(time == 0); - CHECK(utils::parse_datetime("2016-08-29T14:29:28Z") == 1472480968); - CHECK(utils::parse_datetime("2016-08-29T14:29:28UT") == 1472480968); - CHECK(utils::parse_datetime("2016-08-29T14:29:28GMT") == 1472480968); + CHECK(utils::parse_datetime("1970-01-01T00:00:00z") == 0); + CHECK(utils::parse_datetime("2016-08-29T14:29:29Z") == 1472480969); CHECK(utils::parse_datetime("blah") == -1); } \ No newline at end of file -- 2.45.2