Fix bug in duration format logic (#2026)

This commit is contained in:
Robert Sammelson 2022-12-03 20:31:02 -05:00 committed by Joe Stump
parent 6d1eb06b9e
commit eb6b407a34
No known key found for this signature in database
GPG Key ID: 29151C3EC48A0EB9
2 changed files with 3 additions and 1 deletions

View File

@ -19,7 +19,7 @@ export const formatDuration = (d) => {
const f = [hours, minutes, seconds]
.map((v) => v.toString())
.map((v) => (v.length !== 2 ? '0' + v : v))
.filter((v, i) => v !== '00' || i > 0)
.filter((v, i) => v !== '00' || i > 0 || days > 0)
.join(':')
return `${days > 0 ? days + ':' : ''}${f}`

View File

@ -27,5 +27,7 @@ describe('formatDuration', () => {
expect(formatDuration(3 * day + 3 * hour + 7 * minute)).toEqual(
'3:03:07:00'
)
expect(formatDuration(day)).toEqual('1:00:00:00')
expect(formatDuration(day + minute + 0.6)).toEqual('1:00:01:01')
})
})