2020-12-05 13:08:24 +01:00
|
|
|
#include "localized.h"
|
2020-02-06 10:37:12 +01:00
|
|
|
|
2020-10-26 23:50:47 +01:00
|
|
|
QString Localized::GetVerboseTimeByMs(quint64 elapsed_ms, bool show_days) const
|
2020-03-22 16:15:14 +01:00
|
|
|
{
|
2020-10-26 23:50:47 +01:00
|
|
|
const quint64 elapsed_seconds = (elapsed_ms / 1000) + ((elapsed_ms % 1000) > 0 ? 1 : 0);
|
|
|
|
|
quint64 hours = elapsed_seconds / 3600;
|
2020-03-22 16:15:14 +01:00
|
|
|
|
2020-10-26 23:50:47 +01:00
|
|
|
quint64 days = 0;
|
2020-09-03 09:19:27 +02:00
|
|
|
if (show_days)
|
2020-06-19 12:08:19 +02:00
|
|
|
{
|
2020-09-03 09:19:27 +02:00
|
|
|
days = hours / 24;
|
2020-06-19 12:08:19 +02:00
|
|
|
hours = hours % 24;
|
|
|
|
|
}
|
2020-10-26 23:50:47 +01:00
|
|
|
const quint64 minutes = (elapsed_seconds % 3600) / 60;
|
|
|
|
|
const quint64 seconds = (elapsed_seconds % 3600) % 60;
|
2020-06-19 12:08:19 +02:00
|
|
|
|
2021-04-07 23:05:18 +02:00
|
|
|
QString str_days = tr("%Ln day(s)", "", days);
|
|
|
|
|
QString str_hours = tr("%Ln hour(s)", "", hours);
|
|
|
|
|
QString str_minutes = tr("%Ln minute(s)", "", minutes);
|
|
|
|
|
QString str_seconds = tr("%Ln second(s)", "", seconds);
|
2020-03-22 16:15:14 +01:00
|
|
|
|
2020-09-03 09:19:27 +02:00
|
|
|
if (days != 0)
|
|
|
|
|
{
|
|
|
|
|
if (hours == 0)
|
|
|
|
|
return str_days;
|
2021-04-07 23:05:18 +02:00
|
|
|
|
|
|
|
|
return tr("%0 and %1", "Days and hours").arg(str_days).arg(str_hours);
|
2020-09-03 09:19:27 +02:00
|
|
|
}
|
2021-04-07 23:05:18 +02:00
|
|
|
|
|
|
|
|
if (hours != 0)
|
2020-09-03 09:19:27 +02:00
|
|
|
{
|
2021-04-07 23:05:18 +02:00
|
|
|
if (minutes == 0)
|
|
|
|
|
return str_hours;
|
|
|
|
|
|
|
|
|
|
return tr("%0 and %1", "Hours and minutes").arg(str_hours).arg(str_minutes);
|
2020-03-22 16:15:14 +01:00
|
|
|
}
|
2021-04-07 23:05:18 +02:00
|
|
|
|
|
|
|
|
if (minutes != 0)
|
|
|
|
|
{
|
|
|
|
|
if (seconds != 0)
|
|
|
|
|
return tr("%0 and %1", "Minutes and seconds").arg(str_minutes).arg(str_seconds);
|
|
|
|
|
|
|
|
|
|
return str_minutes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return str_seconds;
|
2020-03-22 16:15:14 +01:00
|
|
|
}
|