summaryrefslogtreecommitdiff
path: root/louloulibs/utils/time.cpp
diff options
context:
space:
mode:
authorlouiz’ <louiz@louiz.org>2017-03-14 21:45:23 +0100
committerlouiz’ <louiz@louiz.org>2017-03-14 21:45:23 +0100
commit0ab40dc1ab4e689921da54080b135e1d22b1c586 (patch)
tree238ac477aa6b29a8d1e187a8d97ecbcbbbc663ef /louloulibs/utils/time.cpp
parent2d3806152e854ace7533fc3ad34d4ac1c44e9687 (diff)
downloadbiboumi-0ab40dc1ab4e689921da54080b135e1d22b1c586.tar.gz
biboumi-0ab40dc1ab4e689921da54080b135e1d22b1c586.tar.bz2
biboumi-0ab40dc1ab4e689921da54080b135e1d22b1c586.tar.xz
biboumi-0ab40dc1ab4e689921da54080b135e1d22b1c586.zip
Refactoring louloulibs and cmake
Use OBJECT libraries Remove the louloulibs directory Write FOUND variables in the cache
Diffstat (limited to 'louloulibs/utils/time.cpp')
-rw-r--r--louloulibs/utils/time.cpp70
1 files changed, 0 insertions, 70 deletions
diff --git a/louloulibs/utils/time.cpp b/louloulibs/utils/time.cpp
deleted file mode 100644
index e9f3943..0000000
--- a/louloulibs/utils/time.cpp
+++ /dev/null
@@ -1,70 +0,0 @@
-#include <utils/time.hpp>
-#include <time.h>
-
-#include <sstream>
-#include <iomanip>
-#include <locale>
-
-#include "louloulibs.h"
-
-namespace utils
-{
-std::string to_string(const std::time_t& timestamp)
-{
- constexpr std::size_t stamp_size = 21;
- char date_buf[stamp_size];
- if (std::strftime(date_buf, stamp_size, "%FT%TZ", std::gmtime(&timestamp)) != stamp_size - 1)
- return "";
- return {std::begin(date_buf), std::end(date_buf) - 1};
-}
-
-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("C"));
-
- std::string timezone;
- 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;
-
- if (timezone.compare(0, 1, "Z") != 0)
- {
- std::stringstream tz_ss;
- tz_ss << timezone;
- int multiplier = -1;
- char prefix;
- int hours;
- char sep;
- int minutes;
- tz_ss >> prefix >> hours >> sep >> minutes;
- if (tz_ss.fail())
- return -1;
- if (prefix == '-')
- multiplier = +1;
- else if (prefix != '+')
- return -1;
-
- t.tm_hour += multiplier * hours;
- t.tm_min += multiplier * minutes;
- }
- return ::timegm(&t);
-}
-
-}
-
-