My best guess would be to transform it into seconds and then let coda do the calculation on the backend to transform that into a duration type?
Dear goodness I have no idea how to do that
EDIT: Maybe I do
Heres what I went for:
let durationRaw = "PT1H30M15S";
let myRegex = /(-)?P(?:([.,\d]+)Y)?(?:([.,\d]+)M)?(?:([.,\d]+)W)?(?:([.,\d]+)D)?T(?:([.,\d]+)H)?(?:([.,\d]+)M)?(?:([.,\d]+)S)?/
let replaceAll = function (iso8601Duration) {
var matches = iso8601Duration.match(myRegex);
return {
sign: matches[1] === undefined ? '+' : '-',
years: matches[2] === undefined ? 0 : matches[2],
months: matches[3] === undefined ? 0 : matches[3],
weeks: matches[4] === undefined ? 0 : matches[4],
days: matches[5] === undefined ? 0 : matches[5],
hours: matches[6] === undefined ? 0 : matches[6],
minutes: matches[7] === undefined ? 0 : matches[7],
seconds: matches[8] === undefined ? 0 : matches[8]
};
};
let myRanFunction = replaceAll(durationRaw)
let days = parseInt(myRanFunction.days, 10)
let hours = parseInt(myRanFunction.hours, 10)
let minutes = parseInt(myRanFunction.minutes, 10)
let seconds = parseInt(myRanFunction.seconds, 10)
let intoSeconds = (days*86400)+(hours*3600)+(minutes*60)+seconds;
console.log(`${intoSeconds} seconds`);
Can anyone help me out to let me know if this is fine? Or do you think I will run into issues? It was a mix of googling, then throwing together other random stuff and running the code over and over until it started working
So glad you shared this post, Scott. I saw that Youtube just changed their durations to 8601 and I need to update. Also, thanks @Connor_McCormick1 for a simple solution!