diff options
author | louiz’ <louiz@louiz.org> | 2016-08-31 01:58:13 +0200 |
---|---|---|
committer | louiz’ <louiz@louiz.org> | 2016-08-31 01:58:13 +0200 |
commit | 1140db3b88bb70cbcab044efa729707bd5a442f6 (patch) | |
tree | 37a1a5375533647f2cf66c0f027c8a1674536b27 /louloulibs | |
parent | 2a4905df0153c47656555a21f3d57bbad6f3ffe1 (diff) | |
download | biboumi-1140db3b88bb70cbcab044efa729707bd5a442f6.tar.gz biboumi-1140db3b88bb70cbcab044efa729707bd5a442f6.tar.bz2 biboumi-1140db3b88bb70cbcab044efa729707bd5a442f6.tar.xz biboumi-1140db3b88bb70cbcab044efa729707bd5a442f6.zip |
Add parse_datetime
Diffstat (limited to 'louloulibs')
-rw-r--r-- | louloulibs/utils/time.cpp | 11 | ||||
-rw-r--r-- | louloulibs/utils/time.hpp | 1 |
2 files changed, 12 insertions, 0 deletions
diff --git a/louloulibs/utils/time.cpp b/louloulibs/utils/time.cpp index b85d764..305b2ad 100644 --- a/louloulibs/utils/time.cpp +++ b/louloulibs/utils/time.cpp @@ -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; +} + }
\ No newline at end of file diff --git a/louloulibs/utils/time.hpp b/louloulibs/utils/time.hpp index dff1250..c71cd9c 100644 --- a/louloulibs/utils/time.hpp +++ b/louloulibs/utils/time.hpp @@ -6,4 +6,5 @@ namespace utils { std::string to_string(const std::time_t& timestamp); +std::time_t parse_datetime(const std::string& stamp); }
\ No newline at end of file |