fix(striker-ui): isolate now function in time helpers

main
Tsu-ba-me 1 year ago
parent 813767f85a
commit 5e0f5133e7
  1. 18
      striker-ui/lib/time.ts

@ -4,18 +4,20 @@ const before = (time: number, limit: number): boolean => {
return diff > 0; return diff > 0;
}; };
const now = (ms?: boolean): number => {
let nao = Date.now();
if (!ms) nao /= 1000;
return nao;
};
const last = ( const last = (
time: number, time: number,
duration: number, duration: number,
{ ms }: { ms?: boolean } = {}, { ms }: { ms?: boolean } = {},
): boolean => { ): boolean => {
let now = Date.now(); const diff = now(ms) - time;
if (!ms) {
now /= 1000;
}
const diff = now - time;
return diff <= duration; return diff <= duration;
}; };
@ -62,4 +64,4 @@ const elapsed = (
}; };
}; };
export { before, elapsed, last }; export { before, elapsed, last, now };

Loading…
Cancel
Save