There are three algorithms available from the uuid generator inside
couchdb, "utc_random", "random" and "sequential". Only "utc_random"
includes the current time thus;
utc_random() ->
Now = {_, _, Micro} = now(),
Nowish = calendar:now_to_universal_time(Now),
Nowsecs = calendar:datetime_to_gregorian_seconds(Nowish),
Then = calendar:datetime_to_gregorian_seconds({{1970, 1, 1}, {0, 0, 0}}),
Prefix = io_lib:format("~14.16.0b", [(Nowsecs - Then) * 1000000 + Micro]),
list_to_binary(Prefix ++ couch_util:to_hex(crypto:rand_bytes(9))).
It should be possible to extract the time if you ignore the random
piece on the end. However, you are not forced to use the uuid
generator. If your documents ids need to contain the time, why not
specify the ids yourself and thereby control the format precisely?
B.
On Sun, Sep 26, 2010 at 5:28 PM, sleepy <[email protected]> wrote:
> Some of the UUID generation function use current time to generate UUID.
> Is CouchDB's UUID generation algorithm also take current time as part of
> it's generated UUID?
> If the answer is yes. How can I extract it out from a generated UUID?
>