Better time display for timeouts (#601)

* Better time display for timeouts

* remove newline
This commit is contained in:
Nikolai Zimmermann 2018-07-11 16:09:28 +02:00 committed by fourtf
parent db099260ad
commit f63d9d3e33

View file

@ -68,27 +68,35 @@ QString makeDuration(int count, const QString &order)
return text;
}
QString makeDuration(uint32_t timeoutSeconds)
QString makeDuration(int timeoutSeconds)
{
int timeoutMinutes = floor(timeoutSeconds / 60);
QString res = "";
if (timeoutMinutes > 0 && timeoutSeconds % 60 == 0) {
int timeoutHours = floor(timeoutMinutes / 60);
if (timeoutHours > 0 && timeoutMinutes % 60 == 0) {
int timeoutDays = floor(timeoutHours / 24);
if (timeoutDays > 0 && timeoutHours % 24 == 0) {
return makeDuration(timeoutDays, "day");
int seconds = timeoutSeconds % 60;
int timeoutMinutes = timeoutSeconds / 60;
int minutes = timeoutMinutes % 60;
int timeoutHours = timeoutMinutes / 60;
int hours = timeoutHours % 24;
int days = timeoutHours / 24;
if (days > 0) {
res.append(makeDuration(days, "day"));
}
return makeDuration(timeoutHours, "hour");
if (hours > 0) {
if (!res.isEmpty() )
res.append(" ");
res.append(makeDuration(hours, "hour"));
}
return makeDuration(timeoutMinutes, "minute");
if (minutes > 0) {
if (!res.isEmpty() )
res.append(" ");
res.append(makeDuration(minutes, "minute"));
}
return makeDuration(timeoutSeconds, "second");
if (seconds > 0) {
if (!res.endsWith(" "))
res.append(" ");
res.append(makeDuration(seconds, "second"));
}
return res;
}
} // namespace