Skip to content

Commit

Permalink
chore: refactor method to return empty if time is null (#30)
Browse files Browse the repository at this point in the history
* chore: refactor method to return empty if time is null

* chore: refactor

* chore: fix spec

* chore: fix spec
  • Loading branch information
vishnu-narayanan committed Apr 3, 2024
1 parent 1a13aa1 commit 836dada
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/helpers.ts
Expand Up @@ -112,8 +112,7 @@ export const convertSecondsToTimeUnit = (
seconds: number,
unitNames: { minute: string; hour: string; day: string }
) => {
if (seconds === null || seconds === 0)
return { time: null, unit: unitNames.minute };
if (seconds === null || seconds === 0) return { time: '', unit: '' };
if (seconds < 3600)
return { time: Number((seconds / 60).toFixed(1)), unit: unitNames.minute };
if (seconds < 86400)
Expand Down
5 changes: 5 additions & 0 deletions test/helpers.test.ts
Expand Up @@ -43,4 +43,9 @@ 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: '', unit: '' });
});
});

0 comments on commit 836dada

Please sign in to comment.