Determine batching interval for non-recurring tasks deterministically
Don't use current time to estimate batching interval for non-recurring tasks.
This commit is contained in:
parent
6c58cd1774
commit
9d8d77a356
1 changed files with 13 additions and 12 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue