incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Newson <robert.new...@gmail.com>
Subject Re: Time information and UUID
Date Sun, 26 Sep 2010 17:46:59 GMT
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 <wanpeebaw@gmail.com> 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?
>

Mime
View raw message