It doesn't appear to be one of the supported formats: http://momentjs.com/docs/#/durations/
There aren't any shortage of github repos that solve it with regex (as you saw, based on the links you provided). This solves it without using Date. Is there even a need for moment?
var regex = /P((([0-9]*\.?[0-9]*)Y)?(([0-9]*\.?[0-9]*)M)?(([0-9]*\.?[0-9]*)W)?(([0-9]*\.?[0-9]*)D)?)?(T(([0-9]*\.?[0-9]*)H)?(([0-9]*\.?[0-9]*)M)?(([0-9]*\.?[0-9]*)S)?)?/
minutesFromIsoDuration = function(duration) {
var matches = duration.match(regex);
return parseFloat(matches[14]) || 0;
}
If you test it:
minutesFromIsoDuration("PT120S");
0
minutesFromIsoDuration("PT5M");
5
If you want the logical duration in minutes, you might get away with:
return moment.duration({
years: parseFloat(matches[3]),
months: parseFloat(matches[5]),
weeks: parseFloat(matches[7]),
days: parseFloat(matches[9]),
hours: parseFloat(matches[12]),
minutes: parseFloat(matches[14]),
seconds: parseFloat(matches[16])
});
followed by
result.as("minutes");