From d068d92ffaa050c5d2af68198bad6e977bf082eb Mon Sep 17 00:00:00 2001 From: Thomas Sanchez Date: Fri, 6 Feb 2026 15:29:12 +0100 Subject: [PATCH 1/3] fix: missing cstdint include --- lib/external/json11.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/external/json11.cpp b/lib/external/json11.cpp index 0b79fc9..61db3e6 100644 --- a/lib/external/json11.cpp +++ b/lib/external/json11.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include From 34ec420ed6e10e25682f8a81b6a41374a0b41d99 Mon Sep 17 00:00:00 2001 From: Thomas Sanchez Date: Mon, 9 Feb 2026 12:06:46 +0100 Subject: [PATCH 2/3] fix: DecodeBase64URL does not return anything --- lib/uid2base64urlcoder.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/uid2base64urlcoder.h b/lib/uid2base64urlcoder.h index fa835ba..73d9504 100644 --- a/lib/uid2base64urlcoder.h +++ b/lib/uid2base64urlcoder.h @@ -10,6 +10,6 @@ class UID2Base64UrlCoder { public: static std::string Encode(const std::vector& input) { return macaron::Base64::EncodeBase64URL(input); } - static void Decode(const std::string& input, std::vector& out) { return macaron::Base64::DecodeBase64URL(input, out); } + static void Decode(const std::string& input, std::vector& out) { macaron::Base64::DecodeBase64URL(input, out); } }; } // namespace uid2 From f77be9d42ef80c39920a35c678ca956f4dd05b7f Mon Sep 17 00:00:00 2001 From: Thomas Sanchez Date: Mon, 9 Feb 2026 13:22:44 +0100 Subject: [PATCH 3/3] chore: more idiomatic timestamp class --- include/uid2/timestamp.h | 25 +++++++++++++++---------- lib/timestamp.cpp | 2 +- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/include/uid2/timestamp.h b/include/uid2/timestamp.h index bdb6e3e..3860d18 100644 --- a/include/uid2/timestamp.h +++ b/include/uid2/timestamp.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -10,27 +11,31 @@ class Timestamp { static Timestamp Now(); static Timestamp FromEpochSecond(std::int64_t epochSeconds) { return FromEpochMilli(epochSeconds * 1000); } - static Timestamp FromEpochMilli(std::int64_t epochMilli) { return Timestamp(epochMilli); } + static Timestamp FromEpochMilli(std::int64_t epochMilli) + { + return Timestamp(std::chrono::duration_cast(std::chrono::milliseconds(epochMilli))); + } - std::int64_t GetEpochSecond() const { return epochMilli_ / 1000; } - std::int64_t GetEpochMilli() const { return epochMilli_; } - bool IsZero() const { return epochMilli_ == 0; } + std::int64_t GetEpochSecond() const { return std::chrono::duration_cast(epoch_).count(); } + std::int64_t GetEpochMilli() const { return std::chrono::duration_cast(epoch_).count(); } + bool IsZero() const { return epoch_ == std::chrono::system_clock::duration::zero(); } - Timestamp AddSeconds(std::int64_t seconds) const { return Timestamp(epochMilli_ + seconds * 1000); } + Timestamp AddSeconds(std::int64_t seconds) const { return Timestamp(std::chrono::duration_cast(epoch_ + std::chrono::seconds(seconds))); } Timestamp AddDays(int days) const { return AddSeconds(static_cast(days) * 24 * 60 * 60); } - bool operator==(Timestamp other) const { return epochMilli_ == other.epochMilli_; } + bool operator==(Timestamp other) const { return GetEpochMilli() == other.GetEpochMilli(); } bool operator!=(Timestamp other) const { return !operator==(other); } - bool operator<(Timestamp other) const { return epochMilli_ < other.epochMilli_; } + bool operator<(Timestamp other) const { return GetEpochMilli() < other.GetEpochMilli(); } bool operator<=(Timestamp other) const { return !other.operator<(*this); } bool operator>(Timestamp other) const { return other.operator<(*this); } bool operator>=(Timestamp other) const { return !operator<(other); } private: - explicit Timestamp(std::int64_t epochMilli) : epochMilli_(epochMilli) {} + using Clock = std::chrono::system_clock; + explicit Timestamp(Clock::duration epoch) : epoch_(epoch) {} - std::int64_t epochMilli_ = 0; + std::chrono::system_clock::duration epoch_ = {}; - inline friend std::ostream& operator<<(std::ostream& os, Timestamp ts) { return (os << ts.epochMilli_); } + friend std::ostream& operator<<(std::ostream& os, Timestamp ts) { return (os << ts.GetEpochMilli()); } }; } // namespace uid2 diff --git a/lib/timestamp.cpp b/lib/timestamp.cpp index 89a68a2..2c60b29 100644 --- a/lib/timestamp.cpp +++ b/lib/timestamp.cpp @@ -5,6 +5,6 @@ namespace uid2 { Timestamp Timestamp::Now() { - return Timestamp(std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count()); + return Timestamp(Clock::now().time_since_epoch()); } } // namespace uid2