You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
spa_instat_tv/src/helpers/secondsToHms/index.tsx

16 lines
482 B

const prependZero = (value: number | string) => (
`0${value}`.slice(-2)
)
/**
* Форматирует секунды в hh:mm:ss
*/
export const secondsToHms = (seconds: number) => {
const hours = prependZero(Math.floor(seconds / 3600))
const minutes = prependZero(Math.floor(seconds % 3600 / 60))
const secondsStr = prependZero(Math.floor(seconds % 3600 % 60))
if (Number(hours) > 0) return `${hours}:${minutes}:${secondsStr}`
return `${minutes}:${secondsStr}`
}