From 0fa96499975febd88ba89769c222cd76b64bd109 Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Mon, 25 Dec 2023 14:20:31 +0500 Subject: [PATCH] core: fix invalid object-id generation for some timestamps --- packages/core/src/utils/object-id.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/core/src/utils/object-id.ts b/packages/core/src/utils/object-id.ts index 76a45ea64..a78b5ce9c 100644 --- a/packages/core/src/utils/object-id.ts +++ b/packages/core/src/utils/object-id.ts @@ -24,7 +24,14 @@ let index = ~~(randomInt() * 0xffffff); export function createObjectId(date = Date.now()): string { index++; const time = Math.floor(date / 1000); - return time.toString(16) + PROCESS_UNIQUE + swap16(index).toString(16); + + let timeHex = time.toString(16); + if (timeHex.length !== 8) timeHex = timeHex.padStart(2, "0").padEnd(8, "0"); + + let incHex = swap16(index).toString(16); + if (incHex.length !== 6) incHex = incHex.padStart(6, "0"); + + return timeHex + PROCESS_UNIQUE + incHex; } function swap16(val: number) {