From eb523c739dc252a61fc6999d1f653038d82447b0 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Tue, 26 Sep 2023 19:24:55 -0400 Subject: [PATCH] fix(striker-ui): correct elapsed calculation in time helpers --- striker-ui/lib/time.ts | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/striker-ui/lib/time.ts b/striker-ui/lib/time.ts index 146dc2e5..cd38c03f 100644 --- a/striker-ui/lib/time.ts +++ b/striker-ui/lib/time.ts @@ -7,7 +7,7 @@ const before = (time: number, limit: number): boolean => { const now = (ms?: boolean): number => { let nao = Date.now(); - if (!ms) nao /= 1000; + if (!ms) nao = Math.floor(nao / 1000); return nao; }; @@ -24,14 +24,9 @@ const last = ( const elapsed = ( duration: number, - { ms }: { ms?: boolean } = {}, ): { h: number; m: number; s: number; unit: string; value: number } => { let src = duration; - if (!ms) { - src /= 1000; - } - const parts = [60, 60].reduce((previous, multiplier) => { const remainder = src % multiplier; @@ -47,14 +42,7 @@ const elapsed = ( const significant = [ { unit: 'h', value: h }, { unit: 'm', value: m }, - ].reduce( - (previous, current) => { - const { value } = current; - - return value ? current : previous; - }, - { unit: 's', value: s }, - ); + ].find(({ value }) => value) ?? { unit: 's', value: s }; return { h,