fix(simulator): format properly duration close to zero
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 8 Nov 2023 18:52:05 +0000 (19:52 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 8 Nov 2023 18:52:05 +0000 (19:52 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/utils/Utils.ts
tests/utils/Utils.test.ts

index 6d8c2228b546abaffb220263ace48f17d370f9a3..ca4d2fa996c661eef86ab9d404a5cf3e25d979b7 100644 (file)
@@ -51,15 +51,15 @@ export const formatDurationMilliSeconds = (duration: number): string => {
       hoursToSeconds(hours) -
       minutesToSeconds(minutes),
   );
-  return formatDuration(
-    {
-      days,
-      hours,
-      minutes,
-      seconds,
-    },
-    { zero: true },
-  );
+  if (days === 0 && hours === 0 && minutes === 0 && seconds === 0) {
+    return formatDuration({ seconds }, { zero: true });
+  }
+  return formatDuration({
+    days,
+    hours,
+    minutes,
+    seconds,
+  });
 };
 
 export const formatDurationSeconds = (duration: number): string => {
index 60170cf9ecf0df19e53daa3e54506f649b402ee3..82964803b87e0f4913a9929dc8125dc7e04d4420 100644 (file)
@@ -58,13 +58,15 @@ await describe('Utils test suite', async () => {
   });
 
   await it('Verify formatDurationMilliSeconds()', () => {
-    expect(formatDurationMilliSeconds(0)).toBe('');
+    expect(formatDurationMilliSeconds(0)).toBe('0 seconds');
+    expect(formatDurationMilliSeconds(900)).toBe('0 seconds');
     expect(formatDurationMilliSeconds(1000)).toBe('1 second');
     expect(formatDurationMilliSeconds(hoursToMilliseconds(4380))).toBe('182 days 12 hours');
   });
 
   await it('Verify formatDurationSeconds()', () => {
-    expect(formatDurationSeconds(0)).toBe('');
+    expect(formatDurationSeconds(0)).toBe('0 seconds');
+    expect(formatDurationSeconds(0.9)).toBe('0 seconds');
     expect(formatDurationSeconds(1)).toBe('1 second');
     expect(formatDurationSeconds(hoursToSeconds(4380))).toBe('182 days 12 hours');
   });