From 5ccc3d9d65a2542e96f5f8eb2cea43c4553739bd Mon Sep 17 00:00:00 2001 From: Benjamin Moody Date: Wed, 15 Jun 2022 12:13:27 -0400 Subject: [PATCH] client: use round rather than floor in (ms)timstr. When converting time to a string, round to the nearest elapsed second or millisecond, rather than rounding down. In particular, when we jump forward by "one second" by clicking the forward button, the time display should advance by one second. --- client/js/lightwave.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/client/js/lightwave.js b/client/js/lightwave.js index d5d3c6c..bf12e7d 100644 --- a/client/js/lightwave.js +++ b/client/js/lightwave.js @@ -276,7 +276,7 @@ function set_trace(db, record, s) { function timstr(t) { var ss, mm, hh, tstring; - ss = Math.floor(t/tickfreq); + ss = Math.round(t/tickfreq); mm = Math.floor(ss/60); ss %= 60; hh = Math.floor(mm/60); mm %= 60; if (ss < 10) { ss = '0' + ss; } @@ -288,15 +288,21 @@ function timstr(t) { // Convert argument (in samples) to a string in HH:MM:SS.mmm format function mstimstr(t) { - var mmm, tstring; + var mmm, ss, mm, hh, tstring; - mmm = Math.floor(1000*t/tickfreq) % 1000; + mmm = Math.round(1000*t/tickfreq); + ss = Math.floor(mmm/1000); mmm %= 1000; + mm = Math.floor(ss/60); ss %= 60; + hh = Math.floor(mm/60); mm %= 60; if (mmm < 100) { if (mmm < 10) { mmm = '.00' + mmm; } else { mmm = '.0' + mmm; } } else { mmm = '.' + mmm; } - tstring = timstr(t) + mmm; + if (ss < 10) { ss = '0' + ss; } + if (mm < 10) { mm = '0' + mm; } + if (hh < 10) { hh = '0' + hh; } + tstring = hh + ':' + mm + ':' + ss + mmm; return tstring; }