mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 17:43:30 +01:00
fix created timestamp precision (#1241)
* fix created timestamp precision * perf * Update Snowflake.js * gawdl3y was butthurt * Update Snowflake.js
This commit is contained in:
committed by
Schuyler Cebulskie
parent
21babf8859
commit
2897692cf1
@@ -34,7 +34,8 @@ class SnowflakeUtil {
|
||||
/**
|
||||
* A deconstructed snowflake
|
||||
* @typedef {Object} DeconstructedSnowflake
|
||||
* @property {Date} date Date in the snowflake
|
||||
* @property {number} timestamp Timestamp the snowflake was created
|
||||
* @property {Date} date Date the snowflake was created
|
||||
* @property {number} workerID Worker ID in the snowflake
|
||||
* @property {number} processID Process ID in the snowflake
|
||||
* @property {number} increment Increment in the snowflake
|
||||
@@ -48,13 +49,18 @@ class SnowflakeUtil {
|
||||
*/
|
||||
static deconstruct(snowflake) {
|
||||
const BINARY = pad(Long.fromString(snowflake).toString(2), 64);
|
||||
return {
|
||||
date: new Date(parseInt(BINARY.substring(0, 42), 2) + EPOCH),
|
||||
const res = {
|
||||
timestamp: parseInt(BINARY.substring(0, 42), 2) + EPOCH,
|
||||
workerID: parseInt(BINARY.substring(42, 47), 2),
|
||||
processID: parseInt(BINARY.substring(47, 52), 2),
|
||||
increment: parseInt(BINARY.substring(52, 64), 2),
|
||||
binary: BINARY,
|
||||
};
|
||||
Object.defineProperty(res, 'date', {
|
||||
get: function get() { return new Date(this.timestamp); },
|
||||
enumerable: true,
|
||||
});
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user