Include more info in DONE
This commit is contained in:
parent
0bb01369b8
commit
bfbf53784b
5 changed files with 94 additions and 34 deletions
|
|
@ -7,6 +7,11 @@ DATE sun 22:00 -- +2h
|
||||||
DATE (wd = sun) 22:00 -- 24:00
|
DATE (wd = sun) 22:00 -- 24:00
|
||||||
DATE 2021-11-07 22:00 -- 24:00; +w
|
DATE 2021-11-07 22:00 -- 24:00; +w
|
||||||
DATE 2021-11-07 22:00 -- +2h; +w
|
DATE 2021-11-07 22:00 -- +2h; +w
|
||||||
|
DONE [2021-11-07] 2021-11-07 22:00 -- 24:00
|
||||||
|
DONE [2021-11-14] 2021-11-14 22:00 -- 24:00
|
||||||
|
DONE [2021-11-21] 2021-11-21 22:00 -- 24:00
|
||||||
|
DONE [2021-11-28] 2021-11-28 22:00 -- 24:00
|
||||||
|
DONE [2021-11-30]
|
||||||
|
|
||||||
NOTE daily
|
NOTE daily
|
||||||
DATE *
|
DATE *
|
||||||
|
|
|
||||||
|
|
@ -277,10 +277,31 @@ pub enum Spec {
|
||||||
Formula(FormulaSpec),
|
Formula(FormulaSpec),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum DoneDate {
|
||||||
|
Date {
|
||||||
|
root: NaiveDate,
|
||||||
|
},
|
||||||
|
DateWithTime {
|
||||||
|
root: NaiveDate,
|
||||||
|
root_time: Time,
|
||||||
|
},
|
||||||
|
DateToDate {
|
||||||
|
root: NaiveDate,
|
||||||
|
other: NaiveDate,
|
||||||
|
},
|
||||||
|
DateToDateWithTime {
|
||||||
|
root: NaiveDate,
|
||||||
|
root_time: Time,
|
||||||
|
other: NaiveDate,
|
||||||
|
other_time: Time,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Done {
|
pub struct Done {
|
||||||
pub refering_to: Option<NaiveDate>,
|
pub date: Option<DoneDate>,
|
||||||
pub created_at: Option<(NaiveDate, Time)>,
|
pub done_at: NaiveDate,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ use std::fmt;
|
||||||
use chrono::Datelike;
|
use chrono::Datelike;
|
||||||
|
|
||||||
use super::commands::{
|
use super::commands::{
|
||||||
Birthday, BirthdaySpec, Command, DateSpec, Delta, DeltaStep, Done, Expr, File, FormulaSpec,
|
Birthday, BirthdaySpec, Command, DateSpec, Delta, DeltaStep, Done, DoneDate, Expr, File,
|
||||||
Note, Spec, Task, Time, Var, Weekday, WeekdaySpec,
|
FormulaSpec, Note, Spec, Task, Time, Var, Weekday, WeekdaySpec,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn format_desc(f: &mut fmt::Formatter<'_>, desc: &[String]) -> fmt::Result {
|
fn format_desc(f: &mut fmt::Formatter<'_>, desc: &[String]) -> fmt::Result {
|
||||||
|
|
@ -186,15 +186,28 @@ impl fmt::Display for Spec {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for DoneDate {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
DoneDate::Date { root } => write!(f, "{}", root),
|
||||||
|
DoneDate::DateWithTime { root, root_time } => write!(f, "{} {}", root, root_time),
|
||||||
|
DoneDate::DateToDate { root, other } => write!(f, "{} -- {}", root, other),
|
||||||
|
DoneDate::DateToDateWithTime {
|
||||||
|
root,
|
||||||
|
root_time,
|
||||||
|
other,
|
||||||
|
other_time,
|
||||||
|
} => write!(f, "{} {} -- {} {}", root, root_time, other, other_time),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl fmt::Display for Done {
|
impl fmt::Display for Done {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "DONE")?;
|
write!(f, "DONE [{}]", self.done_at)?;
|
||||||
if let Some(date) = &self.refering_to {
|
if let Some(date) = &self.date {
|
||||||
write!(f, " {}", date)?;
|
write!(f, " {}", date)?;
|
||||||
}
|
}
|
||||||
if let Some((date, time)) = &self.created_at {
|
|
||||||
write!(f, " ({} {})", date, time)?;
|
|
||||||
}
|
|
||||||
writeln!(f)
|
writeln!(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -107,8 +107,13 @@ from = !{ "FROM" ~ datum ~ eol }
|
||||||
until = !{ "UNTIL" ~ datum ~ eol }
|
until = !{ "UNTIL" ~ datum ~ eol }
|
||||||
except = !{ "EXCEPT" ~ datum ~ eol }
|
except = !{ "EXCEPT" ~ datum ~ eol }
|
||||||
|
|
||||||
donedate = { "(" ~ datum ~ time ~ ")" }
|
donedate = {
|
||||||
done = !{ "DONE" ~ datum? ~ donedate? ~ eol }
|
datum ~ time ~ "--" ~ datum ~ time
|
||||||
|
| datum ~ time
|
||||||
|
| datum ~ "--" ~ datum
|
||||||
|
| datum
|
||||||
|
}
|
||||||
|
done = !{ "DONE" ~ "[" ~ datum ~ "]" ~ donedate? ~ eol }
|
||||||
|
|
||||||
desc_line = { "#" ~ (" " ~ rest_any)? ~ eol }
|
desc_line = { "#" ~ (" " ~ rest_any)? ~ eol }
|
||||||
description = { desc_line* }
|
description = { desc_line* }
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ use pest::prec_climber::{Assoc, Operator, PrecClimber};
|
||||||
use pest::{Parser, Span};
|
use pest::{Parser, Span};
|
||||||
|
|
||||||
use super::commands::{
|
use super::commands::{
|
||||||
Birthday, BirthdaySpec, Command, DateSpec, Delta, DeltaStep, Done, Expr, File, FormulaSpec,
|
Birthday, BirthdaySpec, Command, DateSpec, Delta, DeltaStep, Done, DoneDate, Expr, File,
|
||||||
Note, Spec, Task, Time, Var, Weekday, WeekdaySpec,
|
FormulaSpec, Note, Spec, Task, Time, Var, Weekday, WeekdaySpec,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(pest_derive::Parser)]
|
#[derive(pest_derive::Parser)]
|
||||||
|
|
@ -538,36 +538,52 @@ fn parse_except(p: Pair<'_, Rule>) -> Result<NaiveDate> {
|
||||||
parse_datum(p.into_inner().next().unwrap())
|
parse_datum(p.into_inner().next().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_donedate(p: Pair<'_, Rule>) -> Result<(NaiveDate, Time)> {
|
fn parse_donedate(p: Pair<'_, Rule>) -> Result<DoneDate> {
|
||||||
assert_eq!(p.as_rule(), Rule::donedate);
|
assert_eq!(p.as_rule(), Rule::donedate);
|
||||||
let mut p = p.into_inner();
|
let mut ps = p.into_inner().collect::<Vec<_>>();
|
||||||
|
|
||||||
let date = parse_datum(p.next().unwrap())?;
|
// Popping the elements off of the vector in reverse so I don't have to
|
||||||
let time = parse_time(p.next().unwrap())?;
|
// shuffle them around weirdly. In Haskell, I would've just pattern-matched
|
||||||
|
// the list ;-;
|
||||||
assert_eq!(p.next(), None);
|
Ok(match ps.len() {
|
||||||
|
1 => DoneDate::Date {
|
||||||
Ok((date, time))
|
root: parse_datum(ps.pop().unwrap())?,
|
||||||
|
},
|
||||||
|
2 => match ps[1].as_rule() {
|
||||||
|
Rule::time => DoneDate::DateWithTime {
|
||||||
|
root_time: parse_time(ps.pop().unwrap())?,
|
||||||
|
root: parse_datum(ps.pop().unwrap())?,
|
||||||
|
},
|
||||||
|
Rule::datum => DoneDate::DateToDate {
|
||||||
|
other: parse_datum(ps.pop().unwrap())?,
|
||||||
|
root: parse_datum(ps.pop().unwrap())?,
|
||||||
|
},
|
||||||
|
_ => unreachable!(),
|
||||||
|
},
|
||||||
|
4 => DoneDate::DateToDateWithTime {
|
||||||
|
other_time: parse_time(ps.pop().unwrap())?,
|
||||||
|
other: parse_datum(ps.pop().unwrap())?,
|
||||||
|
root_time: parse_time(ps.pop().unwrap())?,
|
||||||
|
root: parse_datum(ps.pop().unwrap())?,
|
||||||
|
},
|
||||||
|
_ => unreachable!(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_done(p: Pair<'_, Rule>) -> Result<Done> {
|
fn parse_done(p: Pair<'_, Rule>) -> Result<Done> {
|
||||||
assert_eq!(p.as_rule(), Rule::done);
|
assert_eq!(p.as_rule(), Rule::done);
|
||||||
|
let mut p = p.into_inner();
|
||||||
|
|
||||||
let mut refering_to = None;
|
let done_at = parse_datum(p.next().unwrap())?;
|
||||||
let mut created_at = None;
|
let date = if let Some(p) = p.next() {
|
||||||
|
Some(parse_donedate(p)?)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
for ele in p.into_inner() {
|
assert_eq!(p.next(), None);
|
||||||
match ele.as_rule() {
|
|
||||||
Rule::datum => refering_to = Some(parse_datum(ele)?),
|
|
||||||
Rule::donedate => created_at = Some(parse_donedate(ele)?),
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(Done {
|
Ok(Done { date, done_at })
|
||||||
refering_to,
|
|
||||||
created_at,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue