MCPcopy Create free account
hub / github.com/SeisSol/SeisSol / formatTime

Method formatTime

src/Monitoring/Unit.cpp:21–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19SIUnit::SIUnit(const std::string& unit, bool binary) : unit(unit), binary(binary) {}
20
21std::string SIUnit::formatTime(double value, bool exact, int digits) const {
22 const double byDay = std::floor(value / (60 * 60 * 24));
23 const double hours = value - byDay * (60 * 60 * 24);
24 const double byHour = std::floor(hours / (60 * 60));
25 const double minutes = hours - byHour * (60 * 60);
26 const double byMinute = std::floor(minutes / 60);
27 const double seconds = minutes - byMinute * (60);
28
29 std::ostringstream stream;
30 stream.precision(0);
31 stream << std::fixed;
32 bool done = false;
33 if (byDay > 0 && (!done || exact)) {
34 stream << byDay << " d";
35 done = true;
36 }
37 if (byHour > 0 && (!done || exact)) {
38 if (done) {
39 stream << " ";
40 }
41 stream << byHour << " h";
42 done = true;
43 }
44 if (byMinute > 0 && (!done || exact)) {
45 if (done) {
46 stream << " ";
47 }
48 stream << byMinute << " min";
49 done = true;
50 }
51 if (seconds != 0 || !done || exact) {
52 if (done) {
53 stream << " ";
54 }
55 stream << formatPrefix(seconds, digits);
56 done = true;
57 }
58 return stream.str();
59}
60
61std::string SIUnit::formatPrefix(double value, int digits) const {
62 double mantissa = std::abs(value);

Callers 2

printMethod · 0.80
printSummaryMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected