From 1ac39c69f238cb949b88865daff155760b05e1e5 Mon Sep 17 00:00:00 2001 From: Joscha Date: Tue, 21 Dec 2021 19:24:27 +0100 Subject: [PATCH] Move entries to a different time --- CHANGELOG.md | 1 + src/eval/command.rs | 39 +++++++++++++++++++++++++++++++-------- src/eval/date.rs | 21 +++++++++++++++++---- src/eval/delta.rs | 8 ++++---- src/files/commands.rs | 3 ++- src/files/format.rs | 9 ++++++++- src/files/grammar.pest | 2 +- src/files/parse.rs | 20 +++++++++++++++++--- src/files/primitives.rs | 22 ++++++++++++++++++---- 9 files changed, 99 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0b9fae..d12e3d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added - `REMIND` statement +- `MOVE` entries to a different time ## 0.1.0 - 2021-12-20 diff --git a/src/eval/command.rs b/src/eval/command.rs index 8bdac96..b277a7d 100644 --- a/src/eval/command.rs +++ b/src/eval/command.rs @@ -1,11 +1,11 @@ use std::collections::HashMap; -use chrono::NaiveDate; +use chrono::{Duration, NaiveDate}; use crate::files::commands::{ self, BirthdaySpec, Command, Done, DoneDate, Note, Spec, Statement, Task, }; -use crate::files::primitives::{Span, Spanned}; +use crate::files::primitives::{Span, Spanned, Time}; use crate::files::SourcedCommand; use super::date::Dates; @@ -220,7 +220,12 @@ impl<'a> CommandState<'a> { Statement::From(date) => self.from = *date, Statement::Until(date) => self.until = *date, Statement::Except(date) => self.eval_except(*date), - Statement::Move { span, from, to } => self.eval_move(*span, *from, *to)?, + Statement::Move { + span, + from, + to, + to_time, + } => self.eval_move(*span, *from, *to, *to_time)?, Statement::Remind(delta) => self.eval_remind(delta), } Ok(()) @@ -242,13 +247,31 @@ impl<'a> CommandState<'a> { self.dated.remove(&date); } - fn eval_move(&mut self, span: Span, from: NaiveDate, to: NaiveDate) -> Result<()> { + fn eval_move( + &mut self, + span: Span, + from: NaiveDate, + to: Option, + to_time: Option