« get me outta code hell

timestamp files!!! - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
path: root/general-util.js
diff options
context:
space:
mode:
author(quasar) nebula <towerofnix@gmail.com>2021-07-13 23:14:20 -0300
committer(quasar) nebula <towerofnix@gmail.com>2021-07-13 23:14:20 -0300
commit382d5afc7e2ac24f67b7c891328b8b9bb7e91058 (patch)
tree87d97b4e20e48d936b33ef2ced898227af29a2e0 /general-util.js
parent80577b066352fe2dfecd706302e183a5705c193b (diff)
timestamp files!!!
Diffstat (limited to 'general-util.js')
-rw-r--r--general-util.js10
1 files changed, 10 insertions, 0 deletions
diff --git a/general-util.js b/general-util.js
index 0a81cdc..f63ae21 100644
--- a/general-util.js
+++ b/general-util.js
@@ -139,6 +139,16 @@ module.exports.throttlePromise = function(maximumAtOneTime = 10) {
   return enqueue
 }
 
+module.exports.getSecFromTimestamp = function(timestamp) {
+  const parts = timestamp.split(':').map(n => parseInt(n))
+  switch (parts.length) {
+    case 3: return parts[0] * 3600 + parts[1] * 60 + parts[2]
+    case 2: return parts[0] * 60 + parts[1]
+    case 1: return parts[0]
+    default: return 0
+  }
+}
+
 module.exports.getTimeStringsFromSec = function(curSecTotal, lenSecTotal) {
   const percentVal = (100 / lenSecTotal) * curSecTotal
   const percentDone = (