aboutsummaryrefslogtreecommitdiff
path: root/src/util.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <[email protected]>2014-05-08 18:01:10 +0200
committerlangerhans <[email protected]>2014-07-09 17:12:18 +0200
commitab25bec2ead54bfa2287fc8a9b364a00efe268f8 (patch)
treef665d6ea8541d75190315029f0b0c472ea467415 /src/util.cpp
parentReplace non-threadsafe strerror (diff)
downloaddiscoin-ab25bec2ead54bfa2287fc8a9b364a00efe268f8.tar.xz
discoin-ab25bec2ead54bfa2287fc8a9b364a00efe268f8.zip
Replace non-threadsafe gmtime and setlocale
Make DateTimeStrFormat use boost::posix_time. Also re-enable the util_DateTimeStrFormat tests, as they are no longer platform specific. Rebased-By: Wladimir J. van der Laan <[email protected]> Rebased-From: 3e8ac6a
Diffstat (limited to 'src/util.cpp')
-rw-r--r--src/util.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/util.cpp b/src/util.cpp
index 45844d881..d1f76f6a5 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -16,6 +16,8 @@
#include <stdarg.h>
+#include <boost/date_time/posix_time/posix_time.hpp>
+
#ifndef WIN32
// for posix_fallocate
#ifdef __linux_
@@ -1444,3 +1446,13 @@ void SetupEnvironment()
}
#endif
}
+
+std::string DateTimeStrFormat(const char* pszFormat, int64_t nTime)
+{
+ // std::locale takes ownership of the pointer
+ std::locale loc(std::locale::classic(), new boost::posix_time::time_facet(pszFormat));
+ std::stringstream ss;
+ ss.imbue(loc);
+ ss << boost::posix_time::from_time_t(nTime);
+ return ss.str();
+}