It would be really handy to be able to get the totalSeconds, totalMinutes, etc. from a duration.
const { totalSeconds } = parse(duration)
I have a use case for this where we're normalizing the length of different media to seconds and one of the formats is an ISO duration. Currently I have to parse the duration, then convert all the components to seconds then add them up.
const durationToSeconds = (duration: string): number => {
const parsed = parse(duration)
const totalSeconds =
(parsed.hours ?? 0) * 3600 +
(parsed.minutes ?? 0) * 60 +
(parsed.seconds ?? 0)
return totalSeconds ?? 0
}
It would be really handy to be able to get the
totalSeconds,totalMinutes, etc. from a duration.I have a use case for this where we're normalizing the length of different media to seconds and one of the formats is an ISO duration. Currently I have to parse the duration, then convert all the components to seconds then add them up.