RobThree / IdGen

Twitter Snowflake-alike ID generator for .Net
MIT License
1.19k stars 148 forks source link

Is there a way to generate id from the past #60

Closed andtii closed 6 months ago

andtii commented 1 year ago

Im creating a feed and using IdGen to create time based ids to sort it and its working perfectly. But is there a way to pass in a date in history and calculate the id? Like 3 days ago or something?

RobThree commented 1 year ago

There isn't and you shouldn't. An ID is supposed to be an opaque, meaningless, identifier. Just because some bits are reserved for a timestamp (which helps in sorting and prevents fragmenting indexes) doesn't mean that you should rely on those bits when you need to get a timestamp. If you need to keep track of a createdate or something from an object then just store it in an extra field; don't use the ID for this.