From b98b050078e35a0a1bb769c9e6147425c0cc7233 Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 11 Apr 2024 00:34:13 -0500 Subject: [PATCH] Website: Fix conditional logic in create-issues-from-todays-rituals script. (#18214) Closes: #17991 Changes: - Updated the logic in the create-issues-from-todays-rituals script that determines if an issue for a ritual should be created. --- .../create-issues-for-todays-rituals.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/website/scripts/create-issues-for-todays-rituals.js b/website/scripts/create-issues-for-todays-rituals.js index 1a3be90ffd..5e1303c736 100644 --- a/website/scripts/create-issues-for-todays-rituals.js +++ b/website/scripts/create-issues-for-todays-rituals.js @@ -64,19 +64,14 @@ module.exports = { let nextIssueShouldBeCreatedAt = ritualStartedAt + ((Math.floor(howManyRitualsCycles) + 1) * ritualsFrequencyInMs); // Get the amount of this ritual's cycle remaining. let amountOfCycleRemainingTillNextRitual = (Math.floor(howManyRitualsCycles) - howManyRitualsCycles) + 1; - // If amountOfCycleRemainingTillNextRitual is 0, then it is time to create a new issue for this ritual (Note: This will probably never happen) - if(amountOfCycleRemainingTillNextRitual === 0 || amountOfCycleRemainingTillNextRitual === -0){ + // Get the number of milliseconds until the next issue for this ritual will be created. + let timeToNextRitualInMs = amountOfCycleRemainingTillNextRitual * ritualsFrequencyInMs; + if(_.startsWith(ritual.frequency, 'Daily')) {// Using _.startsWith() to handle frequencies with emoji ("Daily ⏰") and with out ("Daily") + // Since this script runs once a day, we'll always create issues for daily rituals. + isItTimeToCreateANewIssue = true; + } else if(timeToNextRitualInMs === ritualsFrequencyInMs) { + // For any other frequency, we'll check to see if the calculated timeToNextRitualInMs is the same as the rituals frequency. isItTimeToCreateANewIssue = true; - } else { - // Otherwise, get the number of milliseconds until the next issue for this ritual will be created. - let timeToNextRitualInMs = Math.floor(amountOfCycleRemainingTillNextRitual * ritualsFrequencyInMs); - // Since this script runs once a day at the same time, we'll create issues we'll create issues for - if(_.startsWith(ritual.frequency, 'Daily')) {// Using _.startsWith() to handle frequencies with emoji ("Daily ⏰") and with out ("Daily") - isItTimeToCreateANewIssue = true; - } else if(timeToNextRitualInMs <= 86400000) { - // If the next occurance of this ritual is in less than 24 hours (before this script runs again), we'll create an issue for it. - isItTimeToCreateANewIssue = true; - } } // Skip to the next ritual if it isn't time yet. if (!isItTimeToCreateANewIssue) {