mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
Display the uptime in a more readable way
This adds CString::ToTimeStr() which converts a number of seconds into a human readable time string. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1107 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
26
String.cpp
26
String.cpp
@@ -887,6 +887,32 @@ CString CString::ToByteStr(unsigned long long d) {
|
||||
return CString(d) + " B";
|
||||
}
|
||||
|
||||
CString CString::ToTimeStr(unsigned long s) {
|
||||
const unsigned long m = 60;
|
||||
const unsigned long h = m * 60;
|
||||
const unsigned long d = h * 24;
|
||||
const unsigned long w = d * 7;
|
||||
const unsigned long y = d * 365;
|
||||
CString sRet;
|
||||
|
||||
#define TIMESPAN(time, str) \
|
||||
if (s >= time) { \
|
||||
sRet += CString(s / time) + str " "; \
|
||||
s = s % time; \
|
||||
}
|
||||
TIMESPAN(y, "y");
|
||||
TIMESPAN(w, "w");
|
||||
TIMESPAN(d, "d");
|
||||
TIMESPAN(h, "h");
|
||||
TIMESPAN(m, "m");
|
||||
TIMESPAN(1, "s");
|
||||
|
||||
if (sRet.empty())
|
||||
return "0s";
|
||||
|
||||
return sRet.RightChomp_n();
|
||||
}
|
||||
|
||||
bool CString::ToBool() const { return (!Trim_n().Trim_n("0").empty() && Trim_n().CaseCmp("false") != 0); }
|
||||
short CString::ToShort() const { return strtoul(this->c_str(), (char**) NULL, 10); }
|
||||
unsigned short CString::ToUShort() const { return strtoul(this->c_str(), (char**) NULL, 10); }
|
||||
|
||||
Reference in New Issue
Block a user