aboutsummaryrefslogtreecommitdiffhomepage
path: root/common
diff options
context:
space:
mode:
authorGravatar wm4 <wm4@nowhere>2018-04-30 19:27:00 +0200
committerGravatar Jan Ekström <jeebjp@gmail.com>2018-05-01 00:25:27 +0300
commit8f67fa13f1a61eccd12d85bc20c87b17e9f1f3ec (patch)
tree78b756fce20f452a4a0b55cca9741593fe2aed54 /common
parent6bd2bdc74522f0fbcc51f79e435729b1efe6c4f6 (diff)
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.
Diffstat (limited to 'common')
-rw-r--r--common/common.c8
1 files changed, 6 insertions, 2 deletions
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 <stdarg.h>
+#include <math.h>
#include <assert.h>
#include <libavutil/common.h>
@@ -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] == '%') {