aboutsummaryrefslogtreecommitdiff
path: root/src/utiltime.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2018-04-12 22:31:15 -0700
committerPieter Wuille <pieter.wuille@gmail.com>2018-04-13 01:36:53 -0700
commit152701568159915828613fa131e94e21337c0c2d (patch)
tree5b72f64924e1b377c9b5fd71de49439e340e7738 /src/utiltime.cpp
parent5df84de583c900e00fef63bedaef32786f205a33 (diff)
Avoid std::locale/imbue in DateTimeStrFormat
Diffstat (limited to 'src/utiltime.cpp')
-rw-r--r--src/utiltime.cpp29
1 files changed, 14 insertions, 15 deletions
diff --git a/src/utiltime.cpp b/src/utiltime.cpp
index 8a861039b3..34800c7b6d 100644
--- a/src/utiltime.cpp
+++ b/src/utiltime.cpp
@@ -10,9 +10,10 @@
#include <utiltime.h>
#include <atomic>
-
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/thread.hpp>
+#include <ctime>
+#include <tinyformat.h>
static std::atomic<int64_t> nMockTime(0); //!< For unit testing
@@ -75,25 +76,23 @@ void MilliSleep(int64_t n)
#endif
}
-std::string DateTimeStrFormat(const char* pszFormat, int64_t nTime)
-{
- static std::locale classic(std::locale::classic());
- // std::locale takes ownership of the pointer
- std::locale loc(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();
-}
-
std::string FormatISO8601DateTime(int64_t nTime) {
- return DateTimeStrFormat("%Y-%m-%dT%H:%M:%SZ", nTime);
+ struct tm ts;
+ time_t time_val = nTime;
+ gmtime_r(&time_val, &ts);
+ return strprintf("%04i-%02i-%02iT%02i:%02i:%02iZ", ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec);
}
std::string FormatISO8601Date(int64_t nTime) {
- return DateTimeStrFormat("%Y-%m-%d", nTime);
+ struct tm ts;
+ time_t time_val = nTime;
+ gmtime_r(&time_val, &ts);
+ return strprintf("%04i-%02i-%02i", ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday);
}
std::string FormatISO8601Time(int64_t nTime) {
- return DateTimeStrFormat("%H:%M:%SZ", nTime);
+ struct tm ts;
+ time_t time_val = nTime;
+ gmtime_r(&time_val, &ts);
+ return strprintf("%02i:%02i:%02iZ", ts.tm_hour, ts.tm_min, ts.tm_sec);
}