From f415a0244f3acd9868060e34a686dac18cdc2592 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Tue, 3 Mar 2026 17:26:01 -0500 Subject: [PATCH] digest: remove dead iso_week_info, use chrono directly everywhere MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Deleted iso_week_info() — dead code after week_dates() was rewritten. Replaced remaining epoch_to_local/today/now_epoch calls with chrono Local::now() and NaiveDate parsing. Month arg parsing now uses NaiveDate instead of manual string splitting. Phase 3 month comparison simplified to a single tuple comparison. Co-Authored-By: Kent Overstreet --- Cargo.lock | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/digest.rs | 47 ++++++++----------------- 2 files changed, 111 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4e5e1d8..bb4dade 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22,6 +22,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anyhow" version = "1.0.102" @@ -174,6 +183,25 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" +[[package]] +name = "chrono" +version = "0.4.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c673075a2e0e5f4a1dde27ce9dee1ea4558c7ffe648f576438a20ca1d2acc4b0" +dependencies = [ + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-link", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + [[package]] name = "cpufeatures" version = "0.2.17" @@ -668,6 +696,30 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" +[[package]] +name = "iana-time-zone" +version = "0.1.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "id-arena" version = "2.3.0" @@ -1015,6 +1067,7 @@ dependencies = [ "bincode", "capnp", "capnpc", + "chrono", "faer", "libc", "memmap2", @@ -1754,6 +1807,41 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + [[package]] name = "windows-link" version = "0.2.1" @@ -1769,6 +1857,15 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + [[package]] name = "windows-sys" version = "0.42.0" diff --git a/src/digest.rs b/src/digest.rs index dbd0424..405fc50 100644 --- a/src/digest.rs +++ b/src/digest.rs @@ -143,16 +143,6 @@ fn week_dates(date: &str) -> Result<(String, Vec), String> { Ok((week_label, dates)) } -/// Returns (weekday 0=Sun, iso_year, iso_week) for a given date. -fn iso_week_info(y: i32, m: u32, d: u32) -> Result<(u32, i32, u32), String> { - use chrono::{Datelike, NaiveDate}; - let date = NaiveDate::from_ymd_opt(y, m, d) - .ok_or_else(|| format!("invalid date: {}-{}-{}", y, m, d))?; - let wday = date.weekday().num_days_from_sunday(); - let iso = date.iso_week(); - Ok((wday, iso.year(), iso.week())) -} - fn load_digest_files(prefix: &str, labels: &[String]) -> Result, String> { let dir = memory_subdir("episodic")?; let mut digests = Vec::new(); @@ -273,18 +263,14 @@ fn build_monthly_prompt(month_label: &str, digests: &[(String, String)], keys: & } pub fn generate_monthly(store: &mut Store, month_arg: &str) -> Result<(), String> { + use chrono::{Datelike, Local, NaiveDate}; let (year, month) = if month_arg.is_empty() { - let now = store::now_epoch(); - let (y, m, _, _, _, _) = store::epoch_to_local(now); - (y, m) + let now = Local::now(); + (now.year(), now.month()) } else { - let parts: Vec<&str> = month_arg.split('-').collect(); - if parts.len() != 2 { - return Err(format!("bad month format: {} (expected YYYY-MM)", month_arg)); - } - let y: i32 = parts[0].parse().map_err(|_| "bad year")?; - let m: u32 = parts[1].parse().map_err(|_| "bad month")?; - (y, m) + let d = NaiveDate::parse_from_str(&format!("{}-01", month_arg), "%Y-%m-%d") + .map_err(|e| format!("bad month '{}': {} (expected YYYY-MM)", month_arg, e))?; + (d.year(), d.month()) }; let month_label = format!("{}-{:02}", year, month); @@ -340,7 +326,9 @@ pub fn generate_monthly(store: &mut Store, month_arg: &str) -> Result<(), String /// (needs weeklies). Skips today (incomplete day). Skips already-existing /// digests. pub fn digest_auto(store: &mut Store) -> Result<(), String> { - let today = store::today(); + use chrono::{Datelike, Local}; + let now = Local::now(); + let today = now.format("%Y-%m-%d").to_string(); let epi = memory_subdir("episodic")?; // --- Phase 1: find dates with journal entries but no daily digest --- @@ -430,15 +418,12 @@ pub fn digest_auto(store: &mut Store) -> Result<(), String> { // A month is "ready" if the month is before the current month and at // least one weekly digest exists for it. - let (cur_y, cur_m, _, _, _, _) = store::epoch_to_local(store::now_epoch()); + let cur_month = (now.year(), now.month()); let mut months_seen: std::collections::BTreeSet<(i32, u32)> = std::collections::BTreeSet::new(); for date in &daily_dates_done { - let parts: Vec<&str> = date.split('-').collect(); - if parts.len() >= 2 { - if let (Ok(y), Ok(m)) = (parts[0].parse::(), parts[1].parse::()) { - months_seen.insert((y, m)); - } + if let Ok(nd) = chrono::NaiveDate::parse_from_str(date, "%Y-%m-%d") { + months_seen.insert((nd.year(), nd.month())); } } @@ -446,12 +431,8 @@ pub fn digest_auto(store: &mut Store) -> Result<(), String> { let mut monthly_skipped = 0u32; for (y, m) in &months_seen { - // Skip current month (still in progress) - if *y == cur_y && *m == cur_m { - continue; - } - // Skip future months - if *y > cur_y || (*y == cur_y && *m > cur_m) { + // Skip current or future months + if (*y, *m) >= cur_month { continue; }