//! Pure monthly recurrence calculation; the store owns materialisation.//! The calendar is `zoned_clock`'s: one month length and one clamp for every//! tool, so a money repeat and a yearly day cannot disagree on a short month.usesuper::dates::{add_days, DatesError};usesuper::row::MoneyRepeat;usecrate::transforms::zoned_clock::yearly_in_year;/// Returns the next expected date after `occurred_on` for a monthly rule./// A day beyond the next month's length becomes that month's last day.pubfn next_occurrence( occurred_on: &str, repeat: MoneyRepeat,) -> Result<Option<String>, DatesError> {letMoneyRepeat::Monthly { day } = repeat else {returnOk(None); };if !(1..=31).contains(&day) {returnOk(None); }// Validate and normalise first: a malformed date is the same refusal as// every other money calculation, never a panic on a short string.let occurred_on = add_days(occurred_on, 0)?;let (year, month) = (occurred_on[..4].parse::<i64>(), occurred_on[5..7].parse::<i64>());let (Ok(year), Ok(month)) = (year, month) else {returnErr(DatesError::Unparseable(occurred_on)); };let (year, month) = if month == 12 { (year + 1, 1) } else { (year, month + 1) };let (year, month, day) = yearly_in_year(month, i64::from(day), year);Ok(Some(format!("{year:04}-{month:02}-{day:02}")))}