Error when moving untimed entry to new time
This commit is contained in:
parent
1ac39c69f2
commit
73a44a697a
4 changed files with 18 additions and 4 deletions
|
|
@ -244,6 +244,7 @@ impl<'a> CommandState<'a> {
|
|||
}
|
||||
|
||||
fn eval_except(&mut self, date: NaiveDate) {
|
||||
// TODO Error if nothing is removed?
|
||||
self.dated.remove(&date);
|
||||
}
|
||||
|
||||
|
|
@ -252,7 +253,7 @@ impl<'a> CommandState<'a> {
|
|||
span: Span,
|
||||
from: NaiveDate,
|
||||
to: Option<NaiveDate>,
|
||||
to_time: Option<Time>,
|
||||
to_time: Option<Spanned<Time>>,
|
||||
) -> Result<()> {
|
||||
if let Some(mut entry) = self.dated.remove(&from) {
|
||||
let mut dates = entry.dates.expect("comes from self.dated");
|
||||
|
|
@ -264,7 +265,12 @@ impl<'a> CommandState<'a> {
|
|||
}
|
||||
if let Some(to_time) = to_time {
|
||||
if let Some((root, _)) = dates.times() {
|
||||
delta = delta + Duration::minutes(root.minutes_to(to_time));
|
||||
delta = delta + Duration::minutes(root.minutes_to(to_time.value));
|
||||
} else {
|
||||
return Err(Error::TimedMoveWithoutTime {
|
||||
index: self.command.source.file(),
|
||||
span: to_time.span,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,6 +48,10 @@ pub enum Error {
|
|||
/// date `a`.
|
||||
#[error("tried to move nonexisting entry")]
|
||||
MoveWithoutSource { index: usize, span: Span },
|
||||
/// A `MOVE a TO b` statement was executed where `b` contains a time but `a`
|
||||
/// doesn't was executed.
|
||||
#[error("tried to move un-timed entry to new time")]
|
||||
TimedMoveWithoutTime { index: usize, span: Span },
|
||||
/// A division by zero has occurred.
|
||||
#[error("tried to divide by zero")]
|
||||
DivByZero {
|
||||
|
|
@ -162,6 +166,10 @@ impl Error {
|
|||
let msg = "Tried to move nonexisting entry".to_string();
|
||||
Self::print_at(sources, index, span, msg);
|
||||
}
|
||||
Error::TimedMoveWithoutTime { index, span } => {
|
||||
let msg = "Tried to move un-timed entry to new time".to_string();
|
||||
Self::print_at(sources, index, span, msg);
|
||||
}
|
||||
Error::DivByZero { index, span, date } => {
|
||||
let msg = format!(
|
||||
"Tried to divide by zero\
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue