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.
This commit is contained in:
Wladimir J. van der Laan
2014-05-08 18:01:10 +02:00
parent a60838d09a
commit 3e8ac6af9a
4 changed files with 15 additions and 20 deletions

View File

@@ -14,6 +14,8 @@
#include <stdarg.h>
#include <boost/date_time/posix_time/posix_time.hpp>
#ifndef WIN32
// for posix_fallocate
#ifdef __linux_
@@ -1400,3 +1402,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();
}