summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-03-13 22:11:37 +0200
committerAndrei Karas <akaras@inbox.ru>2011-03-13 22:11:37 +0200
commit86f7b090a335da45047aef1ae7e441b78c11ccdf (patch)
tree7cdabc3c4f3b7d49221c0bd927557fbe6d33d2b7 /src
parentbf32ca896ccf51385eb67812088ba5861ca2ede2 (diff)
downloadplus-86f7b090a335da45047aef1ae7e441b78c11ccdf.tar.gz
plus-86f7b090a335da45047aef1ae7e441b78c11ccdf.tar.bz2
plus-86f7b090a335da45047aef1ae7e441b78c11ccdf.tar.xz
plus-86f7b090a335da45047aef1ae7e441b78c11ccdf.zip
Fix uptime calculation.
Diffstat (limited to 'src')
-rw-r--r--src/commandhandler.cpp21
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);
}