Skip to content

Commit

Permalink
chore(Base): document props, static methods (#1380)
Browse files Browse the repository at this point in the history
  • Loading branch information
eritbh committed Jun 5, 2022
1 parent f7a8e50 commit d0099b1
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/structures/Base.js
Expand Up @@ -2,6 +2,11 @@

const util = require("util");

/**
* Provides utilities for working with many Discord structures
* @prop {string} id A Discord snowflake identifying the object
* @prop {Number} createdAt Timestamp of structure creation
*/
class Base {
constructor(id) {
if(id) {
Expand All @@ -13,10 +18,20 @@ class Base {
return Base.getCreatedAt(this.id);
}

/**
* Calculates the timestamp in milliseconds associated with a Discord ID/snowflake
* @param {String} id The ID of a structure
* @returns {Number}
*/
static getCreatedAt(id) {
return Base.getDiscordEpoch(id) + 1420070400000;
}

/**
* Gets the number of milliseconds since epoch represented by an ID/snowflake
* @param {string} id The ID of a structure
* @returns {number}
*/
static getDiscordEpoch(id) {
return Math.floor(id / 4194304);
}
Expand Down

0 comments on commit d0099b1

Please sign in to comment.