From 548e4ad473e7be22f971184312cc5ce9b8fe56b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Tue, 11 Oct 2016 00:18:48 +0200 Subject: Parse the timezone myself, instead of using the broken strptime See https://lab.louiz.org/louiz/biboumi/issues/3215 https://github.com/andikleen/glibc/blob/master/time/strptime_l.c#L746-L747 for why strptime() sucks We use std::get_time now, to parse the date and time. And we parse the timezone by hand. fix #3215 --- tests/utils.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'tests/utils.cpp') diff --git a/tests/utils.cpp b/tests/utils.cpp index a18fc81..48951da 100644 --- a/tests/utils.cpp +++ b/tests/utils.cpp @@ -124,7 +124,19 @@ TEST_CASE("time_to_string") TEST_CASE("parse_datetime") { - CHECK(utils::parse_datetime("1970-01-01T00:00:00z") == 0); + CHECK(utils::parse_datetime("1970-01-01T00:00:00Z") == 0); + + const int twenty_three_hours = 82800; + CHECK(utils::parse_datetime("1970-01-01T23:00:12Z") == twenty_three_hours + 12); + CHECK(utils::parse_datetime("1970-01-01T23:00:12Z") == utils::parse_datetime("1970-01-01T23:00:12+00:00")); + CHECK(utils::parse_datetime("1970-01-01T23:00:12Z") == utils::parse_datetime("1970-01-01T23:00:12-00:00")); + CHECK(utils::parse_datetime("1970-01-02T00:00:12Z") == utils::parse_datetime("1970-01-01T23:00:12-01:00")); + CHECK(utils::parse_datetime("1970-01-02T00:00:12Z") == utils::parse_datetime("1970-01-02T01:00:12+01:00")); + CHECK(utils::parse_datetime("2016-08-29T14:29:29Z") == 1472480969); + CHECK(utils::parse_datetime("blah") == -1); -} \ No newline at end of file + CHECK(utils::parse_datetime("1970-01-02T00:00:12B") == -1); + CHECK(utils::parse_datetime("1970-01-02T00:00:12*00:00") == -1); + CHECK(utils::parse_datetime("1970-01-02T00:00:12+0000") == -1); +} -- cgit v1.2.3