From c4187f6cd7878b6d5cfb15100af28d1335efe974 Mon Sep 17 00:00:00 2001 From: aevitas Date: Sun, 14 Dec 2025 11:22:11 +0800 Subject: [PATCH] change IsSnowflake to only look for a timestamp --- src/FlakeId/Extensions/IdExtensions.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/FlakeId/Extensions/IdExtensions.cs b/src/FlakeId/Extensions/IdExtensions.cs index 66c61b5..c4adc44 100644 --- a/src/FlakeId/Extensions/IdExtensions.cs +++ b/src/FlakeId/Extensions/IdExtensions.cs @@ -34,15 +34,11 @@ public static long ToUnixTimeMilliseconds(this Id id) /// public static bool IsSnowflake(this Id id) { - // There's no way to guarantee the specified value is a snowflake. - // The closest we can get is by decomposing its components, and ensuring all of them are set - // to values that would be valid for a snowflake. + // Validates that the ID has a non-zero timestamp. + // Thread , Process, and Increment can legitimately be 0, so checking them for > 0 results in false negatives. long timestamp = id >> TimestampOffset; - long thread = (id >> ThreadOffset) & Id.ThreadIdMask; - long process = (id >> ProcessOffset) & Id.ProcessIdMask; - long increment = id & Id.IncrementMask; - return timestamp > 0 && thread > 0 && process > 0 && increment >= 0; + return timestamp > 0; } ///