Добавлена функция вывода длительности в формате ЧЧ:ММ:СС

This commit is contained in:
Александр Сироткин 2021-12-17 10:02:45 +05:00
parent cf7323ba5a
commit 99292bd80d

10
src/utils/datetime.ts Normal file
View File

@ -0,0 +1,10 @@
export const periodToString = (time?: number) => {
if (!time) return '00:00:00'
const hours = Math.floor(time / 3600)
const minutes = Math.floor(time / 60 - hours * 60)
const seconds = Math.floor(time - hours * 3600 - minutes * 60)
const toFixed = (num: number) => `${num}`.padStart(2, '0')
return `${toFixed(hours)}:${toFixed(minutes)}:${toFixed(seconds)}`
}