From 86f7b090a335da45047aef1ae7e441b78c11ccdf Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 13 Mar 2011 22:11:37 +0200 Subject: Fix uptime calculation. --- src/commandhandler.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/commandhandler.cpp') diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp index b1ace058d..b1bf3b756 100644 --- a/src/commandhandler.cpp +++ b/src/commandhandler.cpp @@ -1114,35 +1114,44 @@ void CommandHandler::handleUptime(const std::string &args, else { std::string str; - const int timeDiff = cur_time - start_time; - const int min = timeDiff / 60; - const int hours = min / 60; - const int days = hours / 24; - const int weeks = days / 7; + int timeDiff = cur_time - start_time; + + const int weeks = timeDiff / 60 / 60 / 24 / 7; if (weeks > 0) { str = strprintf(ngettext("%d week", "%d weeks", weeks), weeks); + timeDiff -= weeks * 60 * 60 * 24 * 7; } + + const int days = timeDiff / 60 / 60 / 24; if (days > 0) { if (!str.empty()) str += ", "; str += strprintf(ngettext("%d day", "%d days", days), days); + timeDiff -= days * 60 * 60 * 24; } + const int hours = timeDiff / 60 / 60; if (hours > 0) { if (!str.empty()) str += ", "; str += strprintf(ngettext("%d hour", "%d hours", hours), hours); + timeDiff -= hours * 60 * 60; } + const int min = timeDiff / 60; if (min > 0) { if (!str.empty()) str += ", "; str += strprintf(ngettext("%d minute", "%d minutes", min), min); + timeDiff -= min * 60; } - if (str.empty()) + + if (timeDiff > 0) { + if (!str.empty()) + str += ", "; str += strprintf(ngettext("%d second", "%d seconds", timeDiff), timeDiff); } -- cgit v1.2.3-60-g2f50