diff --git a/contrib/epee/include/time_helper.h b/contrib/epee/include/time_helper.h index bfbcd5a23..5d2c43c78 100644 --- a/contrib/epee/include/time_helper.h +++ b/contrib/epee/include/time_helper.h @@ -28,46 +28,48 @@ #pragma once -#include -#include #include +#include #include -#include - -#include "pragma_comp_defs.h" +#include namespace epee { namespace misc_utils { + inline bool get_gmt_time(time_t t, struct tm &tm) + { +#ifdef _WIN32 + return gmtime_s(&tm, &t); +#else + return gmtime_r(&t, &tm); +#endif + } + inline std::string get_internet_time_str(const time_t& time_) { char tmpbuf[200] = {0}; - tm* pt = NULL; -PRAGMA_WARNING_PUSH -PRAGMA_WARNING_DISABLE_VS(4996) - pt = gmtime(&time_); -PRAGMA_WARNING_POP - strftime( tmpbuf, 199, "%a, %d %b %Y %H:%M:%S GMT", pt ); + struct tm pt; + get_gmt_time(time_, pt); + strftime( tmpbuf, 199, "%a, %d %b %Y %H:%M:%S GMT", &pt ); return tmpbuf; } inline std::string get_time_interval_string(const time_t& time_) { - std::string res; time_t tail = time_; -PRAGMA_WARNING_PUSH -PRAGMA_WARNING_DISABLE_VS(4244) - int days = tail/(60*60*24); + const int days = (int) (tail/(60*60*24)); tail = tail%(60*60*24); - int hours = tail/(60*60); + const int hours = (int) (tail/(60*60)); tail = tail%(60*60); - int minutes = tail/(60); + const int minutes = (int) (tail/(60)); tail = tail%(60); - int seconds = tail; -PRAGMA_WARNING_POP - res = std::string() + "d" + boost::lexical_cast(days) + ".h" + boost::lexical_cast(hours) + ".m" + boost::lexical_cast(minutes) + ".s" + boost::lexical_cast(seconds); - return res; + const int seconds = (int) tail; + + char tmpbuf[64] = {0}; + snprintf(tmpbuf, sizeof(tmpbuf) - 1, "d%d.h%d.m%d.s%d", days, hours, minutes, seconds); + + return tmpbuf; } inline uint64_t get_ns_count() @@ -81,14 +83,5 @@ PRAGMA_WARNING_POP { return get_ns_count() / 1000000; } - - inline bool get_gmt_time(time_t t, struct tm &tm) - { -#ifdef _WIN32 - return gmtime_s(&tm, &t); -#else - return gmtime_r(&t, &tm); -#endif - } } } \ No newline at end of file diff --git a/tests/unit_tests/epee_utils.cpp b/tests/unit_tests/epee_utils.cpp index b83a809b7..73f1b3774 100644 --- a/tests/unit_tests/epee_utils.cpp +++ b/tests/unit_tests/epee_utils.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include