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:
parent
31c1bca7d7
commit
a9b90f881e
2 changed files with 110 additions and 126 deletions
28
src/main.rs
28
src/main.rs
|
|
@ -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])),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue