Weekly meal plan fails to populate specific week (Feb 9–16 2026) #186647
Replies: 3 comments 2 replies
-
|
This issue is most likely caused by a date-range calculation bug, where the end date is excluded or shifted due to timezone or week-start logic. ✅ Most common cause ✅ What to check and fix 1. Fix the date loop let current = new Date(startDate);
while (current <= endDate) {
generateMeals(current);
current.setDate(current.getDate() + 1);
}2. Normalize timezone const start = new Date(startDate + "T00:00:00");
const end = new Date(endDate + "T23:59:59");3. Verify week-start logic 4. Avoid string-based keys ✅ Add a regression test
Fixing the inclusive date range and normalizing timezone usually resolves this type of issue. |
Beta Was this translation helpful? Give feedback.
-
|
This pattern usually boils down to two bits of date logic drifting apart:
Root cause to look for
Patch so it doesn’t trip you up againPick one rule and stick to it everywhere:
Then:
Example shape (date-fns style, but same idea in dayjs/moment): export function dayKey(d: Date) {
const x = new Date(d);
x.setHours(0, 0, 0, 0);
return x.toISOString().slice(0, 10); // YYYY-MM-DD (UTC key)
}
export function getDaysInRange(start: Date, end: Date) {
const days: Date[] = [];
const cur = new Date(start);
cur.setHours(0, 0, 0, 0);
const last = new Date(end);
last.setHours(0, 0, 0, 0);
while (cur <= last) {
days.push(new Date(cur));
cur.setDate(cur.getDate() + 1);
}
return days;
}If you don’t want UTC keys, don’t use Why only 9–16 Feb 2026 blows upThat range is a perfect “boundary bait”:
Regression test that actually pins it downTest the thing that matters: every key exists for that range.
If your generator is deterministic (or can be seeded), assert totals; otherwise assert “not empty” + “within tolerance”. Next place to dig when “Generate” still errorsIf the week view is fixed but “Generate” throws:
Make them all call the same helper, then the bug can’t creep back in. If you paste the two functions that (a) build the range and (b) write/read by date key, I can point out the exact mismatch that’s tripping it up. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Body
Summary
My Meal Planning page fails to generate/populate meals for the date range 9 Feb 2026 → 16 Feb 2026. Other weeks generate normally.
This looks like a date boundary / week calculation issue (or an edge case with how the range is built).
Expected
Actual
Reproduction steps
Notes / Context
What I think is happening
Likely one of these:
< endDateinstead of<= endDateYYYY-MM-DDvs locale)What I need help with
Helpful info to include (I can provide)
Tech details
...(date range / week calc)...(meal generation / auto-portioning)The GitHub file can be found here: https://github.com/jacobsscoots/lfinance
Guidelines
Beta Was this translation helpful? Give feedback.
All reactions