From 9024ec09458acf67e4cd0f228130af02a2b32819 Mon Sep 17 00:00:00 2001 From: Davide Fantino <80767709+fantinodavide@users.noreply.github.com> Date: Sun, 18 Sep 2022 14:19:22 +0200 Subject: [PATCH] utc time support --- README.MD | 14 ++++++++++++++ mapvote.js | 7 ++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/README.MD b/README.MD index 394324d..6fb9d8c 100644 --- a/README.MD +++ b/README.MD @@ -125,6 +125,18 @@ Array of timeframes that allows to override options based on local time. See exa ```json [] ``` +###### Timeframe format +```javascript +{ + "name": "friendly name", // a friendly name visible in the logs + "start": "12:00", // timeframe start time : + "end": "18:00", // timeframe end time : + "utcTime": true, // true: use UTC time; false: use LOCAL time + "overrides": { + "automaticVoteStart": false + } +}, +``` ### Example configuration ```json { @@ -149,6 +161,7 @@ Array of timeframes that allows to override options based on local time. See exa "name": "follow layer rotation list", "start": "12:00", "end": "18:00", + "utcTime": true, "overrides": { "automaticVoteStart": false } @@ -156,6 +169,7 @@ Array of timeframes that allows to override options based on local time. See exa { "start": "22:00", "end": "02:00", + "utcTime": false, "overrides": { "voteBroadcastMessage": "Late night games? Vote your favourite map!" } diff --git a/mapvote.js b/mapvote.js index 0a62a5a..8829ef0 100644 --- a/mapvote.js +++ b/mapvote.js @@ -175,7 +175,6 @@ export default class MapVote extends DiscordBasePlugin { this.updateNextMap(); } async timeframeOptionOverrider() { - const timeNow = new Date(0, 0, 0, new Date().getHours(), new Date().getMinutes()); const activeTimeframes = this.or_options.timeFrames.filter(tfFilter); let logTimeframe = "Active Time Frames: "; @@ -184,13 +183,15 @@ export default class MapVote extends DiscordBasePlugin { for (let atfK in activeTimeframes) { const atf = activeTimeframes[ atfK ]; activeTfIds.push(atf.name || atf.id); - for(let o in atf.overrides){ - this.options[o] = atf.overrides[o]; + for (let o in atf.overrides) { + this.options[ o ] = atf.overrides[ o ]; } } this.verbose(1, logTimeframe + activeTfIds.join(', ')); function tfFilter(tf, key, arr) { + const timeNow = tf.utcTime?new Date(0, 0, 0, new Date().getUTCHours(), new Date().getUTCMinutes()):new Date(0, 0, 0, new Date().getHours(), new Date().getMinutes()); + arr[ key ].id = key + 1; const tfStartSplit = [ parseInt(tf.start.split(':')[ 0 ]), parseInt(tf.start.split(':')[ 1 ]) ]; const tfEndSplit = [ parseInt(tf.end.split(':')[ 0 ]), parseInt(tf.end.split(':')[ 1 ]) ];