fix(timestamps): account for timestamps of 0 when creating Dates (#7226)

This commit is contained in:
Rodry
2022-01-09 20:48:45 +00:00
committed by GitHub
parent a0a4a2258a
commit a8509c91ca
2 changed files with 7 additions and 4 deletions

View File

@@ -266,7 +266,10 @@ class GuildMemberManager extends CachedManager {
_data.roles &&= _data.roles.map(role => (role instanceof Role ? role.id : role));
_data.communication_disabled_until =
_data.communicationDisabledUntil && new Date(_data.communicationDisabledUntil).toISOString();
// eslint-disable-next-line eqeqeq
_data.communicationDisabledUntil != null
? new Date(_data.communicationDisabledUntil).toISOString()
: _data.communicationDisabledUntil;
let endpoint = this.client.api.guilds(this.guild.id);
if (id === this.client.user.id) {

View File

@@ -88,8 +88,8 @@ class MessageEmbed {
* @type {?number}
*/
// Date.parse() cannot be used here because data.timestamp might be a number
// Additionally, the nullish coalescing operator cannot be used here as we're checking for 0
this.timestamp = new Date(data.timestamp).getTime() || null;
// eslint-disable-next-line eqeqeq
this.timestamp = data.timestamp != null ? new Date(data.timestamp).getTime() : null;
/**
* Represents a field of a MessageEmbed
@@ -242,7 +242,7 @@ class MessageEmbed {
* @readonly
*/
get createdAt() {
return this.timestamp && new Date(this.timestamp);
return typeof this.timestamp === 'number' ? new Date(this.timestamp) : null;
}
/**