File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1313
1414#include " file_progress.hpp"
1515
16- #include < chrono>
17- #include < cmath>
18- #include < cstdint>
1916#include < filesystem>
2017#include < iomanip>
2118#include < iostream>
2219#include < limits>
23- #include < sstream>
2420#include < string>
2521
2622// NOLINTBEGIN(*-narrowing-conversions)
2723
28- [[nodiscard]] std::string
29- format_duration (const std::chrono::duration<double > elapsed) {
30- static constexpr auto s_per_h = 3600 ;
31- static constexpr auto s_per_m = 60 ;
32- const double tot_s = elapsed.count ();
33-
34- // break down into hours, minutes, seconds
35- const std::uint32_t hours = tot_s / 3600 ;
36- const std::uint32_t minutes = (static_cast <int >(tot_s) % s_per_h) / s_per_m;
37- const double seconds = tot_s - (hours * s_per_h) - (minutes * s_per_m);
38-
39- std::ostringstream oss;
40- // NOLINTBEGIN(*-avoid-magic-numbers)
41- oss << std::setfill (' 0' ) << std::setw (2 ) << hours << " :" << std::setfill (' 0' )
42- << std::setw (2 ) << minutes << " :" << std::fixed << std::setprecision (2 )
43- << std::setw (5 ) << seconds;
44- // NOLINTEND(*-avoid-magic-numbers)
45- return oss.str ();
46- }
47-
4824file_progress::file_progress (const std::string &filename) :
4925 one_thousand_over_filesize{
5026 static_cast <double >(one_thousand) /
Original file line number Diff line number Diff line change 1616#ifndef SRC_COMMON_FILE_PROGRESS_HPP_
1717#define SRC_COMMON_FILE_PROGRESS_HPP_
1818
19- #include < chrono>
2019#include < cstddef>
21- #include < cstdint>
2220#include < fstream>
2321#include < string>
2422
25- [[nodiscard]] std::string
26- format_duration (const std::chrono::duration<double > elapsed);
27-
2823struct file_progress {
2924 static constexpr auto one_thousand{1000ul };
3025 double one_thousand_over_filesize{};
You can’t perform that action at this time.
0 commit comments