Properly handle when days roll over to being negative

This commit is contained in:
Firepup Sixfifty 2024-08-16 01:29:20 +00:00
parent b2832c7427
commit c5390c3909
Signed by: firepup650
SSH key fingerprint: SHA256:U0Zp8EhEe3CMqFSrC79CqatzaEiL4sjta80/RSX2XrY
2 changed files with 17 additions and 8 deletions

View file

@ -173,9 +173,14 @@ async function report() {
function predictSpeed(goalDate, goalNumber, currentNumber) {
let today = new Date();
let goal = new Date(goalDate);
let timeRemaining = Math.abs(goal - today);
let daysRemaining = Math.ceil(timeRemaining / (1000 * 60 * 60 * 24));
let neededSpeed = (goalNumber - currentNumber) / daysRemaining;
let timeRemaining = goal - today;
let daysRemaining
if (timeRemaining >= 0) {
daysRemaining = Math.ceil(timeRemaining / (1000 * 60 * 60 * 24));
else {
daysRemaining = math.floor(timeRemaining / (1000 * 60 * 60 * 24));
}
let neededSpeed = (goalNumber - currentNumber) / Math.abs(daysRemaining);
return [daysRemaining, neededSpeed];
}

View file

@ -29,12 +29,16 @@ function addQuotes(message, rawGoals, rawSpeed) {
let diff = goals - speed;
if (goals <= 0) {
end = `:tada: YOU DID IT, MY LOYAL SERVANTS! YOU'VE REACHED OUR GOAL ON TIME! :tada: But there's still loads of time before we reach a million-- let's keep up the pace!`
} else if (diff < 10) {
} else if (diff < 10 && days > 0) {
end = `You're doing well, my lackeys! Keep up that speed of at least *+${speed}* if you want to reach that goal! You have *${days}* days remaining to get there!`
} else if (diff > 10 && diff < 1000) {
} else if (diff > 10 && diff < 1000 && days > 0) {
end = `Still room to improve your performance, my underlings-- you're only at *${speed}* a day! Get that speed up to at least *+${goals}* to get there on time! You have *${days}* days left!`
} else if (diff > 1000) {
} else if (diff > 1000 && days > 0) {
end = `You're slogging behind, my minions! Only *${speed}* a day? RiDONKulous! Get that speed up to at least *+${goals}* to get there on time! Hurry up!!! You have *${days}* days left to get there!`
} else if (days == 0) {
end = `Today's the deadline my minions! I hope you can count at least *+${goals}* today, otherwise we'll miss the deadline!`
} else if (days < 0) {
end = `We've missed the deadline by ${Math.abs(days)} day${(days < -1)? 's': ''} my underlings-- I hope you can make the next one. In the meantime, I recommend counting *+${goals}* numbers today.`
}
return start + "\n" + message + "\n" + end;
}