From 8e1f207b6aad5d41474031b668cbcff93b11fdf0 Mon Sep 17 00:00:00 2001 From: Levente Batuska Date: Thu, 5 Feb 2026 21:15:50 +0100 Subject: [PATCH] feat(uuid): add optional caller provided timestamp for v7 --- include/cpputils/uuid.h | 4 +++- src/uuid.cpp | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/cpputils/uuid.h b/include/cpputils/uuid.h index fb60e9f..070c550 100644 --- a/include/cpputils/uuid.h +++ b/include/cpputils/uuid.h @@ -5,6 +5,7 @@ #include #include #include +#include "cpputils/datetime.h" namespace cpputils { namespace uuid { @@ -46,7 +47,8 @@ class V7 { return timestamp; } - std::array generate(); + std::array generate( + int64_t timestamp = cpputils::datetime::now()); }; } // namespace uuid diff --git a/src/uuid.cpp b/src/uuid.cpp index c75802a..11ffbe1 100644 --- a/src/uuid.cpp +++ b/src/uuid.cpp @@ -88,9 +88,8 @@ uint8_t V7::next_sequence(int64_t current_timestamp) { } } -std::array V7::generate() { +std::array V7::generate(int64_t timestamp) { std::array uuid{}; - int64_t timestamp = cpputils::datetime::now(); uint8_t seq = next_sequence(timestamp); uint64_t rand_a = random64(); uint64_t rand_b = random64();