Skip to content

Commit

Permalink
fix: ignore negative system clock adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
kripod committed Sep 28, 2021
1 parent 4c68c15 commit 2161e35
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/_common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export function uuidv7Builder(
let seq = 0;

return () => {
const timestamp = Date.now();
// Negative system clock adjustments are ignored to keep monotonicity
const timestamp = Math.max(Date.now(), prevTimestamp);
seq = timestamp === prevTimestamp ? seq + 1 : 0;
prevTimestamp = timestamp;

Expand Down

0 comments on commit 2161e35

Please sign in to comment.