Last active
June 25, 2019 23:49
-
-
Save louismanson/f7ead68f38f3eab2ac2d5e54b97b6f17 to your computer and use it in GitHub Desktop.
ISO 8601 to seconds
This file contains hidden or 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
let iso8601toSeg = (duaration) => { | |
let mDuration = []; | |
let hours = duaration.match(/\d{1,2}[H]/); | |
let minutes = duaration.match(/\d{1,2}[M]/); | |
let seconds = duaration.match(/\d{1,2}[S]/); | |
mDuration['hours'] = hours ? hours[0] : "0H"; | |
mDuration['minutes'] = minutes ? minutes[0] : "0M"; | |
mDuration['seconds'] = seconds ? seconds[0] : "0S"; | |
let mHours = parseInt(mDuration['hours'].substr(0, mDuration['hours'].length-1)); | |
let mMinutes = parseInt(mDuration['minutes'].substr(0,mDuration['minutes'].length-1)); | |
let mSeconds = parseInt(mDuration['seconds'].substr(0, mDuration['seconds'].length-1)); | |
return toltalSeconds = (mHours * 60 * 60) + (mMinutes * 60) + mSeconds; | |
} | |
console.log(iso8601toSeg("PT15M35S")); //Returns a value of 935 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment