Created
June 15, 2021 00:03
-
-
Save sweeneyapps/2cfbfd1594e9f6f65b7c484a327fc4b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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