From f2c8ae6854558a1c5223362f28be42c23fd6d37a Mon Sep 17 00:00:00 2001 From: Peter Date: Sat, 26 Aug 2023 23:46:44 +0200 Subject: [PATCH] fix bug that shows 1 h 60 min instead of 2 h --- src/Converters.ts | 1 + test/Converters.test.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/Converters.ts b/src/Converters.ts index 89fe61c3..361c7e46 100644 --- a/src/Converters.ts +++ b/src/Converters.ts @@ -6,6 +6,7 @@ export function milliSecondsToText(ms: number) { const hours = Math.floor(ms / 3600000) const minutes = Math.round((ms % 3600000) / 60000) + if (minutes == 60) return hours + 1 + ' h' const hourText = hours > 0 ? hours + ' h' : '' if (minutes == 0 && hourText.length > 0) return hourText return (hourText ? hourText + ' ' : '') + minutes + ' min' diff --git a/test/Converters.test.ts b/test/Converters.test.ts index 6a6a94b9..96a3c762 100644 --- a/test/Converters.test.ts +++ b/test/Converters.test.ts @@ -6,6 +6,8 @@ describe('Converters', function () { expect(milliSecondsToText(59 * 1000)).toEqual('1 min') expect(milliSecondsToText(63 * 60 * 1000)).toEqual('1 h 3 min') + + expect(milliSecondsToText(7198000)).toEqual('2 h') }) })