From 5f38d9dca2c93f9527eb1d1014e13d4631f17eff Mon Sep 17 00:00:00 2001 From: Deluan Date: Wed, 26 Oct 2022 09:09:04 -0400 Subject: [PATCH] Fix 60 seconds (again). Fixes #1956 --- ui/src/utils/formatters.js | 3 ++- ui/src/utils/formatters.test.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ui/src/utils/formatters.js b/ui/src/utils/formatters.js index f7c658e40..a4de54bbd 100644 --- a/ui/src/utils/formatters.js +++ b/ui/src/utils/formatters.js @@ -11,10 +11,11 @@ export const formatBytes = (bytes, decimals = 2) => { } export const formatDuration = (d) => { + d = Math.round(d) const days = Math.floor(d / 86400) const hours = Math.floor(d / 3600) % 24 const minutes = Math.floor(d / 60) % 60 - const seconds = Math.round(d % 60) + const seconds = Math.floor(d % 60) const f = [hours, minutes, seconds] .map((v) => v.toString()) .map((v) => (v.length !== 2 ? '0' + v : v)) diff --git a/ui/src/utils/formatters.test.js b/ui/src/utils/formatters.test.js index c4102fb92..0b853e728 100644 --- a/ui/src/utils/formatters.test.js +++ b/ui/src/utils/formatters.test.js @@ -19,7 +19,7 @@ describe('formatDuration', () => { it('formats seconds', () => { expect(formatDuration(0)).toEqual('00:00') expect(formatDuration(59)).toEqual('00:59') - expect(formatDuration(59.99)).toEqual('00:60') + expect(formatDuration(59.99)).toEqual('01:00') }) it('formats days, hours and minutes', () => {