Skip to content

Commit

Permalink
core: fix object-id is sometimes less than 24 chars in length (street…
Browse files Browse the repository at this point in the history
  • Loading branch information
dyw770 authored Dec 6, 2024
1 parent 0ffbf83 commit a78a2e4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/core/src/utils/object-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

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);
Expand All @@ -40,4 +41,4 @@ function swap16(val: number) {

export function getObjectIdTimestamp(id: string) {
return new Date(parseInt(id.substring(0, 8), 16) * 1000);
}
}

0 comments on commit a78a2e4

Please sign in to comment.