Use next sunday as enddate to avoid overlap

This commit is contained in:
2026-01-26 15:20:14 +01:00
parent 7ca4b47ba9
commit 53c496422e

View File

@@ -23,9 +23,9 @@ module.exports = {
lastMonday.setDate(today.getDate() - ((today.getDay() === 0) ? 6 : today.getDay() - 1)); lastMonday.setDate(today.getDate() - ((today.getDay() === 0) ? 6 : today.getDay() - 1));
const startDate = formatDate(lastMonday); const startDate = formatDate(lastMonday);
const nextMonday = new Date(lastMonday); const nextSunday = new Date(lastMonday);
nextMonday.setDate(lastMonday.getDate() + 7); nextSunday.setDate(lastMonday.getDate() + 6);
const endDate = formatDate(nextMonday); const endDate = formatDate(nextSunday);
// 0 1 2 3 4 5 6 // 0 1 2 3 4 5 6
// S M T W T F S // S M T W T F S
let db = await client.localDB; let db = await client.localDB;
@@ -35,7 +35,7 @@ module.exports = {
const existingBudget = db.prepare(`SELECT id FROM weekly_budgets WHERE start_date = ?`).get(startDate); const existingBudget = db.prepare(`SELECT id FROM weekly_budgets WHERE start_date = ?`).get(startDate);
if (!existingBudget) { if (!existingBudget) {
await channel.send(`Format date last monday ${lastMonday} as startDate Format date next monday ${nextMonday} as endDate`); await channel.send(`Format date last monday ${lastMonday} as startDate Format date next sunday ${nextSunday} as endDate`);
await channel.send(`\`\`\`SELECT id FROM weekly_budgets WHERE start_date = ${startDate}\`\`\` await channel.send(`\`\`\`SELECT id FROM weekly_budgets WHERE start_date = ${startDate}\`\`\`
${JSON.stringify(existingBudget)}`); ${JSON.stringify(existingBudget)}`);
console.log(`No budget found for week starting ${startDate}.`); console.log(`No budget found for week starting ${startDate}.`);
@@ -130,7 +130,7 @@ module.exports = {
}, delay); }, delay);
const channel = await client.channels.fetch(timer.data.channelId); const channel = await client.channels.fetch(timer.data.channelId);
if (channel) await channel.send(`Next message scheduled for: ${next.toLocaleString()} with ms delta of ${delay} / ${delay/3600000}`); //if (channel) await channel.send(`Next message scheduled for: ${next.toLocaleString()} with ms delta of ${delay} / ${delay/3600000}`);
console.log(`[TIMER] Next message scheduled for: ${next.toLocaleString()}`); console.log(`[TIMER] Next message scheduled for: ${next.toLocaleString()}`);
} }
}; };