summaryrefslogtreecommitdiff
path: root/louloulibs/utils/time.cpp
diff options
context:
space:
mode:
authorlouiz’ <louiz@louiz.org>2016-10-11 21:00:56 +0200
committerlouiz’ <louiz@louiz.org>2016-10-11 21:00:56 +0200
commitc54f28d29d5f1d7a2bb973609beffbe5ad56d422 (patch)
treeae678be64f6bb8559fadadf3caee2be883a8b35f /louloulibs/utils/time.cpp
parentdfc0793ef2fec12d2613b53b27f1a7f85dae2688 (diff)
downloadbiboumi-c54f28d29d5f1d7a2bb973609beffbe5ad56d422.tar.gz
biboumi-c54f28d29d5f1d7a2bb973609beffbe5ad56d422.tar.bz2
biboumi-c54f28d29d5f1d7a2bb973609beffbe5ad56d422.tar.xz
biboumi-c54f28d29d5f1d7a2bb973609beffbe5ad56d422.zip
Conditionally use strptime if we don’t have std::get_time
Diffstat (limited to 'louloulibs/utils/time.cpp')
-rw-r--r--louloulibs/utils/time.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/louloulibs/utils/time.cpp b/louloulibs/utils/time.cpp
index 7ad6663..afd6117 100644
--- a/louloulibs/utils/time.cpp
+++ b/louloulibs/utils/time.cpp
@@ -5,6 +5,8 @@
#include <iomanip>
#include <locale>
+#include "louloulibs.h"
+
namespace utils
{
std::string to_string(const std::time_t& timestamp)
@@ -20,6 +22,7 @@ std::time_t parse_datetime(const std::string& stamp)
{
static const char* format = "%Y-%m-%dT%H:%M:%S";
std::tm t = {};
+#ifdef HAS_GET_TIME
std::istringstream ss(stamp);
ss.imbue(std::locale("en_US.utf-8"));
@@ -27,6 +30,14 @@ std::time_t parse_datetime(const std::string& stamp)
ss >> std::get_time(&t, format) >> timezone;
if (ss.fail())
return -1;
+#else
+ /* Y - m - d T H : M : S */
+ constexpr std::size_t stamp_size_without_tz = 4 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2;
+ if (!strptime(stamp.data(), format, &t)) {
+ return -1;
+ }
+ const std::string timezone(stamp.data() + stamp_size_without_tz);
+#endif
if (timezone.empty())
return -1;