roles-bot/packages/bot/snowflakeUtils.ts
2022-01-02 18:58:59 +01:00

15 lines
No EOL
444 B
TypeScript

export const toSnowflake = (snowflake: number, epoch = DISCORD_EPOCH) => {
return new Date(snowflake / 4194304 + epoch);
};
export const DISCORD_EPOCH = 1420070400000;
export const isSnowflake = (snowflake: number, epoch?: number) => {
if (!Number.isInteger(+snowflake)) return false;
if (snowflake < 4194304) return false;
const timestamp = toSnowflake(snowflake, epoch);
if (isNaN(timestamp.getTime())) return false;
return true;
};