Skip to content

Commit

Permalink
fix(simulator): handle close to zero duration formatting
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 b3b3f0e commit 17b07e4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions src/utils/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export const sleep = async (milliSeconds: number): Promise<NodeJS.Timeout> => {

export const formatDurationMilliSeconds = (duration: number): string => {
duration = convertToInt(duration);
if (duration < 0) {
throw new RangeError('Duration cannot be negative');
}
const days = Math.floor(duration / (24 * 3600 * 1000));
const hours = Math.floor(millisecondsToHours(duration) - days * 24);
const minutes = Math.floor(
Expand All @@ -48,12 +51,15 @@ export const formatDurationMilliSeconds = (duration: number): string => {
hoursToSeconds(hours) -
minutesToSeconds(minutes),
);
return formatDuration({
days,
hours,
minutes,
seconds,
});
return formatDuration(
{
days,
hours,
minutes,
seconds,
},
{ zero: true },
);
};

export const formatDurationSeconds = (duration: number): string => {
Expand Down
2 changes: 1 addition & 1 deletion ui/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@types/node": "^20.9.0",
"@typescript-eslint/eslint-plugin": "^6.10.0",
"@typescript-eslint/parser": "^6.10.0",
"@vitejs/plugin-vue": "^4.4.0",
"@vitejs/plugin-vue": "^4.4.1",
"@vitejs/plugin-vue-jsx": "^3.0.2",
"@vitest/coverage-v8": "^0.34.6",
"@vue/eslint-config-prettier": "^8.0.0",
Expand Down
18 changes: 9 additions & 9 deletions ui/web/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 17b07e4

Please sign in to comment.