From 23ee6a29511e82b3a7b4325d177ac8d22d0692d8 Mon Sep 17 00:00:00 2001 From: Sean Date: Wed, 1 Jul 2020 17:40:57 +0200 Subject: [PATCH] Allow negative duration Allow negative values for durationToString. The use case is fairly constructed, but now logically correct --- client/src/app/core/ui-services/duration.service.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/src/app/core/ui-services/duration.service.ts b/client/src/app/core/ui-services/duration.service.ts index 3647f2e1e..0a9fa84fe 100644 --- a/client/src/app/core/ui-services/duration.service.ts +++ b/client/src/app/core/ui-services/duration.service.ts @@ -88,10 +88,11 @@ export class DurationService { * @returns a more human readable time representation */ public durationToString(duration: number, suffix: 'h' | 'm'): string { - const major = Math.floor(duration / 60); + const major = duration < 0 ? Math.ceil(duration / 60) : Math.floor(duration / 60); const minor = `0${duration % 60}`.slice(-2); if (!isNaN(+major) && !isNaN(+minor)) { - return `${major}:${minor} ${suffix}`; + // converting the number '-0' to string results in '0' + return `${major === -0 ? '-' + major : major}:${minor} ${suffix}`; } else { return ''; }