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; 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 seconds = timeoutSeconds % 60;
int timeoutHours = floor(timeoutMinutes / 60); int timeoutMinutes = timeoutSeconds / 60;
int minutes = timeoutMinutes % 60;
if (timeoutHours > 0 && timeoutMinutes % 60 == 0) { int timeoutHours = timeoutMinutes / 60;
int timeoutDays = floor(timeoutHours / 24); int hours = timeoutHours % 24;
int days = timeoutHours / 24;
if (timeoutDays > 0 && timeoutHours % 24 == 0) { if (days > 0) {
return makeDuration(timeoutDays, "day"); res.append(makeDuration(days, "day"));
}
return makeDuration(timeoutHours, "hour");
}
return makeDuration(timeoutMinutes, "minute");
} }
if (hours > 0) {
return makeDuration(timeoutSeconds, "second"); if (!res.isEmpty() )
res.append(" ");
res.append(makeDuration(hours, "hour"));
}
if (minutes > 0) {
if (!res.isEmpty() )
res.append(" ");
res.append(makeDuration(minutes, "minute"));
}
if (seconds > 0) {
if (!res.endsWith(" "))
res.append(" ");
res.append(makeDuration(seconds, "second"));
}
return res;
} }
} // namespace } // namespace