fix(striker-ui): correct elapsed calculation in time helpers

main
Tsu-ba-me 1 year ago
parent 5e0f5133e7
commit eb523c739d
  1. 16
      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<number[]>((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,

Loading…
Cancel
Save