Fix the parse_datetime by using %Z instead of %z
If anybody knows why fedora accepts both, but it only works with %z on debian, please tell me.
This commit is contained in:
@@ -15,10 +15,10 @@ std::string to_string(const std::time_t& timestamp)
|
|||||||
std::time_t parse_datetime(const std::string& stamp)
|
std::time_t parse_datetime(const std::string& stamp)
|
||||||
{
|
{
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
if (!::strptime(stamp.data(), "%FT%T%z", &tm))
|
if (!::strptime(stamp.data(), "%FT%T%Z", &tm))
|
||||||
return -1;
|
return -1;
|
||||||
auto res = ::timegm(&tm);
|
auto res = ::timegm(&tm);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,5 +127,7 @@ TEST_CASE("parse_datetime")
|
|||||||
const auto time = utils::parse_datetime("1970-01-01T00:00:00Z");
|
const auto time = utils::parse_datetime("1970-01-01T00:00:00Z");
|
||||||
CHECK(time == 0);
|
CHECK(time == 0);
|
||||||
CHECK(utils::parse_datetime("2016-08-29T14:29:28Z") == 1472480968);
|
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("blah") == -1);
|
CHECK(utils::parse_datetime("blah") == -1);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user