|
@ -127,11 +127,11 @@ struct duration_t { |
|
|
* 59s |
|
|
* 59s |
|
|
*/ |
|
|
*/ |
|
|
char* toString(char * const buffer) const { |
|
|
char* toString(char * const buffer) const { |
|
|
int y = this->year(), |
|
|
const uint16_t y = this->year(), |
|
|
d = this->day() % 365, |
|
|
d = this->day() % 365, |
|
|
h = this->hour() % 24, |
|
|
h = this->hour() % 24, |
|
|
m = this->minute() % 60, |
|
|
m = this->minute() % 60, |
|
|
s = this->second() % 60; |
|
|
s = this->second() % 60; |
|
|
|
|
|
|
|
|
if (y) sprintf_P(buffer, PSTR("%iy %id %ih %im %is"), y, d, h, m, s); |
|
|
if (y) sprintf_P(buffer, PSTR("%iy %id %ih %im %is"), y, d, h, m, s); |
|
|
else if (d) sprintf_P(buffer, PSTR("%id %ih %im %is"), d, h, m, s); |
|
|
else if (d) sprintf_P(buffer, PSTR("%id %ih %im %is"), d, h, m, s); |
|
@ -149,23 +149,29 @@ struct duration_t { |
|
|
* |
|
|
* |
|
|
* Output examples: |
|
|
* Output examples: |
|
|
* 123456789 (strlen) |
|
|
* 123456789 (strlen) |
|
|
|
|
|
* 12'34 |
|
|
* 99:59 |
|
|
* 99:59 |
|
|
* 11d 12:33 |
|
|
* 11d 12:33 |
|
|
*/ |
|
|
*/ |
|
|
uint8_t 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()), |
|
|
const uint16_t h = uint16_t(this->hour()), |
|
|
m = uint16_t(this->minute() % 60UL); |
|
|
m = uint16_t(this->minute() % 60UL); |
|
|
if (with_days) { |
|
|
if (with_days) { |
|
|
uint16_t d = this->day(); |
|
|
const uint16_t d = this->day(); |
|
|
sprintf_P(buffer, PSTR("%hud %02hu:%02hu"), d, h % 24, m); |
|
|
sprintf_P(buffer, PSTR("%hud %02hu:%02hu"), d, h % 24, m); // 1d 23:45
|
|
|
return d >= 10 ? 9 : 8; |
|
|
return d >= 10 ? 9 : 8; |
|
|
} |
|
|
} |
|
|
|
|
|
else if (!h) { |
|
|
|
|
|
const uint16_t s = uint16_t(this->second() % 60UL); |
|
|
|
|
|
sprintf_P(buffer, PSTR("%02hu'%02hu"), m, s); // 12'34
|
|
|
|
|
|
return 5; |
|
|
|
|
|
} |
|
|
else if (h < 100) { |
|
|
else if (h < 100) { |
|
|
sprintf_P(buffer, PSTR("%02hu:%02hu"), h, m); |
|
|
sprintf_P(buffer, PSTR("%02hu:%02hu"), h, m); // 12:34
|
|
|
return 5; |
|
|
return 5; |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
sprintf_P(buffer, PSTR("%hu:%02hu"), h, m); |
|
|
sprintf_P(buffer, PSTR("%hu:%02hu"), h, m); // 123:45
|
|
|
return 6; |
|
|
return 6; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|