1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | function toMS(input) { const sRegex = /\d+s/g; const msRegex = /\d+ms/g; const usRegex = /\d+us/g; Logger.log("Running toMS with parameter: " + input); var sToMs = 0; var msToMs = 0; var usToMs = 0; while((seg = sRegex.exec(input)) !== null) { sToMs += parseInt(seg) * 1000; } while((seg = msRegex.exec(input)) !== null) { msToMs += parseInt(seg); } while((seg = usRegex.exec(input)) !== null) { usToMs += parseInt(seg) / 1000; } usToMs += msToMs + sToMs; return usToMs; } function toUS(input) { return toMS(input) * 1000; } |