Improve readability

pull/541/head
capostrophic 5 years ago
parent 2affb8ed63
commit 26f59e47db

@ -678,48 +678,45 @@ namespace MWGui
return ret; return ret;
} }
constexpr float secondsPerMinute = 60.f; // 60 seconds constexpr int secondsPerMinute = 60; // 60 seconds
constexpr float secondsPerHour = secondsPerMinute * 60.f; // 60 minutes constexpr int secondsPerHour = secondsPerMinute * 60; // 60 minutes
constexpr float secondsPerDay = secondsPerHour * 24.f; // 24 hours constexpr int secondsPerDay = secondsPerHour * 24; // 24 hours
constexpr float secondsPerMonth = secondsPerDay * 30.f; // 30 days constexpr int secondsPerMonth = secondsPerDay * 30; // 30 days
constexpr float secondsPerYear = secondsPerDay * 365.f; constexpr int secondsPerYear = secondsPerDay * 365;
int fullDuration = static_cast<int>(duration);
int units = 0; int units = 0;
if (duration >= secondsPerYear) int years = fullDuration / secondsPerYear;
int months = fullDuration % secondsPerYear / secondsPerMonth;
int days = fullDuration % secondsPerYear % secondsPerMonth / secondsPerDay; // Because a year is not exactly 12 "months"
int hours = fullDuration % secondsPerDay / secondsPerHour;
int minutes = fullDuration % secondsPerHour / secondsPerMinute;
int seconds = fullDuration % secondsPerMinute;
if (years)
{ {
units++; units++;
int years = duration / secondsPerYear;
duration -= years * secondsPerYear;
ret += toString(years) + " y "; ret += toString(years) + " y ";
} }
if (duration >= secondsPerMonth) if (months)
{ {
units++; units++;
int months = duration / secondsPerMonth;
duration -= months * secondsPerMonth;
ret += toString(months) + " mo "; ret += toString(months) + " mo ";
} }
if (units < 2 && duration >= secondsPerDay) if (units < 2 && days)
{ {
units++; units++;
int days = duration / secondsPerDay;
duration -= days * secondsPerDay;
ret += toString(days) + " d "; ret += toString(days) + " d ";
} }
if (units < 2 && duration >= secondsPerHour) if (units < 2 && hours)
{ {
units++; units++;
int hours = duration / secondsPerHour;
duration -= hours * secondsPerHour;
ret += toString(hours) + " h "; ret += toString(hours) + " h ";
} }
if (units < 2 && duration >= secondsPerMinute) if (units >= 2)
{ return ret;
int minutes = duration / secondsPerMinute; if (minutes)
duration -= minutes * secondsPerMinute;
ret += toString(minutes) + " min "; ret += toString(minutes) + " min ";
} if (seconds)
if (units < 2 && duration >= 1.f) ret += toString(seconds) + " s ";
ret += toString(int(duration)) + " s ";
return ret; return ret;
} }

Loading…
Cancel
Save