diff --git a/src/util/time.ts b/src/util/time.ts new file mode 100644 index 0000000..da32243 --- /dev/null +++ b/src/util/time.ts @@ -0,0 +1,14 @@ +import dayjs from 'dayjs'; +import relativeTime from 'dayjs/plugin/relativeTime.js'; +import pl from 'dayjs/locale/pl.js'; + +dayjs.extend(relativeTime); +dayjs.locale(pl); + + +export const msToTime = (duration: number) => { + const minutes = Math.floor((duration / (1000 * 60)) % 60); + const hours = Math.floor((duration / (1000 * 60 * 60)) % 24); + + return `${hours ? `${hours}h ` : ''}${minutes ? `${minutes}m` : ''}`; +} \ No newline at end of file