From 30faeb73d222a85b38ef5e25abbe882944e539f7 Mon Sep 17 00:00:00 2001 From: Michcio Date: Sun, 25 Sep 2022 15:46:11 +0200 Subject: [PATCH] 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) --- packages/backend/src/misc/gen-id.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/misc/gen-id.ts b/packages/backend/src/misc/gen-id.ts index 641182c14..b3a808f0a 100644 --- a/packages/backend/src/misc/gen-id.ts +++ b/packages/backend/src/misc/gen-id.ts @@ -7,8 +7,8 @@ import * as crypto from 'node:crypto'; const TIME2000 = 946684800000; let counter = crypto.randomBytes(2).readUInt16LE(0); -export function genId(date?: Date = new Date()): string { - let t = Math.min(date, new Date()); +export function genId(date: Date = new Date()): string { + let t = Math.min(date.valueOf(), new Date().valueOf()); t -= TIME2000; if (t < 0) t = 0; if (isNaN(t)) throw new Error('Failed to create AID: Invalid Date');