1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-14 11:59:50 +03:00

Merge with latest 2.3

This commit is contained in:
Bertrand Songis 2020-10-07 21:01:45 +02:00
commit 42a3198568
No known key found for this signature in database
GPG key ID: F189F79290FEC50F
376 changed files with 10566 additions and 8633 deletions

View file

@ -159,7 +159,11 @@ char * strAppendStringWithIndex(char * dest, const char * s, int idx)
return strAppendUnsigned(strAppend(dest, s), abs(idx));
}
char * getTimerString(char * dest, int32_t tme, uint8_t hours)
constexpr int secondsPerDay = 24 * 3600;
constexpr int secondsPer99Hours = 99*3600 + 59*60 + 59;
constexpr int secondsPerYear = 365 * secondsPerDay;
char * getTimerString(char * dest, int tme, uint8_t hours)
{
char * s = dest;
div_t qr;
@ -169,28 +173,63 @@ char * getTimerString(char * dest, int32_t tme, uint8_t hours)
*s++ = '-';
}
qr = div((int)tme, 60);
if (tme < secondsPerDay) {
qr = div((int) tme, 60);
if (hours) {
div_t qr2 = div(qr.quot, 60);
if (hours) {
div_t qr2 = div(qr.quot, 60);
*s++ = '0' + (qr2.quot / 10);
*s++ = '0' + (qr2.quot % 10);
*s++ = ':';
qr.quot = qr2.rem;
}
if (!hours && qr.quot > 99) {
*s++ = '0' + (qr.quot / 100);
qr.quot = qr.quot % 100;
}
*s++ = '0' + (qr.quot / 10);
*s++ = '0' + (qr.quot % 10);
*s++ = ':';
*s++ = '0' + (qr.rem / 10);
*s++ = '0' + (qr.rem % 10);
*s = '\0';
}
else if (tme < secondsPer99Hours) {
qr = div(tme, 3600);
div_t qr2 = div(qr.rem, 60);
*s++ = '0' + (qr.quot / 10);
*s++ = '0' + (qr.quot % 10);
*s++ = 'H';
*s++ = '0' + (qr2.quot / 10);
*s++ = '0' + (qr2.quot % 10);
*s++ = ':';
qr.quot = qr2.rem;
*s = '\0';
}
if (!hours && qr.quot > 99) {
else if (tme < secondsPerYear) {
qr = div(tme, secondsPerDay);
div_t qr2 = div(qr.rem, 60);
*s++ = '0' + (qr.quot / 100);
qr.quot = qr.quot % 100;
*s++ = '0' + (qr.quot / 10);
*s++ = '0' + (qr.quot % 10);
*s++ = 'D';
*s++ = '0' + (qr2.quot / 10);
*s++ = '0' + (qr2.quot % 10);
*s++ = 'H';
*s = '\0';
}
else {
qr = div(tme, secondsPerYear);
div_t qr2 = div(qr.rem, secondsPerDay);
*s++ = '0' + (qr.quot / 10);
*s++ = '0' + (qr.quot % 10);
*s++ = 'Y';
*s++ = 'Y';
*s++ = '0' + (qr2.quot / 10);
*s++ = '0' + (qr2.quot % 10);
*s++ = 'D';
*s = '\0';
}
*s++ = '0' + (qr.quot / 10);
*s++ = '0' + (qr.quot % 10);
*s++ = ':';
*s++ = '0' + (qr.rem / 10);
*s++ = '0' + (qr.rem % 10);
*s = '\0';
return dest;
}