Skip to content

feat(shopping-list): --from / --to for some days of a menu - #612

Merged
LeMyst merged 1 commit into
cooklang:mainfrom
LeMyst:feat/shopping-list-dates
Oct 10, 2026
Merged

LeMyst merged 1 commit into
cooklang:mainfrom
LeMyst:feat/shopping-list-dates

Conversation

@LeMyst

@LeMyst LeMyst commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #385: the cook shopping-list day filter listed as still open in the summary. Independent of the other PRs. Rebased onto main 0734d32 (after #592, #596, #610).

# The first week of a fortnight plan
cook shopping-list Plans/October.menu --from 2026-10-07 --to 2026-10-13

# What is left of this week's menu
cook shopping-list "Weekly Plan.menu" --from today

A menu's days are its sections whose name holds a YYYY-MM-DD date (== Wednesday (2026-10-07) ==, = 2026-10-07 Dinner), as meal plans (#596) and the editor's Day button write them. With --from, --to or both, only the days in range go on the list: the recipes they reference, expanded as usual, and the ingredients written into them (@almonds{50%g}). Both ends are included; either may be left out; today is accepted.

Behaviour

  • Undated sections (== Leftovers ==, == Day 1 ==) are not days, so a range leaves them out.
  • A recipe, or a menu with no dated section, has no days to choose from and is taken whole; for a menu, a warning says so.
  • A menu with no day in range adds nothing, with a warning: None of this menu's days is in the range asked for (from 2027-01-01), so nothing from it is on the list.
  • A reversed range (--from 2026-10-07 --to 2026-10-01) or a malformed date is an error.
  • A scaling factor (Week.menu:2) applies to the days kept.
  • Optional ingredients (feat(shopping-list): leave optional ingredients out unless --include-optional #592) on the days kept follow --include-optional as everywhere else.

Implementation

  • Core (crates/core/src/shopping_list/days.rs): ScaledRecipe gains days: Option<DayRange> plus ScaledRecipe::on_days, so one request can narrow a menu and keep a recipe whole. ScaledRecipe::new / scaled set it to None; the server's two struct literals now use scaled (no behaviour change there).
  • section_date lives in core and follows the planner's rule from feat(ui): meal plans laid out as a calendar #596: the first YYYY-MM-DD anywhere in the section name, not inside a longer number. web::plan::section_date now builds on it (it returns the rest of the name too, for the meal), so the calendar and the shopping list cannot disagree on what a day is.
  • The filtered path collects the ingredient indices the chosen sections' steps use and hands them to add_ingredients (the function feat(shopping-list): leave optional ingredients out unless --include-optional #592 added): ingredients outside them are neither listed nor returned for expansion, so the listing, optional and reference rules stay in one place. An ingredient group (& references) counts only its in-range members (days::kept_quantity). Today's parser doesn't enable &, but the code doesn't assume that.
  • Each @./stew{} on a different day is its own ingredient, so the same recipe on two kept days is expanded twice, exactly as without a range.

Tests

  • Core: section_date cases (both heading styles); a plan headed = 2026-10-06 Dinner; optional ingredients on a kept day, with and without --include-optional; one day kept; open-ended ranges; undated sections dropped; the menu's scale applied to the kept days; a recipe taken whole without a warning; an undated menu taken whole with a warning; no day in range.
  • CLI (tests/shopping_list_test.rs, config isolated): --from/--to, --to alone, the no-day warning, a bad date and a reversed range refused, --from today.
  • cargo fmt, cargo clippy --all-targets clean (--no-default-features shows only the warnings already on main), cargo test: 1085 passed, 0 failed.

Docs: docs/shopping-list.md options table, examples and a "Some days of a menu" section.

Possible follow-up: #611 filters a menu's days server-side for the web shopping list. Once both are in, it could build on DayRange here (it already shares section_date through web::plan).

🤖 Generated with Claude Code

https://claude.ai/code/session_01RXA3hAKY9Q8hLCZGeokLPK

@LeMyst
LeMyst marked this pull request as ready for review October 4, 2026 21:19
`cook shopping-list Plans/October.menu --from 2026-10-07 --to 2026-10-13`
shops for that week only: the sections dated in the range (a YYYY-MM-DD
in the name, as meal plans and the editor's Day button write them), with
the recipes they reference expanded as usual and the ingredients written
into them. Both ends are included and either may be left out; `today` is
accepted.

- Undated sections are not days, so a range leaves them out.
- A recipe, or a menu with no dated section, is taken whole; for a menu
  a warning says so. A menu with no day in range adds nothing, with a
  warning.
- A reversed range or a malformed date is refused.
- Optional ingredients on the days kept follow --include-optional as
  everywhere else.

In core, `ScaledRecipe` gains `days: Option<DayRange>` (and `on_days`),
so a request can narrow one menu and not another. `add_ingredients` takes
the ingredients the chosen sections use and skips the rest, counting only
the in-range members of an ingredient group; the references among them
are expanded unchanged.

`section_date` moves to core with the planner's rule (the first
`YYYY-MM-DD` in a section name, `Wednesday (2026-10-07)` or
`2026-10-07 Dinner`), and `web::plan::section_date` builds on it, so the
calendar and the shopping list agree on what a day is. The server's two
struct literals use the constructor instead.

Part of cooklang#385.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@LeMyst
LeMyst force-pushed the feat/shopping-list-dates branch from 0bb1133 to 0b5e815 Compare October 4, 2026 21:39
@LeMyst
LeMyst merged commit 6e22411 into cooklang:main Oct 10, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant