X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/cd4be4497c82b49b78567956755727408fe34c1e..d8845c7819caac09b95c4cdf1e8d48cc1cb1b7a6:/stglibs/common.lib/common.cpp diff --git a/stglibs/common.lib/common.cpp b/stglibs/common.lib/common.cpp index 76a1b421..a4722a00 100644 --- a/stglibs/common.lib/common.cpp +++ b/stglibs/common.lib/common.cpp @@ -749,6 +749,38 @@ void SwapBytes(int64_t & value) value = temp; } //--------------------------------------------------------------------------- +std::string formatTime(time_t ts) +{ +char buf[32]; +struct tm brokenTime; + +brokenTime.tm_wday = 0; +brokenTime.tm_yday = 0; +brokenTime.tm_isdst = 0; + +gmtime_r(&ts, &brokenTime); + +strftime(buf, 32, "%Y-%m-%d %H:%M:%S", &brokenTime); + +return buf; +} +//--------------------------------------------------------------------------- +time_t readTime(const std::string & ts) +{ +if (ts == "0000-00-00 00:00:00") + return 0; + +struct tm brokenTime; + +brokenTime.tm_wday = 0; +brokenTime.tm_yday = 0; +brokenTime.tm_isdst = 0; + +stg_strptime(ts.c_str(), "%Y-%m-%d %H:%M:%S", &brokenTime); + +return stg_timegm(&brokenTime); +} +//--------------------------------------------------------------------------- int str2x(const std::string & str, int32_t & x) { x = static_cast(strtol(str.c_str(), NULL, 10));