From 8f67fa13f1a61eccd12d85bc20c87b17e9f1f3ec Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 30 Apr 2018 19:27:00 +0200 Subject: common: round all integer times to milliseconds This means that a time of 4.5678 is displayed as "00:00:04.568" when the format string is "%H:%M:%S.%T". Likewise, 59.99999 will be displayed as "00:01:00.000". Before this change, the sub-ms times were just truncated. Requested by TheAMM. --- common/common.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'common') diff --git a/common/common.c b/common/common.c index 12e8e141ec..786d2e5328 100644 --- a/common/common.c +++ b/common/common.c @@ -16,6 +16,7 @@ */ #include +#include #include #include @@ -48,14 +49,17 @@ char *mp_format_time_fmt(const char *fmt, double time) time = time < 0 ? -time : time; long long int itime = time; long long int h, m, tm, s; - int ms; + int ms = lrint((time - itime) * 1000); + if (ms >= 1000) { + ms -= 1000; + itime += 1; + } s = itime; tm = s / 60; h = s / 3600; s -= h * 3600; m = s / 60; s -= m * 60; - ms = (time - itime) * 1000; char *res = talloc_strdup(NULL, ""); while (*fmt) { if (fmt[0] == '%') { -- cgit v1.2.3