« get me outta code hell

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:
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 = (