added to misc: timespec_to_stream_with_unit() for printing times either is seconds or miliseconds

This commit is contained in:
2021-06-30 16:30:11 +02:00
parent 0f78968579
commit df3f04a951
3 changed files with 33 additions and 5 deletions

View File

@@ -1509,6 +1509,34 @@ void timespec_to_stream(timespec & val, pt::Stream & stream)
}
void timespec_to_stream_with_unit(timespec & val, pt::Stream & stream)
{
char buf[50];
bool is_ms = false;
double val_double = timespec_to_double(val);
if( val_double < 0.1 )
{
is_ms = true;
val_double = val_double * 1000;
}
sprintf(buf, "%f", val_double);
SetNonZeroDigitsAfterComma(buf, 2);
stream << buf;
if( is_ms )
{
stream << "ms";
}
else
{
stream << "s";
}
}
} // namespace Winix