From: Jérôme Benoit Date: Wed, 8 Nov 2023 17:39:42 +0000 (+0100) Subject: fix(simulator): handle close to zero duration formatting X-Git-Tag: v1.2.24~31 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=17b07e476ae779024c63bf175da8dda655845d32;p=e-mobility-charging-stations-simulator.git fix(simulator): handle close to zero duration formatting Signed-off-by: Jérôme Benoit --- diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7f248e8a..cc83468e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2718,7 +2718,7 @@ packages: '@istanbuljs/schema': 0.1.3 find-up: 5.0.0 foreground-child: 2.0.0 - istanbul-lib-coverage: 3.2.1 + istanbul-lib-coverage: 3.2.2 istanbul-lib-report: 3.0.1 istanbul-reports: 3.1.6 rimraf: 3.0.2 @@ -6011,8 +6011,8 @@ packages: lodash.uniqby: 4.7.0 dev: true - /istanbul-lib-coverage@3.2.1: - resolution: {integrity: sha512-opCrKqbthmq3SKZ10mFMQG9dk3fTa3quaOLD35kJa5ejwZHd9xAr+kLuziiZz2cG32s4lMZxNdmdcEQnTDP4+g==} + /istanbul-lib-coverage@3.2.2: + resolution: {integrity: sha512-O8dpsF+r0WV/8MNRKfnmrtCWhuKjxrq2w+jpzBL5UZKTi2LeVWnWOmWRxFlesJONmc+wLAGvKQZEOanko0LFTg==} engines: {node: '>=8'} dev: true @@ -6020,7 +6020,7 @@ packages: resolution: {integrity: sha512-GCfE1mtsHGOELCU8e/Z7YWzpmybrx/+dSTfLrvY8qRmaY6zXTKWn6WQIjaAFw069icm6GVMNkgu0NzI4iPZUNw==} engines: {node: '>=10'} dependencies: - istanbul-lib-coverage: 3.2.1 + istanbul-lib-coverage: 3.2.2 make-dir: 4.0.0 supports-color: 7.2.0 dev: true diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index 6a3d30fe..6d8c2228 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -37,6 +37,9 @@ export const sleep = async (milliSeconds: number): Promise => { 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( @@ -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 => { diff --git a/ui/web/package.json b/ui/web/package.json index 8c94bd8f..a4b864a9 100644 --- a/ui/web/package.json +++ b/ui/web/package.json @@ -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", diff --git a/ui/web/pnpm-lock.yaml b/ui/web/pnpm-lock.yaml index ddfac46c..221e1f05 100644 --- a/ui/web/pnpm-lock.yaml +++ b/ui/web/pnpm-lock.yaml @@ -38,8 +38,8 @@ devDependencies: specifier: ^6.10.0 version: 6.10.0(eslint@8.53.0)(typescript@5.2.2) '@vitejs/plugin-vue': - specifier: ^4.4.0 - version: 4.4.0(vite@4.5.0)(vue@3.3.8) + specifier: ^4.4.1 + version: 4.4.1(vite@4.5.0)(vue@3.3.8) '@vitejs/plugin-vue-jsx': specifier: ^3.0.2 version: 3.0.2(vite@4.5.0)(vue@3.3.8) @@ -957,8 +957,8 @@ packages: - supports-color dev: true - /@vitejs/plugin-vue@4.4.0(vite@4.5.0)(vue@3.3.8): - resolution: {integrity: sha512-xdguqb+VUwiRpSg+nsc2HtbAUSGak25DXYvpQQi4RVU1Xq1uworyoH/md9Rfd8zMmPR/pSghr309QNcftUVseg==} + /@vitejs/plugin-vue@4.4.1(vite@4.5.0)(vue@3.3.8): + resolution: {integrity: sha512-HCQG8VDFDM7YDAdcj5QI5DvUi+r6xvo9LgvYdk7LSkUNwdpempdB5horkMSZsbdey9Ywsf5aaU8kEPw9M5kREA==} engines: {node: ^14.18.0 || >=16.0.0} peerDependencies: vite: ^4.0.0 @@ -975,7 +975,7 @@ packages: dependencies: '@ampproject/remapping': 2.2.1 '@bcoe/v8-coverage': 0.2.3 - istanbul-lib-coverage: 3.2.1 + istanbul-lib-coverage: 3.2.2 istanbul-lib-report: 3.0.1 istanbul-lib-source-maps: 4.0.1 istanbul-reports: 3.1.6 @@ -2731,8 +2731,8 @@ packages: resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} dev: true - /istanbul-lib-coverage@3.2.1: - resolution: {integrity: sha512-opCrKqbthmq3SKZ10mFMQG9dk3fTa3quaOLD35kJa5ejwZHd9xAr+kLuziiZz2cG32s4lMZxNdmdcEQnTDP4+g==} + /istanbul-lib-coverage@3.2.2: + resolution: {integrity: sha512-O8dpsF+r0WV/8MNRKfnmrtCWhuKjxrq2w+jpzBL5UZKTi2LeVWnWOmWRxFlesJONmc+wLAGvKQZEOanko0LFTg==} engines: {node: '>=8'} dev: true @@ -2740,7 +2740,7 @@ packages: resolution: {integrity: sha512-GCfE1mtsHGOELCU8e/Z7YWzpmybrx/+dSTfLrvY8qRmaY6zXTKWn6WQIjaAFw069icm6GVMNkgu0NzI4iPZUNw==} engines: {node: '>=10'} dependencies: - istanbul-lib-coverage: 3.2.1 + istanbul-lib-coverage: 3.2.2 make-dir: 4.0.0 supports-color: 7.2.0 dev: true @@ -2750,7 +2750,7 @@ packages: engines: {node: '>=10'} dependencies: debug: 4.3.4 - istanbul-lib-coverage: 3.2.1 + istanbul-lib-coverage: 3.2.2 source-map: 0.6.1 transitivePeerDependencies: - supports-color