]> git.stg.codes - stg.git/blobdiff - stglibs/common.lib/common.cpp
Merge branch 'naffanya-dev'
[stg.git] / stglibs / common.lib / common.cpp
index 7ba78e1d8b311e149ea0b705ee3b0102a3af423f..c27a387d647949bbb8a27791c955bff6de10f3ee 100644 (file)
@@ -531,6 +531,22 @@ uint32_t inet_strington(const std::string & value)
     return result;
 }
 //-----------------------------------------------------------------------------
+std::string TimeToString(time_t time)
+{
+struct tm brokenTime;
+
+brokenTime.tm_wday = 0;
+brokenTime.tm_yday = 0;
+brokenTime.tm_isdst = 0;
+
+gmtime_r(&time, &brokenTime);
+
+char buf[32];
+strftime(buf, 32, "%Y-%m-%d %H:%M:%S", &brokenTime);
+
+return buf;
+}
+//-----------------------------------------------------------------------------
 int ParseTariffTimeStr(const char * str, int &h1, int &m1, int &h2, int &m2)
 {
 char hs1[10], ms1[10], hs2[10], ms2[10];
@@ -807,7 +823,8 @@ return unsigned2str(x, s);
 const std::string & x2str(double x, std::string & s)
 {
 char buf[256];
-s = snprintf(buf, sizeof(buf), "%f", x);
+snprintf(buf, sizeof(buf), "%f", x);
+s = buf;
 return s;
 }
 //---------------------------------------------------------------------------