some time refactors
no more weird totalTicks name code looks better
This commit is contained in:
parent
a2b56b5b64
commit
5ff81aef33
16 changed files with 256 additions and 211 deletions
|
|
@ -20,7 +20,7 @@
|
|||
#include "timeutils.h"
|
||||
#include <fmt/printf.h>
|
||||
|
||||
String TimeMicros::toString(signed char prec, unsigned char hms) {
|
||||
String TimeMicros::toString(signed char prec, TATimeFormats hms) {
|
||||
String ret;
|
||||
int actualSeconds=seconds;
|
||||
int actualMicros=micros;
|
||||
|
|
@ -31,8 +31,55 @@ String TimeMicros::toString(signed char prec, unsigned char hms) {
|
|||
}
|
||||
if (negative) actualSeconds=-actualSeconds;
|
||||
|
||||
// handle auto formats
|
||||
switch (hms) {
|
||||
case 2: { // h:mm:ss
|
||||
case TA_TIME_FORMAT_AUTO:
|
||||
hms=TA_TIME_FORMAT_SECONDS;
|
||||
if (actualSeconds>60) hms=TA_TIME_FORMAT_MS;
|
||||
if (actualSeconds>3600) hms=TA_TIME_FORMAT_HMS;
|
||||
if (actualSeconds>86400) hms=TA_TIME_FORMAT_DAYS_HMS;
|
||||
break;
|
||||
case TA_TIME_FORMAT_AUTO_ZERO:
|
||||
hms=TA_TIME_FORMAT_SECONDS;
|
||||
if (actualSeconds>60) hms=TA_TIME_FORMAT_MS_ZERO;
|
||||
if (actualSeconds>3600) hms=TA_TIME_FORMAT_HMS_ZERO;
|
||||
if (actualSeconds>86400) hms=TA_TIME_FORMAT_DAYS_HMS_ZERO;
|
||||
break;
|
||||
case TA_TIME_FORMAT_AUTO_MS:
|
||||
hms=TA_TIME_FORMAT_MS;
|
||||
if (actualSeconds>3600) hms=TA_TIME_FORMAT_HMS;
|
||||
if (actualSeconds>86400) hms=TA_TIME_FORMAT_DAYS_HMS;
|
||||
break;
|
||||
case TA_TIME_FORMAT_AUTO_MS_ZERO:
|
||||
hms=TA_TIME_FORMAT_MS_ZERO;
|
||||
if (actualSeconds>3600) hms=TA_TIME_FORMAT_HMS_ZERO;
|
||||
if (actualSeconds>86400) hms=TA_TIME_FORMAT_DAYS_HMS_ZERO;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (hms) {
|
||||
case TA_TIME_FORMAT_SECONDS: { // seconds
|
||||
if (negative) {
|
||||
ret=fmt::sprintf("-%d",actualSeconds);
|
||||
} else {
|
||||
ret=fmt::sprintf("%d",actualSeconds);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TA_TIME_FORMAT_MS: { // m:ss
|
||||
int m=actualSeconds/60;
|
||||
int s=actualSeconds%60;
|
||||
|
||||
if (negative) {
|
||||
ret=fmt::sprintf("-%d:%02d",m,s);
|
||||
} else {
|
||||
ret=fmt::sprintf("%d:%02d",m,s);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TA_TIME_FORMAT_HMS: { // h:mm:ss
|
||||
int h=actualSeconds/3600;
|
||||
int m=(actualSeconds/60)%60;
|
||||
int s=actualSeconds%60;
|
||||
|
|
@ -44,25 +91,65 @@ String TimeMicros::toString(signed char prec, unsigned char hms) {
|
|||
}
|
||||
break;
|
||||
}
|
||||
case 1: { // m:ss
|
||||
case TA_TIME_FORMAT_MS_ZERO: { // mm:ss
|
||||
int m=actualSeconds/60;
|
||||
int s=actualSeconds%60;
|
||||
|
||||
if (negative) {
|
||||
ret=fmt::sprintf("-%d:%02d",m,s);
|
||||
ret=fmt::sprintf("-%02d:%02d",m,s);
|
||||
} else {
|
||||
ret=fmt::sprintf("%d:%02d",m,s);
|
||||
ret=fmt::sprintf("%02d:%02d",m,s);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: { // seconds
|
||||
case TA_TIME_FORMAT_HMS_ZERO: { // hh:mm:ss
|
||||
int h=actualSeconds/3600;
|
||||
int m=(actualSeconds/60)%60;
|
||||
int s=actualSeconds%60;
|
||||
|
||||
if (negative) {
|
||||
ret=fmt::sprintf("-%d",actualSeconds);
|
||||
ret=fmt::sprintf("-%02d:%02d:%02d",h,m,s);
|
||||
} else {
|
||||
ret=fmt::sprintf("%d",actualSeconds);
|
||||
ret=fmt::sprintf("%02d:%02d:%02d",h,m,s);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TA_TIME_FORMAT_DAYS_HMS: { // ?y?m?d h:mm:ss
|
||||
int days=actualSeconds/86400;
|
||||
int years=days/365;
|
||||
days%=365;
|
||||
int months=days/30;
|
||||
days%=30;
|
||||
int h=(actualSeconds/3600)%24;
|
||||
int m=(actualSeconds/60)%60;
|
||||
int s=actualSeconds%60;
|
||||
|
||||
if (negative) {
|
||||
ret=fmt::sprintf("-%dy%dm%dd %d:%02d:%02d",years,months,days,h,m,s);
|
||||
} else {
|
||||
ret=fmt::sprintf("%dy%dm%dd %d:%02d:%02d",years,months,days,h,m,s);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TA_TIME_FORMAT_DAYS_HMS_ZERO: { // ?y?m?d hh:mm:ss
|
||||
int days=actualSeconds/86400;
|
||||
int years=days/365;
|
||||
days%=365;
|
||||
int months=days/30;
|
||||
days%=30;
|
||||
int h=(actualSeconds/3600)%24;
|
||||
int m=(actualSeconds/60)%60;
|
||||
int s=actualSeconds%60;
|
||||
|
||||
if (negative) {
|
||||
ret=fmt::sprintf("-%dy%dm%dd %02d:%02d:%02d",years,months,days,h,m,s);
|
||||
} else {
|
||||
ret=fmt::sprintf("%dy%dm%dd %02d:%02d:%02d",years,months,days,h,m,s);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return "ERROR!";
|
||||
}
|
||||
|
||||
if (prec<0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue