From a78a2e4ae203df6f205d807217482487b6dbce7e Mon Sep 17 00:00:00 2001 From: dyw770 Date: Fri, 6 Dec 2024 13:11:57 +0800 Subject: [PATCH] core: fix object-id is sometimes less than 24 chars in length (#6991) (#6994) Signed-off-by: dyw770 --- packages/core/src/utils/object-id.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/core/src/utils/object-id.ts b/packages/core/src/utils/object-id.ts index 8cab59bab0..969fa7f8b7 100644 --- a/packages/core/src/utils/object-id.ts +++ b/packages/core/src/utils/object-id.ts @@ -19,8 +19,9 @@ along with this program. If not, see . const MACHINE_ID = Math.floor(Math.random() * 0xffffff); const pid = Math.floor(Math.random() * 100000) % 0xffff; +const PROCESS_UNIQUE = MACHINE_ID.toString(16).padStart(6, "0") + pid.toString(16).padStart(4, "0"); let index = Math.floor(Math.random() * 0xffffff); -const PROCESS_UNIQUE = MACHINE_ID.toString(16) + pid.toString(16); + export function createObjectId(date = Date.now()): string { index++; const time = Math.floor(date / 1000); @@ -40,4 +41,4 @@ function swap16(val: number) { export function getObjectIdTimestamp(id: string) { return new Date(parseInt(id.substring(0, 8), 16) * 1000); -} +} \ No newline at end of file