Reorganize spec evaluation
This commit is contained in:
parent
3a219ecac2
commit
2112272347
4 changed files with 32 additions and 23 deletions
59
src/eval/command/date.rs
Normal file
59
src/eval/command/date.rs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
use chrono::NaiveDate;
|
||||
|
||||
use crate::files::commands::{self, Spanned, Time};
|
||||
|
||||
use super::super::command::CommandState;
|
||||
use super::super::delta::{Delta, DeltaStep};
|
||||
use super::super::Result;
|
||||
|
||||
pub struct DateSpec {
|
||||
pub start: NaiveDate,
|
||||
pub start_delta: Delta,
|
||||
pub start_time: Option<Time>,
|
||||
pub end_delta: Delta,
|
||||
pub repeat: Option<Delta>,
|
||||
pub start_at_done: bool,
|
||||
}
|
||||
|
||||
impl From<&commands::DateSpec> for DateSpec {
|
||||
fn from(spec: &commands::DateSpec) -> Self {
|
||||
let start_delta: Delta = spec
|
||||
.start_delta
|
||||
.as_ref()
|
||||
.map(|delta| delta.into())
|
||||
.unwrap_or_default();
|
||||
|
||||
let mut end_delta: Delta = spec
|
||||
.end_delta
|
||||
.as_ref()
|
||||
.map(|delta| delta.into())
|
||||
.unwrap_or_default();
|
||||
if let Some(time) = spec.end_time {
|
||||
end_delta
|
||||
.steps
|
||||
.push(Spanned::new(time.span, DeltaStep::Time(time.value)));
|
||||
}
|
||||
|
||||
let repeat: Option<Delta> = spec.repeat.as_ref().map(|repeat| (&repeat.delta).into());
|
||||
let start_at_done = spec
|
||||
.repeat
|
||||
.as_ref()
|
||||
.map(|repeat| repeat.start_at_done)
|
||||
.unwrap_or(false);
|
||||
|
||||
Self {
|
||||
start: spec.start,
|
||||
start_delta,
|
||||
start_time: spec.start_time,
|
||||
end_delta,
|
||||
repeat,
|
||||
start_at_done,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> CommandState<'a> {
|
||||
pub fn eval_date_spec(&mut self, spec: DateSpec) -> Result<()> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue