Updated getDateEST() function, added more verbose mongodb error log, removed unnecessary await
This commit is contained in:
1 file changed
+7
-7
@@ -104,11 +104,11 @@ class DayzRBot extends Client {
|
|||||||
error(Text) { this.logger.error(Text); }
|
error(Text) { this.logger.error(Text); }
|
||||||
|
|
||||||
async getDateEST(time) {
|
async getDateEST(time) {
|
||||||
let t = new Date(); // Get current date (PST)
|
let timeArray = time.split(' ')[0].split(':')
|
||||||
let e = new Date(t.getTime() + 180*60*1000); // Convert to EST to ensure the date is correct for the applied EST time
|
let t = new Date(); // Get current date & time (UTC)
|
||||||
let n = new Date(`${e.getFullYear()}-${e.getMonth()<10?'0':''}${e.getMonth()+1}-${e.getDate()<10?'0':''}${e.getDate()}T${time.split(' ')[0]}`) // Apply given time to EST date
|
let f = new Date(t.getTime() - 4 * 3600000) // Convert UTC into EST time to roll back the day as necessary
|
||||||
let f = new Date(n.getTime() - 180*60*1000) // Convert back to PST
|
f.setUTCHours(timeArray[0], timeArray[1], timeArray[2]); // Apply the supplied EST time to the converted date (EST is the timezone produced from the Nitrado logs).
|
||||||
return f;
|
return new Date(f.getTime() + 4 * 3600000); // Add EST time offset to return timestamp in UTC
|
||||||
}
|
}
|
||||||
|
|
||||||
async readLogs(guildId) {
|
async readLogs(guildId) {
|
||||||
@@ -246,12 +246,12 @@ class DayzRBot extends Client {
|
|||||||
this.databaseConnected = true;
|
this.databaseConnected = true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
databaselogs.attempts++;
|
databaselogs.attempts++;
|
||||||
this.error(`Failed to connect to mongodb: attempt ${databaselogs.attempts}`);
|
this.error(`Failed to connect to mongodb (mongodb://${mongoURI.split('@')[1]}/${dbo}): attempt ${databaselogs.attempts} - Error: ${err}`);
|
||||||
failed = true;
|
failed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// write JSON string to a file
|
// write JSON string to a file
|
||||||
await fs.writeFileSync(dbLogDir, JSON.stringify(databaselogs));
|
fs.writeFileSync(dbLogDir, JSON.stringify(databaselogs));
|
||||||
|
|
||||||
if (failed) process.exit(-1);
|
if (failed) process.exit(-1);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user