Fix range calculation for done tasks

This commit is contained in:
Joscha 2021-12-14 23:38:45 +01:00
parent c69af9bcde
commit 6d0acf8db7
4 changed files with 35 additions and 7 deletions

View file

@ -2,7 +2,7 @@ use std::collections::HashMap;
use chrono::NaiveDate;
use crate::files::commands::{BirthdaySpec, Command, Done, Note, Spec, Statement, Task};
use crate::files::commands::{BirthdaySpec, Command, Done, DoneDate, Note, Spec, Statement, Task};
use crate::files::primitives::Span;
use crate::files::SourcedCommand;
@ -73,7 +73,20 @@ impl<'a> CommandState<'a> {
}
}
fn last_done(&self) -> Option<NaiveDate> {
/// Last root date mentioned in any `DONE`.
fn last_done_root(&self) -> Option<NaiveDate> {
match self.command.command {
Command::Task(task) => task
.done
.iter()
.filter_map(|done| done.date.map(DoneDate::root))
.max(),
Command::Note(_) => None,
}
}
/// Last completion date mentioned in any `DONE`.
fn last_done_completion(&self) -> Option<NaiveDate> {
match self.command.command {
Command::Task(task) => task.done.iter().map(|done| done.done_at).max(),
Command::Note(_) => None,