diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-03-13 22:11:37 +0200 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-03-13 22:11:37 +0200 |
commit | 86f7b090a335da45047aef1ae7e441b78c11ccdf (patch) | |
tree | 7cdabc3c4f3b7d49221c0bd927557fbe6d33d2b7 | |
parent | bf32ca896ccf51385eb67812088ba5861ca2ede2 (diff) | |
download | manaverse-86f7b090a335da45047aef1ae7e441b78c11ccdf.tar.gz manaverse-86f7b090a335da45047aef1ae7e441b78c11ccdf.tar.bz2 manaverse-86f7b090a335da45047aef1ae7e441b78c11ccdf.tar.xz manaverse-86f7b090a335da45047aef1ae7e441b78c11ccdf.zip |
Fix uptime calculation.
-rw-r--r-- | src/commandhandler.cpp | 21 |
1 files changed, 15 insertions, 6 deletions
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); } |