Skip to content

Commit b0734d6

Browse files
committed
New constants: SECONDS_IN_MINUTE and MINUTES_IN_HOUR
1 parent b75d73a commit b0734d6

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

src/util.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,22 @@ namespace util {
2323

2424
std::string human_readable_duration(uint64_t seconds)
2525
{
26-
if (seconds < 60UL) {
26+
constexpr uint64_t SECONDS_IN_MINUTE = 60UL;
27+
constexpr uint64_t MINUTES_IN_HOUR = 60UL;
28+
29+
if (seconds < SECONDS_IN_MINUTE) {
2730
return fmt::format("{}s", seconds);
2831
}
2932

30-
if (seconds < (60UL * 60UL)) {
31-
return fmt::format("{}s ({}m {}s)", seconds, seconds / 60,
32-
seconds % 60);
33+
uint64_t const mins = seconds / SECONDS_IN_MINUTE;
34+
uint64_t const secs = seconds % SECONDS_IN_MINUTE;
35+
36+
if (seconds < (SECONDS_IN_MINUTE * MINUTES_IN_HOUR)) {
37+
return fmt::format("{}s ({}m {}s)", seconds, mins, secs);
3338
}
3439

35-
auto const secs = seconds % 60;
36-
auto const mins = seconds / 60;
37-
return fmt::format("{}s ({}h {}m {}s)", seconds, mins / 60, mins % 60,
38-
secs);
40+
return fmt::format("{}s ({}h {}m {}s)", seconds, mins / MINUTES_IN_HOUR,
41+
mins % MINUTES_IN_HOUR, secs);
3942
}
4043

4144
std::string human_readable_duration(std::chrono::microseconds duration)

0 commit comments

Comments
 (0)