« get me outta code hell

Metadata (in memory) - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
path: root/players.js
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2019-02-25 11:27:11 -0400
committerFlorrie <towerofnix@gmail.com>2019-02-25 11:27:11 -0400
commit75251bb2309505c20dc7500117a17649d41412d8 (patch)
tree97c646cb2ccb224a456147aaec8c4a5854990bb5 /players.js
parent4eee44f7d92dcdf2c8bccea78723ba0b194eb2d7 (diff)
Metadata (in memory)
Diffstat (limited to 'players.js')
-rw-r--r--players.js41
1 files changed, 1 insertions, 40 deletions
diff --git a/players.js b/players.js
index e9cf76e..0c980e7 100644
--- a/players.js
+++ b/players.js
@@ -3,46 +3,7 @@
 const { spawn } = require('child_process')
 const FIFO = require('fifo-js')
 const EventEmitter = require('events')
-const { commandExists, killProcess } = require('./general-util')
-
-function getTimeStrings({curHour, curMin, curSec, lenHour, lenMin, lenSec}) {
-  // Multiplication casts to numbers; addition prioritizes strings.
-  // Thanks, JavaScript!
-  const curSecTotal = (3600 * curHour) + (60 * curMin) + (1 * curSec)
-  const lenSecTotal = (3600 * lenHour) + (60 * lenMin) + (1 * lenSec)
-  const percentVal = (100 / lenSecTotal) * curSecTotal
-  const percentDone = (
-    (Math.trunc(percentVal * 100) / 100).toFixed(2) + '%'
-  )
-
-  const leftSecTotal = lenSecTotal - curSecTotal
-  let leftHour = Math.floor(leftSecTotal / 3600)
-  let leftMin = Math.floor((leftSecTotal - leftHour * 3600) / 60)
-  let leftSec = Math.floor(leftSecTotal - leftHour * 3600 - leftMin * 60)
-
-  const pad = val => val.toString().padStart(2, '0')
-  curMin = pad(curMin)
-  curSec = pad(curSec)
-  lenMin = pad(lenMin)
-  lenSec = pad(lenSec)
-  leftMin = pad(leftMin)
-  leftSec = pad(leftSec)
-
-  // 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) {
-    timeDone = `${curHour}:${curMin}:${curSec}`
-    timeLeft = `${leftHour}:${leftMin}:${leftSec}`
-    duration = `${lenHour}:${lenMin}:${lenSec}`
-  } else {
-    timeDone = `${curMin}:${curSec}`
-    timeLeft = `${leftMin}:${leftSec}`
-    duration = `${lenMin}:${lenSec}`
-  }
-
-  return {percentDone, timeDone, timeLeft, duration, curSecTotal, lenSecTotal}
-}
+const { commandExists, killProcess, getTimeStrings } = require('./general-util')
 
 class Player extends EventEmitter {
   constructor() {