The id is from the NewId() query.
The date is from the Now() query.
The timestamp is retrieved with id >> 22.
The epoch is retrieved with date - timestamp.
Fauna uses Unix Epoch (January 1, 1970) as the basis for all time computation. Fauna document IDs are, indeed, created with the help of the Snowflake algorithm, but they encode more information than just time.
What are you hoping to achieve by manipulating the document IDs in this way?
What are you hoping to achieve by manipulating the document IDs in this way?
My goal is to get the creation date from the Snowflake identifier.
The first 22 bits of a Snowflake identifier should be the timestamp. Fauna follows that convention, right? Yet it appears that the Snowflake epoch is 2019-03-22, which is not the UNIX epoch, of course. And as I pointed out before, the times of each Snowflake identifier are different for some reason. Am I missing something?
Since the create event should always be the first event it will be in the first position of the pagination of all events; the ts field for that document will show the creation time in milliseconds since the epoch for it.
As I mentioned, while we use Snowflake, the document ID encodes additional information. While it could be possible to compute the creation date based on the document ID, we don’t recommend it, and we’re not going to provide enough information to do so.
To capture a document’s creation date, the simplest thing to do is to use Now. For example: