From 9d8d77a356f2000443d959b4d58a188f174146b0 Mon Sep 17 00:00:00 2001 From: Rahix Date: Thu, 5 Mar 2026 20:55:39 +0100 Subject: [PATCH] Determine batching interval for non-recurring tasks deterministically Don't use current time to estimate batching interval for non-recurring tasks. --- src/reminder.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/reminder.rs b/src/reminder.rs index 6388997..42be76d 100644 --- a/src/reminder.rs +++ b/src/reminder.rs @@ -23,7 +23,7 @@ pub async fn remind_all_tasks(ctx: &crate::Context, tasks: &[task::Task]) -> any continue; }; - let batching_interval = find_batching_interval(ctx, &info.due_date, task); + let batching_interval = find_batching_interval(task, info); log::debug!("Reminder interval for {task} is {batching_interval:?}."); if !is_time_to_remind(ctx, &info.due_date, batching_interval) { @@ -118,13 +118,7 @@ Hello again. This task is overdue, please take care of it ASAP!" Ok(()) } -fn find_batching_interval( - ctx: &crate::Context, - due_date: &jiff::Zoned, - task: &task::Task, -) -> BatchingInterval { - let time_until_due = due_date - &ctx.timestamp; - +fn find_batching_interval(task: &task::Task, info: &task::ScheduledInfo) -> BatchingInterval { if let Some(recurring) = &task.recurring { match &recurring.interval { task::RecurringInterval::Months(_) => BatchingInterval::Monthly, @@ -135,12 +129,19 @@ fn find_batching_interval( // For tasks that are not recurring, the batching interval is determined based on how // far in the future the task is due. - let weeks_until_due = time_until_due - .total((jiff::Unit::Week, jiff::SpanRelativeTo::days_are_24_hours())) + let task_duration = &info.due_date - &info.start_date; + + let task_weeks = task_duration + .total((jiff::Unit::Week, &info.start_date)) .unwrap(); - if weeks_until_due >= 3. { + + let task_months = task_duration + .total((jiff::Unit::Month, &info.start_date)) + .unwrap(); + + if task_months >= 1. { BatchingInterval::Monthly - } else if weeks_until_due >= 1. { + } else if task_weeks >= 1. { BatchingInterval::Weekly } else { BatchingInterval::OnTheDay