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;
|
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:?}.");
|
log::debug!("Reminder interval for {task} is {batching_interval:?}.");
|
||||||
|
|
||||||
if !is_time_to_remind(ctx, &info.due_date, 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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_batching_interval(
|
fn find_batching_interval(task: &task::Task, info: &task::ScheduledInfo) -> BatchingInterval {
|
||||||
ctx: &crate::Context,
|
|
||||||
due_date: &jiff::Zoned,
|
|
||||||
task: &task::Task,
|
|
||||||
) -> BatchingInterval {
|
|
||||||
let time_until_due = due_date - &ctx.timestamp;
|
|
||||||
|
|
||||||
if let Some(recurring) = &task.recurring {
|
if let Some(recurring) = &task.recurring {
|
||||||
match &recurring.interval {
|
match &recurring.interval {
|
||||||
task::RecurringInterval::Months(_) => BatchingInterval::Monthly,
|
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
|
// For tasks that are not recurring, the batching interval is determined based on how
|
||||||
// far in the future the task is due.
|
// far in the future the task is due.
|
||||||
|
|
||||||
let weeks_until_due = time_until_due
|
let task_duration = &info.due_date - &info.start_date;
|
||||||
.total((jiff::Unit::Week, jiff::SpanRelativeTo::days_are_24_hours()))
|
|
||||||
|
let task_weeks = task_duration
|
||||||
|
.total((jiff::Unit::Week, &info.start_date))
|
||||||
.unwrap();
|
.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
|
BatchingInterval::Monthly
|
||||||
} else if weeks_until_due >= 1. {
|
} else if task_weeks >= 1. {
|
||||||
BatchingInterval::Weekly
|
BatchingInterval::Weekly
|
||||||
} else {
|
} else {
|
||||||
BatchingInterval::OnTheDay
|
BatchingInterval::OnTheDay
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue