Human-readable nanosecond duration: "42s", "12m 30s", "3h 45m", "2d 5h 30m".
| 85 | |
| 86 | // Human-readable nanosecond duration: "42s", "12m 30s", "3h 45m", "2d 5h 30m". |
| 87 | std::string formatDuration(std::int64_t duration_ns) { |
| 88 | const std::int64_t total_secs = duration_ns / 1'000'000'000LL; |
| 89 | if (total_secs < 60) { |
| 90 | return std::to_string(total_secs) + "s"; |
| 91 | } |
| 92 | const std::int64_t days = total_secs / 86400; |
| 93 | const std::int64_t hours = (total_secs % 86400) / 3600; |
| 94 | const std::int64_t minutes = (total_secs % 3600) / 60; |
| 95 | const std::int64_t secs = total_secs % 60; |
| 96 | if (days > 0) { |
| 97 | return std::to_string(days) + "d " + std::to_string(hours) + "h " + std::to_string(minutes) + "m"; |
| 98 | } |
| 99 | if (hours > 0) { |
| 100 | return std::to_string(hours) + "h " + std::to_string(minutes) + "m"; |
| 101 | } |
| 102 | return std::to_string(minutes) + "m " + std::to_string(secs) + "s"; |
| 103 | } |
| 104 | |
| 105 | // Map a slider position in [0, slider_max] onto absolute nanoseconds within |
| 106 | // [min_ns, max_ns]. |