| 203 | |
| 204 | |
| 205 | String StopWatch::toString(const double time_in_seconds) |
| 206 | { |
| 207 | int d(0), h(0), m(0), s(0); |
| 208 | |
| 209 | TimeType time_i = (TimeType)time_in_seconds; // trunc to integer |
| 210 | |
| 211 | // compute days |
| 212 | d = int(time_i / (3600*24)); |
| 213 | time_i -= d*(3600*24); |
| 214 | |
| 215 | // hours |
| 216 | h = int(time_i / 3600); |
| 217 | time_i -= h*3600; |
| 218 | |
| 219 | // minutes |
| 220 | m = int(time_i / 60); |
| 221 | time_i -= m*60; |
| 222 | |
| 223 | s = int(time_i); |
| 224 | |
| 225 | |
| 226 | String s_d = String(d); |
| 227 | String s_h = String(h).fillLeft('0', 2) + ":"; |
| 228 | String s_m = String(m).fillLeft('0', 2) + ":"; |
| 229 | String s_s = String(s).fillLeft('0', 2); // if we show seconds in combination with minutes, we round to nominal |
| 230 | |
| 231 | return ( (d>0 ? s_d + "d " + s_h + s_m + s_s + " h" : |
| 232 | (h>0 ? s_h + s_m + s_s + " h" : |
| 233 | (m>0 ? s_m + s_s + " m" : |
| 234 | ( String::number(time_in_seconds, 2) + " s"))))); // second (shown by itself with no minutes) has two digits after decimal |
| 235 | |
| 236 | } |
| 237 | |
| 238 | String StopWatch::toString() const |
| 239 | { |