Fix bug in duration format logic (#2026)

This commit is contained in:
Robert Sammelson 2022-12-03 20:31:02 -05:00 committed by GitHub
parent 68ceeb9ea1
commit c4d1569441
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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')
})
})