Adapt eval code to changes
These changes include the new file representation and Files API as well as the codespan error reporting.
This commit is contained in:
parent
810ec67cf7
commit
8ae691bc3c
8 changed files with 238 additions and 215 deletions
|
|
@ -1,12 +1,14 @@
|
|||
use chrono::NaiveDate;
|
||||
|
||||
use crate::files::commands::{self, Command};
|
||||
use crate::files::commands;
|
||||
use crate::files::primitives::{Spanned, Time};
|
||||
use crate::files::FileSource;
|
||||
|
||||
use super::super::command::CommandState;
|
||||
use super::super::date::Dates;
|
||||
use super::super::delta::{Delta, DeltaStep};
|
||||
use super::super::{DateRange, Error, Result};
|
||||
use super::super::{DateRange, Error};
|
||||
use super::EvalCommand;
|
||||
|
||||
pub struct DateSpec {
|
||||
pub start: NaiveDate,
|
||||
|
|
@ -72,14 +74,16 @@ impl DateSpec {
|
|||
/// `start` date itself should be skipped (and thus not result in an entry).
|
||||
/// This may be necessary if [`Self::start_at_done`] is set.
|
||||
fn start_and_range(&self, s: &CommandState<'_>) -> Option<(NaiveDate, bool, DateRange)> {
|
||||
let (start, skip, range) = match s.command.command {
|
||||
Command::Task(_) => {
|
||||
let (start, skip, range) = match s.command {
|
||||
EvalCommand::Task(_) => {
|
||||
let (start, skip) = s
|
||||
.command
|
||||
.last_done_completion()
|
||||
.map(|start| (start, true))
|
||||
.filter(|_| self.start_at_done)
|
||||
.unwrap_or((self.start, false));
|
||||
let range_from = s
|
||||
.command
|
||||
.last_done_root()
|
||||
.map(|date| date.succ())
|
||||
.unwrap_or(self.start);
|
||||
|
|
@ -90,7 +94,7 @@ impl DateSpec {
|
|||
.with_from(range_from)?;
|
||||
(start, skip, range)
|
||||
}
|
||||
Command::Note(_) => {
|
||||
EvalCommand::Note(_) => {
|
||||
let start = self.start;
|
||||
let range = s
|
||||
.range_with_remind()
|
||||
|
|
@ -103,7 +107,11 @@ impl DateSpec {
|
|||
Some((start, skip, range))
|
||||
}
|
||||
|
||||
fn step(index: usize, from: NaiveDate, repeat: &Spanned<Delta>) -> Result<NaiveDate> {
|
||||
fn step(
|
||||
index: FileSource,
|
||||
from: NaiveDate,
|
||||
repeat: &Spanned<Delta>,
|
||||
) -> Result<NaiveDate, Error<FileSource>> {
|
||||
let to = repeat.value.apply_date(index, from)?;
|
||||
if to > from {
|
||||
Ok(to)
|
||||
|
|
@ -117,7 +125,7 @@ impl DateSpec {
|
|||
}
|
||||
}
|
||||
|
||||
fn dates(&self, index: usize, start: NaiveDate) -> Result<Dates> {
|
||||
fn dates(&self, index: FileSource, start: NaiveDate) -> Result<Dates, Error<FileSource>> {
|
||||
let root = self.start_delta.apply_date(index, start)?;
|
||||
Ok(if let Some(root_time) = self.start_time {
|
||||
let (other, other_time) = self.end_delta.apply_date_time(index, root, root_time)?;
|
||||
|
|
@ -130,8 +138,8 @@ impl DateSpec {
|
|||
}
|
||||
|
||||
impl<'a> CommandState<'a> {
|
||||
pub fn eval_date_spec(&mut self, spec: DateSpec) -> Result<()> {
|
||||
let index = self.command.source.file();
|
||||
pub fn eval_date_spec(&mut self, spec: DateSpec) -> Result<(), Error<FileSource>> {
|
||||
let index = self.source.file();
|
||||
if let Some(repeat) = &spec.repeat {
|
||||
if let Some((mut start, skip, range)) = spec.start_and_range(self) {
|
||||
if skip {
|
||||
|
|
@ -142,13 +150,13 @@ impl<'a> CommandState<'a> {
|
|||
}
|
||||
while start <= range.until() {
|
||||
let dates = spec.dates(index, start)?;
|
||||
self.add(self.entry_with_remind(self.kind(), Some(dates))?);
|
||||
self.add(self.entry_with_remind(self.command.kind(), Some(dates))?);
|
||||
start = DateSpec::step(index, start, repeat)?;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let dates = spec.dates(index, spec.start)?;
|
||||
self.add(self.entry_with_remind(self.kind(), Some(dates))?);
|
||||
self.add(self.entry_with_remind(self.command.kind(), Some(dates))?);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue