MCPcopy Create free account
hub / github.com/ccache/ccache / format_duration

Function format_duration

src/ccache/util/string.cpp:177–205  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

175}
176
177std::string
178format_duration(std::chrono::milliseconds ms)
179{
180 const auto ms_count = ms.count();
181
182 if (ms_count == 0) {
183 return "0s";
184 }
185
186 // Try to express in the largest unit that divides evenly.
187 constexpr int64_t ms_per_day = 24 * 60 * 60 * 1000;
188 constexpr int64_t ms_per_hour = 60 * 60 * 1000;
189 constexpr int64_t ms_per_minute = 60 * 1000;
190 constexpr int64_t ms_per_second = 1000;
191
192 if (ms_count % ms_per_day == 0) {
193 return FMT("{}d", ms_count / ms_per_day);
194 }
195 if (ms_count % ms_per_hour == 0) {
196 return FMT("{}h", ms_count / ms_per_hour);
197 }
198 if (ms_count % ms_per_minute == 0) {
199 return FMT("{}m", ms_count / ms_per_minute);
200 }
201 if (ms_count % ms_per_second == 0) {
202 return FMT("{}s", ms_count / ms_per_second);
203 }
204 return FMT("{}ms", ms_count);
205}
206
207std::string
208format_human_readable_diff(int64_t diff, SizeUnitPrefixType prefix_type)

Callers 2

to_stringFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected