X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/1c9c1588c5d07cea181632fc95b0046b6b04758e..be4b0c4a82a46b9f69d4ee403fc397dc197626dc:/stglibs/common.lib/common.cpp?ds=sidebyside diff --git a/stglibs/common.lib/common.cpp b/stglibs/common.lib/common.cpp index d0ff074c..fc7c35ce 100644 --- a/stglibs/common.lib/common.cpp +++ b/stglibs/common.lib/common.cpp @@ -48,6 +48,7 @@ #include #include + #include #include #include @@ -344,20 +345,6 @@ for (size_t i = 0; i < src.length() / 2; i++) } } //--------------------------------------------------------------------------- -std::string Encode12str(const std::string & src) -{ -std::string res; -Encode12str(res, src); -return res; -} -//--------------------------------------------------------------------------- -std::string Decode21str(const std::string & src) -{ -std::string res; -Decode21str(res, src); -return res; -} -//--------------------------------------------------------------------------- void Encode12(char * dst, const char * src, size_t srcLen) { for (size_t i = 0; i <= srcLen; i++) @@ -527,22 +514,6 @@ 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]; @@ -762,6 +733,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)); @@ -781,6 +784,11 @@ if (errno == ERANGE) return 0; } +//--------------------------------------------------------------------------- +int str2x(const std::string & str, double & x) +{ +return strtodouble2(str.c_str(), x); +} #ifndef WIN32 //--------------------------------------------------------------------------- int str2x(const std::string & str, int64_t & x) @@ -851,12 +859,6 @@ std::string & Trim(std::string & val) return TrimR(TrimL(val)); } //--------------------------------------------------------------------------- -std::string Trim(const std::string & val) -{ -std::string res(val); -return TrimR(TrimL(res)); -} -//--------------------------------------------------------------------------- std::string ToLower(std::string value) { std::transform(value.begin(), value.end(), value.begin(), ::tolower); @@ -934,7 +936,7 @@ strncpy(inBuf, source.c_str(), source.length()); inBuf[source.length()] = 0; -#if defined(FREE_BSD) || defined(FREE_BSD5) || defined(WIN32) +#if defined(CONST_ICONV) const char * srcPos = inBuf; #else char * srcPos = inBuf;