Add parse_datetime
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include <utils/time.hpp>
|
||||
#include <time.h>
|
||||
|
||||
namespace utils
|
||||
{
|
||||
@@ -10,4 +11,14 @@ std::string to_string(const std::time_t& timestamp)
|
||||
return "";
|
||||
return {std::begin(date_buf), std::end(date_buf) - 1};
|
||||
}
|
||||
|
||||
std::time_t parse_datetime(const std::string& stamp)
|
||||
{
|
||||
struct tm tm;
|
||||
if (!::strptime(stamp.data(), "%FT%T%z", &tm))
|
||||
return -1;
|
||||
auto res = ::timegm(&tm);
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user