Better alignment of elapsed print time

This commit is contained in:
Scott Lahteine
2016-12-04 21:09:12 -06:00
parent 0b9b529745
commit 9d88a61d52
3 changed files with 39 additions and 23 deletions

View File

@ -145,15 +145,22 @@ struct duration_t {
* 99:59
* 11d 12:33
*/
void toDigital(char *buffer, bool with_days=false) const {
uint8_t toDigital(char *buffer, bool with_days=false) const {
uint16_t h = uint16_t(this->hour()),
m = uint16_t(this->minute() % 60UL);
if (with_days)
sprintf_P(buffer, PSTR("%ud %02u:%02u"), this->day(), h, m);
else if (h < 100)
if (with_days) {
uint16_t d = this->day();
sprintf_P(buffer, PSTR("%ud %02u:%02u"), d, h, m);
return d >= 10 ? 8 : 7;
}
else if (h < 100) {
sprintf_P(buffer, PSTR("%02u:%02u"), h % 24, m);
else
return 5;
}
else {
sprintf_P(buffer, PSTR("%u:%02u"), h, m);
return 6;
}
}
};