aboutsummaryrefslogtreecommitdiff
path: root/src/util.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2014-05-08 18:01:10 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2014-05-23 16:04:02 +0200
commita62649723bab311107468038e41bf76410990423 (patch)
treecc81cddea34380368b2fb99c005f3dd7ed36fdea /src/util.cpp
parente0036e9f0e0240541bf5a4ebcd8087be99739e71 (diff)
downloadbitcoin-a62649723bab311107468038e41bf76410990423.tar.xz
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 <laanwj@gmail.com> 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 8af47643cb..b8036a3872 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -14,6 +14,8 @@
#include <stdarg.h>
+#include <boost/date_time/posix_time/posix_time.hpp>
+
#ifndef WIN32
// for posix_fallocate
#ifdef __linux_
@@ -1423,3 +1425,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();
+}