digest: unify gather/find with composable date_range + date_to_label

Each DigestLevel now carries two date-math fn pointers:
- label_dates: expand an arg into (label, dates covered)
- date_to_label: map any date to this level's label

Parent gather works by expanding its date range then mapping those
dates through the child level's date_to_label to derive child labels.
find_candidates groups journal dates through date_to_label and skips
the current period. This eliminates six per-level functions
(gather_daily/weekly/monthly, find_daily/weekly/monthly_args) and the
three generate_daily/weekly/monthly public entry points in favor of
one generic gather, one generic find_candidates, and one public
generate(store, level_name, arg).
This commit is contained in:
ProofOfConcept 2026-03-03 18:04:21 -05:00
parent 31c1bca7d7
commit a9b90f881e
2 changed files with 110 additions and 126 deletions

View file

@ -765,27 +765,15 @@ fn cmd_digest(args: &[String]) -> Result<(), String> {
let date_arg = args.get(1).map(|s| s.as_str()).unwrap_or("");
match args[0].as_str() {
"daily" => {
let date = if date_arg.is_empty() {
store::format_date(store::now_epoch())
} else {
date_arg.to_string()
};
digest::generate_daily(&mut store, &date)
}
"weekly" => {
let date = if date_arg.is_empty() {
store::format_date(store::now_epoch())
} else {
date_arg.to_string()
};
digest::generate_weekly(&mut store, &date)
}
"monthly" => {
let month = if date_arg.is_empty() { "" } else { date_arg };
digest::generate_monthly(&mut store, month)
}
"auto" => digest::digest_auto(&mut store),
name @ ("daily" | "weekly" | "monthly") => {
let arg = if date_arg.is_empty() {
store::format_date(store::now_epoch())
} else {
date_arg.to_string()
};
digest::generate(&mut store, name, &arg)
}
_ => Err(format!("Unknown digest type: {}. Use: daily, weekly, monthly, auto", args[0])),
}
}