mirror of
https://github.com/Mastermindzh/tidal-hifi.git
synced 2025-08-05 12:26:41 +02:00
15 lines
449 B
TypeScript
15 lines
449 B
TypeScript
/**
|
|
* Convert a HH:MM:SS string (or variants such as MM:SS or SS) to plain seconds
|
|
* @param duration in HH:MM:SS format
|
|
* @returns number of seconds in duration
|
|
*/
|
|
export const convertDurationToSeconds = (duration: string) => {
|
|
return duration
|
|
.split(":")
|
|
.reverse()
|
|
.map((val) => Number(val))
|
|
.reduce((previous, current, index) => {
|
|
return index === 0 ? current : previous + current * Math.pow(60, index);
|
|
}, 0);
|
|
};
|