diff --git a/hooks/__tests__/useMsToTime.tests.ts b/hooks/__tests__/useMsToTime.tests.ts index ecb7552..7ab527c 100644 --- a/hooks/__tests__/useMsToTime.tests.ts +++ b/hooks/__tests__/useMsToTime.tests.ts @@ -25,4 +25,9 @@ describe('useMsToTime unit tests', () => { const minutes = useMsToTime(1335000) expect(minutes).toBe('22:15') }) + + it('given 6443000 ms, should return 01:47:23', () => { + const minutes = useMsToTime(6443000) + expect(minutes).toBe('01:47:23') + }) }) diff --git a/hooks/useMsToTime.ts b/hooks/useMsToTime.ts index 136c48e..2532bab 100644 --- a/hooks/useMsToTime.ts +++ b/hooks/useMsToTime.ts @@ -8,8 +8,15 @@ export function useMsToTime(s: number) { const secs = s % 60 s = (s - secs) / 60 const mins = s % 60 + s = (s - mins) / 60 + const hour = s + const hourString = formatToString(hour) const minsString = formatToString(mins) const secsString = formatToString(secs) - return minsString + ':' + secsString + if (s === 0) { + return minsString + ':' + secsString + } else { + return hourString + ':' + minsString + ':' + secsString + } }