backend: Fix type errors in genId
I checked on NodeJS locally and `Math.min` was coercing the Dates to numbers, I'm just making it more obvious (to the typechecker as well)
This commit is contained in:
parent
a91bbed34e
commit
30faeb73d2
1 changed files with 2 additions and 2 deletions
|
@ -7,8 +7,8 @@ import * as crypto from 'node:crypto';
|
||||||
const TIME2000 = 946684800000;
|
const TIME2000 = 946684800000;
|
||||||
let counter = crypto.randomBytes(2).readUInt16LE(0);
|
let counter = crypto.randomBytes(2).readUInt16LE(0);
|
||||||
|
|
||||||
export function genId(date?: Date = new Date()): string {
|
export function genId(date: Date = new Date()): string {
|
||||||
let t = Math.min(date, new Date());
|
let t = Math.min(date.valueOf(), new Date().valueOf());
|
||||||
t -= TIME2000;
|
t -= TIME2000;
|
||||||
if (t < 0) t = 0;
|
if (t < 0) t = 0;
|
||||||
if (isNaN(t)) throw new Error('Failed to create AID: Invalid Date');
|
if (isNaN(t)) throw new Error('Failed to create AID: Invalid Date');
|
||||||
|
|
Loading…
Reference in a new issue