From 39732bd31e13c9a785eac1fc724bc9fc768be2ab Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 14 Aug 2021 00:44:47 -0300 Subject: show timestamp hours column whenever appropriate --- general-util.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'general-util.js') diff --git a/general-util.js b/general-util.js index f63ae21..aba1541 100644 --- a/general-util.js +++ b/general-util.js @@ -149,7 +149,7 @@ module.exports.getSecFromTimestamp = function(timestamp) { } } -module.exports.getTimeStringsFromSec = function(curSecTotal, lenSecTotal) { +module.exports.getTimeStringsFromSec = function(curSecTotal, lenSecTotal, fraction = false) { const percentVal = (100 / lenSecTotal) * curSecTotal const percentDone = ( (Math.trunc(percentVal * 100) / 100).toFixed(2) + '%' @@ -159,29 +159,36 @@ module.exports.getTimeStringsFromSec = function(curSecTotal, lenSecTotal) { let leftHour = Math.floor(leftSecTotal / 3600) let leftMin = Math.floor((leftSecTotal - leftHour * 3600) / 60) let leftSec = Math.floor(leftSecTotal - leftHour * 3600 - leftMin * 60) + let leftFrac = lenSecTotal % 1 // Yeah, yeah, duplicate math. let curHour = Math.floor(curSecTotal / 3600) let curMin = Math.floor((curSecTotal - curHour * 3600) / 60) let curSec = Math.floor(curSecTotal - curHour * 3600 - curMin * 60) + let curFrac = curSecTotal % 1 // Wee! let lenHour = Math.floor(lenSecTotal / 3600) let lenMin = Math.floor((lenSecTotal - lenHour * 3600) / 60) let lenSec = Math.floor(lenSecTotal - lenHour * 3600 - lenMin * 60) + let lenFrac = lenSecTotal % 1 const pad = val => val.toString().padStart(2, '0') + const padFrac = val => Math.floor(val * 1000).toString().padEnd(3, '0') curMin = pad(curMin) curSec = pad(curSec) lenMin = pad(lenMin) lenSec = pad(lenSec) leftMin = pad(leftMin) leftSec = pad(leftSec) + curFrac = padFrac(curFrac) + lenFrac = padFrac(lenFrac) + leftFrac = padFrac(leftFrac) // We don't want to display hour counters if the total length is less // than an hour. let timeDone, timeLeft, duration - if (parseInt(lenHour) > 0) { + if (parseInt(lenHour) > 0 || parseInt(curHour) > 0) { timeDone = `${curHour}:${curMin}:${curSec}` timeLeft = `${leftHour}:${leftMin}:${leftSec}` duration = `${lenHour}:${lenMin}:${lenSec}` @@ -191,6 +198,12 @@ module.exports.getTimeStringsFromSec = function(curSecTotal, lenSecTotal) { duration = `${lenMin}:${lenSec}` } + if (fraction) { + timeDone += '.' + curFrac + timeLeft += '.' + leftFrac + duration += '.' + lenFrac + } + return {percentDone, timeDone, timeLeft, duration, curSecTotal, lenSecTotal} } -- cgit 1.3.0-6-gf8a5