aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Warta <[email protected]>2015-07-20 21:26:23 +0200
committerSimon Warta <[email protected]>2015-07-27 13:04:40 +0200
commit2e9109c80eb8fbbb94893827bf9753a735917735 (patch)
tree24c62741fb4a279756412dc0feff62f392ee726e
parentd4be8c6f64420bcc0f55ce6ae18bf9363bd46481 (diff)
Add boost implementation of timegm()
-rw-r--r--src/lib/utils/calendar.cpp36
-rw-r--r--src/lib/vendor/boost/info.txt1
2 files changed, 37 insertions, 0 deletions
diff --git a/src/lib/utils/calendar.cpp b/src/lib/utils/calendar.cpp
index 966c97730..f071a7328 100644
--- a/src/lib/utils/calendar.cpp
+++ b/src/lib/utils/calendar.cpp
@@ -13,6 +13,10 @@
#include <iomanip>
#include <mutex>
+#if defined(BOTAN_HAS_BOOST_DATETIME)
+#include <boost/date_time/posix_time/posix_time_types.hpp>
+#endif
+
namespace Botan {
namespace {
@@ -37,6 +41,34 @@ std::tm do_gmtime(std::time_t time_val)
#if !defined(BOTAN_TARGET_OS_HAS_TIMEGM) && !defined(BOTAN_TARGET_OS_HAS_MKGMTIME)
+#if defined(BOTAN_HAS_BOOST_DATETIME)
+
+std::time_t boost_timegm(std::tm *tm)
+ {
+ const int sec = tm->tm_sec;
+ const int min = tm->tm_min;
+ const int hour = tm->tm_hour;
+ const int day = tm->tm_mday;
+ const int mon = tm->tm_mon + 1;
+ const int year = tm->tm_year + 1900;
+
+ std::time_t out;
+
+ {
+ using namespace boost::posix_time;
+ using namespace boost::gregorian;
+ const auto epoch = ptime(date(1970, 01, 01));
+ const auto time = ptime(date(year, mon, day),
+ hours(hour) + minutes(min) + seconds(sec));
+ const time_duration diff(time - epoch);
+ out = diff.ticks() / diff.ticks_per_second();
+ }
+
+ return out;
+ }
+
+#else
+
#pragma message "Caution! A fallback version of timegm() is used which is not thread-safe"
std::mutex ENV_TZ;
@@ -75,6 +107,8 @@ std::time_t fallback_timegm(std::tm *tm)
return out;
}
+#endif // BOTAN_HAS_BOOST_DATETIME
+
#endif
}
@@ -107,6 +141,8 @@ std::chrono::system_clock::time_point calendar_point::to_std_timepoint()
#elif defined(BOTAN_TARGET_OS_HAS_MKGMTIME)
// http://stackoverflow.com/questions/16647819/timegm-cross-platform
std::time_t (&botan_timegm)(std::tm *tm) = _mkgmtime;
+ #elif defined(BOTAN_HAS_BOOST_DATETIME)
+ std::time_t (&botan_timegm)(std::tm *tm) = boost_timegm;
#else
std::time_t (&botan_timegm)(std::tm *tm) = fallback_timegm;
#endif
diff --git a/src/lib/vendor/boost/info.txt b/src/lib/vendor/boost/info.txt
index c335dcd74..8748c0bf1 100644
--- a/src/lib/vendor/boost/info.txt
+++ b/src/lib/vendor/boost/info.txt
@@ -1,5 +1,6 @@
define BOOST_FILESYSTEM 20131228
define BOOST_ASIO 20131228
+define BOOST_DATETIME 20150720
load_on vendor