Skip to content

Commit

Permalink
fix bug that shows 1 h 60 min instead of 2 h
Browse files Browse the repository at this point in the history
  • Loading branch information
karussell committed Aug 26, 2023
1 parent 624625a commit f2c8ae6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 2 additions & 0 deletions test/Converters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})

Expand Down

0 comments on commit f2c8ae6

Please sign in to comment.