Skip to content

Instantly share code, notes, and snippets.

@sweeneyapps
Created June 15, 2021 00:03
Show Gist options
  • Save sweeneyapps/2cfbfd1594e9f6f65b7c484a327fc4b7 to your computer and use it in GitHub Desktop.
Save sweeneyapps/2cfbfd1594e9f6f65b7c484a327fc4b7 to your computer and use it in GitHub Desktop.
function convert(line) {
let timeMatch = /\1(\d\d):\2(\d\d),\3(\d+)\4([sm])/
if(timeMatch.test(line)) {
let arr = timeMatch.exec(line)
let min = Number(arr[1])
let sec = Number(arr[2])
let duration = Number(arr[3])
let time = arr[4]
let addMin = sec + duration > 59 ? 1 : 0
let subSec = addMin === 1 ? 60 : 0
return {
startTime: {
min,
sec
},
endTime: {
min: min + (time === 'm' ? duration : 0) + addMin,
sec: sec + (time === 's' ? duration : 0) - subSec
}
}
}
else return ''
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment