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:
psychon
2008-06-27 09:55:55 +00:00
parent 9e6d05a0bd
commit b2512e55ea
3 changed files with 28 additions and 1 deletions

View File

@@ -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); }