From: Elena Mamontova Date: Tue, 27 Sep 2016 13:05:39 +0000 (+0300) Subject: Ticket 37. formatTime() and readTime() methods define added. X-Git-Tag: 2.409~70 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/7320b695badad72772466e1cc49bb28c20b25ccc Ticket 37. formatTime() and readTime() methods define added. --- diff --git a/stglibs/common.lib/common.cpp b/stglibs/common.lib/common.cpp index 8b62e68b..2b10af26 100644 --- a/stglibs/common.lib/common.cpp +++ b/stglibs/common.lib/common.cpp @@ -733,6 +733,35 @@ 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) +{ +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));