couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Davis <paul.joseph.da...@gmail.com>
Subject Re: Time information and UUID
Date Sun, 26 Sep 2010 17:49:19 GMT
On Sun, Sep 26, 2010 at 1:46 PM, Robert Newson <robert.newson@gmail.com> wrote:
> 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?
>>
>

Also, I sure wouldn't depend on being able to pull the time out of a
UUID. They're intended to be opaque so if things change and it breaks
your code, you don't have any sort of recourse to complain about.
Heck, even if someone happens to switch the algorithm on you it'd
break.

IOW, you have the power to do this, but I'd take heed of Rob's advice
and just generate your own UUIDs client side.

HTH,
Paul Davis

Mime
View raw message