From 7efa87eac87c6da7b4416750ae4f32d3f2543af8 Mon Sep 17 00:00:00 2001 From: Vishnu Narayanan Date: Fri, 23 Feb 2024 13:56:49 +0530 Subject: [PATCH 1/4] chore: refactor method to return empty if time is null --- src/helpers.ts | 2 +- test/helpers.test.ts | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/helpers.ts b/src/helpers.ts index 8dcd591..f00b9b6 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -113,7 +113,7 @@ export const convertSecondsToTimeUnit = ( unitNames: { minute: string; hour: string; day: string } ) => { if (seconds === null || seconds === 0) - return { time: null, unit: unitNames.minute }; + return { time: '', unit: ''}; if (seconds < 3600) return { time: Number((seconds / 60).toFixed(1)), unit: unitNames.minute }; if (seconds < 86400) diff --git a/test/helpers.test.ts b/test/helpers.test.ts index ce7488f..6e08130 100644 --- a/test/helpers.test.ts +++ b/test/helpers.test.ts @@ -43,4 +43,14 @@ describe('#convertSecondsToTimeUnit', () => { }) ).toEqual({ time: 1, unit: 'Days' }); }); + it("it should return { time: '', unit: '' } if seconds passed is 0", () => { + expect( + convertSecondsToTimeUnit(0, { minute: 'm', hour: 'h', day: 'd' }) + ).toEqual({ time: 1, unit: 's' }); + }); + it("it should return { time: '', unit: '' } if seconds passed is null", () => { + expect( + convertSecondsToTimeUnit(null, { minute: 'm', hour: 'h', day: 'd' }) + ).toEqual({ time: 1, unit: 's' }); + }); }); From cc2dbfa27d1eab58774184ed91e9d8aff2bdb250 Mon Sep 17 00:00:00 2001 From: Vishnu Narayanan Date: Fri, 23 Feb 2024 14:00:17 +0530 Subject: [PATCH 2/4] chore: refactor --- src/helpers.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/helpers.ts b/src/helpers.ts index f00b9b6..a0cb504 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -112,8 +112,7 @@ export const convertSecondsToTimeUnit = ( seconds: number, unitNames: { minute: string; hour: string; day: string } ) => { - if (seconds === null || seconds === 0) - return { time: '', unit: ''}; + if (seconds === null || seconds === 0) return { time: '', unit: '' }; if (seconds < 3600) return { time: Number((seconds / 60).toFixed(1)), unit: unitNames.minute }; if (seconds < 86400) From 17d1a415e4cbcaf47abc80b46e760e2ae5469935 Mon Sep 17 00:00:00 2001 From: Vishnu Narayanan Date: Fri, 23 Feb 2024 14:04:33 +0530 Subject: [PATCH 3/4] chore: fix spec --- test/helpers.test.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/helpers.test.ts b/test/helpers.test.ts index 6e08130..379adba 100644 --- a/test/helpers.test.ts +++ b/test/helpers.test.ts @@ -48,9 +48,4 @@ describe('#convertSecondsToTimeUnit', () => { convertSecondsToTimeUnit(0, { minute: 'm', hour: 'h', day: 'd' }) ).toEqual({ time: 1, unit: 's' }); }); - it("it should return { time: '', unit: '' } if seconds passed is null", () => { - expect( - convertSecondsToTimeUnit(null, { minute: 'm', hour: 'h', day: 'd' }) - ).toEqual({ time: 1, unit: 's' }); - }); }); From b6082e6439c7a14087666177f3ece52c14260603 Mon Sep 17 00:00:00 2001 From: Vishnu Narayanan Date: Wed, 3 Apr 2024 19:49:14 +1100 Subject: [PATCH 4/4] chore: fix spec --- test/helpers.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/helpers.test.ts b/test/helpers.test.ts index 379adba..36db1e2 100644 --- a/test/helpers.test.ts +++ b/test/helpers.test.ts @@ -46,6 +46,6 @@ describe('#convertSecondsToTimeUnit', () => { it("it should return { time: '', unit: '' } if seconds passed is 0", () => { expect( convertSecondsToTimeUnit(0, { minute: 'm', hour: 'h', day: 'd' }) - ).toEqual({ time: 1, unit: 's' }); + ).toEqual({ time: '', unit: '' }); }); });