diff --git a/backend/src/lib/workforce.js b/backend/src/lib/workforce.js index a92fe8e..f11d8b5 100644 --- a/backend/src/lib/workforce.js +++ b/backend/src/lib/workforce.js @@ -196,10 +196,21 @@ export async function runRollingSync() { current.setDate(current.getDate() + 7) } - // Scheduled: next 14 days (well within 31-day limit) - const fwdDate = new Date(today) - fwdDate.setDate(fwdDate.getDate() + 14) - const scheduledRows = await syncScheduled(todayStr, fwdDate.toISOString().slice(0, 10)) + // Scheduled: next 14 days in 7-day batches + const schedEnd = new Date(today) + schedEnd.setDate(schedEnd.getDate() + 14) + let scheduledRows = 0 + let schedCurrent = new Date(today) + while (schedCurrent <= schedEnd) { + const batchEnd = new Date(schedCurrent) + batchEnd.setDate(batchEnd.getDate() + 6) + if (batchEnd > schedEnd) batchEnd.setTime(schedEnd.getTime()) + scheduledRows += await syncScheduled( + schedCurrent.toISOString().slice(0, 10), + batchEnd.toISOString().slice(0, 10) + ) + schedCurrent.setDate(schedCurrent.getDate() + 7) + } return { actualRows, scheduledRows } }