MCPcopy Create free account
hub / github.com/PlotJuggler/PlotJuggler / formatDuration

Function formatDuration

pj_dialog_host/src/widget_binding.cpp:87–103  ·  view source on GitHub ↗

Human-readable nanosecond duration: "42s", "12m 30s", "3h 45m", "2d 5h 30m".

Source from the content-addressed store, hash-verified

85
86// Human-readable nanosecond duration: "42s", "12m 30s", "3h 45m", "2d 5h 30m".
87std::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].

Callers 1

applyToWidgetFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected