From 67a1decc6371b5f60a3c850390c5093e97cb17bf Mon Sep 17 00:00:00 2001 From: Davide Fantino <80767709+fantinodavide@users.noreply.github.com> Date: Tue, 20 Sep 2022 23:20:59 +0200 Subject: [PATCH] fixes and optimizations --- mapvote.js | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/mapvote.js b/mapvote.js index f999997..5185eb1 100644 --- a/mapvote.js +++ b/mapvote.js @@ -177,8 +177,24 @@ export default class MapVote extends DiscordBasePlugin { this.updateNextMap(); } async timeframeOptionOverrider() { - const orOpt = { ...this.or_options }; + + let tfFilter = function (tf, key, arr) { + const utcDelay = tf.timezone ? parseFloat(tf.timezone) : 0; + const timeNow = new Date(0, 0, 0, new Date().getUTCHours() + utcDelay, new Date().getUTCMinutes()); + this.verbose(1, `Current time (UTC+${utcDelay}) ${timeNow.getHours()}:${timeNow.getMinutes()}`) + + const tfStartSplit = [ parseInt(tf.start.split(':')[ 0 ]), parseInt(tf.start.split(':')[ 1 ]) ]; + const tfEndSplit = [ parseInt(tf.end.split(':')[ 0 ]), parseInt(tf.end.split(':')[ 1 ]) ]; + + const tfStart = new Date(0, 0, 0, ...tfStartSplit) + const tfStart2 = new Date(0, 0, 0, 0, 0) + const tfEnd = new Date(0, 0, 0, ...tfEndSplit) + const tfEnd2 = new Date(0, 0, 0, 24, 0) + return (tfStart <= timeNow && timeNow < tfEnd) || (tfStart > tfEnd && ((tfStart <= timeNow && timeNow < tfEnd2) || (tfStart2 <= timeNow && timeNow < tfEnd))) + } + tfFilter = tfFilter.bind(this); + const activeTimeframes = orOpt.timeFrames.filter(tfFilter); let logTimeframe = "Active Time Frames: "; @@ -192,22 +208,8 @@ export default class MapVote extends DiscordBasePlugin { } } this.verbose(1, logTimeframe + activeTfIds.join(', ')); - const _verbose = this.verbose; + // this.verbose(1, `Current UTC time: ${timeNow.getHours()}:${timeNow.getMinutes()}`) - function tfFilter(tf, key, arr) { - const utcDelay = tf.timezone ? parseFloat(tf.timezone) : 0; - const timeNow = new Date(0, 0, 0, new Date().getUTCHours() + utcDelay, new Date().getUTCMinutes()); - _verbose(1, `Current time (UTC+${utcDelay}) ${timeNow.getHours()}:${timeNow.getMinutes()}`) - - const tfStartSplit = [ parseInt(tf.start.split(':')[ 0 ]), parseInt(tf.start.split(':')[ 1 ]) ]; - const tfEndSplit = [ parseInt(tf.end.split(':')[ 0 ]), parseInt(tf.end.split(':')[ 1 ]) ]; - - const tfStart = new Date(0, 0, 0, ...tfStartSplit) - const midnight = new Date(0, 0, 0, 0, 0) - const tfEnd = new Date(0, 0, 0, ...tfEndSplit) - const tfEnd2 = new Date(0, 0, 0, ...tfEndSplit) - return (tfStart <= timeNow && timeNow < tfEnd) || (tfStart > tfEnd && ((tfStart <= timeNow && timeNow < midnight) || (midnight <= timeNow && timeNow < tfEnd))) - } } async checkUpdates(callback) { const versionN = "1.0.0"