5 ms·
HAHAHAHAHA he appends a 4-character string of random numbers to "new Date().getTime()", hides it behind several terribly-named and terribly-namespaced function
by gingerrr 13y ago
HAHAHAHAHA he appends a 4-character string of random numbers to "new Date().getTime()", hides it behind several terribly-named and terribly-namespaced function calls and tries to call it hyper precise:
https://github.com/amark/theory/blob/master/theory.js#L449 https://github.com/amark/theory/blob/master/theory.js#L449
look at 'time.now()', called by when, and 'time.is()'.
- gingerrr 13y agoor i can just copypasta: time.is = (function(t){ t = ($=a.fns.$(time))||t; return t? t instanceof Date : (+new Date().getTime()); }); time.now = (function(){ return a.num.ify((a.time.is().toString())+'.'+a.num.r(4)); }); ... num.random = num.r = (function(l){ ... how cute
- jamesrom 13y agoI think that the comment about it being "hyper precise" is a joke. The likely reason for the extra 4 digits is to prevent collisions in timing. The probability of messages having the same timestamp is already pretty low, this just divides that probability by ten thousand.
- stingraycharles 13y agoIsn't this the reason UUIDs were invented?
- lostcolony 13y agoNot exactly. UUIDs are for uniqueness, but don't imply order. Timestamps imply order, but not necessarily uniqueness. Sometimes you want both. Some languages give you mechanisms to guarantee an increasing timestamp (Erlang's erlang:now(), for instance) for that purpose. Now, if this is actually appending just random data, rather than an incrementing counter, you still are guaranteeing uniqueness (well, a reasonable guarantee of probably uniqueness), and have order to a specific coarseness, but beyond that all bets are off. My guess is that it's to imply an absolute ordering, but once you're sub-millisecond assume that it doesn't really matter if the order is accurate.