]> git.stg.codes - stg.git/commitdiff
Ticket 37. formatTime() and readTime() methods define added.
authorElena Mamontova <helenh463@gmail.com>
Tue, 27 Sep 2016 13:05:39 +0000 (16:05 +0300)
committerElena Mamontova <helenh463@gmail.com>
Tue, 27 Sep 2016 13:05:39 +0000 (16:05 +0300)
stglibs/common.lib/common.cpp

index 8b62e68b0fad70adfd55e8c4c445c1b352c0b43a..2b10af26d59fc7f41c4dceb0c687d383570e5af5 100644 (file)
@@ -733,6 +733,35 @@ void SwapBytes(int64_t & value)
     value = temp;
 }
 //---------------------------------------------------------------------------
     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<int32_t>(strtol(str.c_str(), NULL, 10));
 int str2x(const std::string & str, int32_t & x)
 {
 x = static_cast<int32_t>(strtol(str.c_str(), NULL, 10));