This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#First tweet on 21 Mar 2006 at 20:50:14.000 GMT (in ms) | |
TWEPOCH = 1288834974657 | |
#High 42 bytes are timestamp, low 22 are worker, datacenter and sequence bits | |
SHIFT = 22 | |
# Give it a snowflake id, it tells you what time it was created | |
# Will fail for very high ids because Ruby Time can only represent up to | |
# Jan 18, 2038 at 19:14:07 UTC (max signed int in seconds since unix epoch) | |
def what_time?(id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MockSnowflake | |
TWEPOCH = 1142974214000 | |
WORKERIDBITS = 5 | |
DATACENTERIDBITS = 5 | |
MAXWORKERID = -1 ^ (-1 << WORKERIDBITS) | |
SEQUENCEBITS = 12 | |
WORKERIDSHIFT = SEQUENCEBITS | |
DATACENTERIDSHIFT = SEQUENCEBITS + WORKERIDBITS | |
TIMESTAMPLEFTSHIFT = SEQUENCEBITS + WORKERIDBITS + DATACENTERIDBITS |