Skip to content

Commit

Permalink
fix(simulator): format properly duration close to zero
Browse files Browse the repository at this point in the history
Signed-off-by: Jérôme Benoit <[email protected]>
  • Loading branch information
Jérôme Benoit committed Nov 8, 2023
1 parent 17b07e4 commit d7ceb0f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
18 changes: 9 additions & 9 deletions src/utils/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
6 changes: 4 additions & 2 deletions tests/utils/Utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand Down

0 comments on commit d7ceb0f

Please sign in to comment.