diff options
| author | Wladimir J. van der Laan <[email protected]> | 2014-05-08 18:01:10 +0200 |
|---|---|---|
| committer | langerhans <[email protected]> | 2014-07-09 17:12:18 +0200 |
| commit | ab25bec2ead54bfa2287fc8a9b364a00efe268f8 (patch) | |
| tree | f665d6ea8541d75190315029f0b0c472ea467415 /src/util.cpp | |
| parent | Replace non-threadsafe strerror (diff) | |
| download | discoin-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.cpp | 12 |
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(); +} |