Flesh out commands and DATE annotations
This commit is contained in:
parent
dea704065c
commit
afa708960c
2 changed files with 183 additions and 55 deletions
76
README.md
76
README.md
|
|
@ -1,33 +1,55 @@
|
|||
# today
|
||||
|
||||
## Goal 1
|
||||
## `DATE` annotations
|
||||
|
||||
- Support simple dates and optional times
|
||||
- Support tasks, notes and birthdays
|
||||
Most commands allow or require `DATE` annotations. They are roughly structured
|
||||
like `DATE start [-- end]`. The `end` part can only contain time-related
|
||||
information if the `start` specifies a time.
|
||||
|
||||
More specifically, there are three variants of the `DATE` annotation:
|
||||
```
|
||||
TASK Task without date
|
||||
DONE (2021-10-27 00:50)
|
||||
|
||||
TASK Another simple task
|
||||
DONE
|
||||
|
||||
TASK Another task, this time with date
|
||||
DATE 2021-10-26
|
||||
DONE 2021-10-26 (2021-10-27 00:52)
|
||||
|
||||
NOTE Maybe an appointment
|
||||
DATE 2021-12-07 16:00
|
||||
Here are some notes regarding the appointment
|
||||
Notes can be multiple lines long
|
||||
|
||||
Including empty lines (not even whitespace) in-between
|
||||
As long as the text stays indented, it's still part of it
|
||||
|
||||
BIRTHDAY John Doe
|
||||
DATE 1987-05-12
|
||||
|
||||
BIRTHDAY Jane Doe
|
||||
DATE ?-08-22
|
||||
DONE 2021-08-22 (2021-08-22 10:23)
|
||||
DATE date [delta] [time] [-- [date] [delta] [time]] [; delta]
|
||||
DATE weekday [time] [-- [weekday] [delta] [time]]
|
||||
DATE formula [delta] [time] [-- [delta] [time]]
|
||||
```
|
||||
|
||||
In all three cases, the `end` must contain at least one of the optional elements
|
||||
if it is present. Deltas in the `end` may represent fractional days (e. g.
|
||||
`+3h`) as long as they are not immediately followed by a time and the `start`
|
||||
includes a time. Other deltas may only represent whole-day intervals (they may
|
||||
contain sub-day specifiers like `+24h` or `+25h-60m` as long as they sum to a
|
||||
whole-day interval).
|
||||
|
||||
In the case of the `date` variant, a repetition delta can be specified following
|
||||
a semicolon.
|
||||
|
||||
If multiple `DATE` annotations from a single command start on the same date, all
|
||||
except the first are ignored.
|
||||
|
||||
## Examples
|
||||
```
|
||||
NOTE Spielerunde
|
||||
DATE sun 22:00 -- 24:00
|
||||
DATE sun 22:00 -- 00:00
|
||||
DATE sun 22:00 -- +2h
|
||||
DATE (wd = sun) 22:00 -- 24:00
|
||||
DATE 2021-11-07 22:00 -- 24:00; +w
|
||||
DATE 2021-11-07 22:00 -- +2h; +w
|
||||
|
||||
NOTE daily
|
||||
DATE *
|
||||
DATE (true)
|
||||
DATE 2021-11-07; +d
|
||||
|
||||
NOTE on weekends
|
||||
DATE (wd = sat | wd = sun)
|
||||
|
||||
NOTE weekends
|
||||
DATE sat -- sun
|
||||
DATE 2021-11-06 -- 2021-11-07; +w
|
||||
DATE 2021-11-06 -- +d; +w
|
||||
DATE (wd = sat) -- +d
|
||||
|
||||
NOTE last of each month
|
||||
DATE (m = 1) -d
|
||||
```
|
||||
|
|
|
|||
162
src/commands.rs
162
src/commands.rs
|
|
@ -1,5 +1,27 @@
|
|||
use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Weekday {
|
||||
Monday,
|
||||
Tuesday,
|
||||
Wednesday,
|
||||
Thursday,
|
||||
Friday,
|
||||
Saturday,
|
||||
Sunday,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum DeltaStep {
|
||||
Year(i32),
|
||||
Month(i32),
|
||||
Day(i32),
|
||||
Week(i32),
|
||||
Hour(i32),
|
||||
Minute(i32),
|
||||
Weekday(i32, Weekday),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Delta {
|
||||
pub years: i32,
|
||||
|
|
@ -11,46 +33,130 @@ pub struct Delta {
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct DateDelta {
|
||||
years: i32,
|
||||
months: i32,
|
||||
weeks: i32,
|
||||
days: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct TimeDelta {
|
||||
hours: i32,
|
||||
minutes: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct EndDateSpec {
|
||||
struct DateEndSpec {
|
||||
end: Option<NaiveDate>,
|
||||
delta: Option<Delta>,
|
||||
end_time: Option<NaiveTime>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct DateSpec {
|
||||
start: NaiveDate,
|
||||
delta: Option<Delta>,
|
||||
start_time: Option<NaiveTime>,
|
||||
offset: Option<Delta>,
|
||||
end: Option<EndDateSpec>,
|
||||
end: Option<DateEndSpec>,
|
||||
repeat: Option<Delta>,
|
||||
}
|
||||
|
||||
// #[derive(Debug)]
|
||||
// struct FormulaSpec {
|
||||
// start: (), // TODO Formula
|
||||
// start_time: Option<NaiveTime>,
|
||||
// offset: Option<Delta>,
|
||||
// end: Option<Delta>,
|
||||
// }
|
||||
#[derive(Debug)]
|
||||
struct WeekdayEndSpec {
|
||||
end: Option<Weekday>,
|
||||
delta: Option<Delta>,
|
||||
end_time: Option<NaiveTime>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct WeekdaySpec {
|
||||
start: Weekday,
|
||||
start_time: Option<NaiveTime>,
|
||||
end: Option<WeekdayEndSpec>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum IntVar {
|
||||
/// `j`, see https://en.wikipedia.org/wiki/Julian_day
|
||||
JulianDay,
|
||||
/// `y`
|
||||
Year,
|
||||
/// `yl`, length of the current year in days
|
||||
YearLength,
|
||||
/// `yd`, day of the year
|
||||
YearDay,
|
||||
/// `m`
|
||||
Month,
|
||||
/// `ml`, length of the current month in days
|
||||
MonthLength,
|
||||
/// `d`, day of the month
|
||||
MonthDay,
|
||||
/// `iy`, ISO 8601 year
|
||||
IsoYear,
|
||||
/// `iyl`, length of current ISO 8601 year **in weeks**
|
||||
IsoYearLength,
|
||||
/// `iw`, ISO 8601 week
|
||||
IsoWeek,
|
||||
/// `wd`, day of the week, starting at monday with 1
|
||||
Weekday,
|
||||
/// `e`, day of the year that easter falls on
|
||||
Easter,
|
||||
/// `mon`, always 1
|
||||
Monday,
|
||||
/// `tue`, always 2
|
||||
Tuesday,
|
||||
/// `wed`, always 3
|
||||
Wednesday,
|
||||
/// `thu`, always 4
|
||||
Thursday,
|
||||
/// `fri`, always 5
|
||||
Friday,
|
||||
/// `sat`, always 6
|
||||
Saturday,
|
||||
/// `sun`, always 7
|
||||
Sunday,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum IntExpr {
|
||||
Lit(i64),
|
||||
Var(IntVar),
|
||||
Paren(Box<IntVar>),
|
||||
Neg(Box<IntExpr>),
|
||||
Add(Box<IntExpr>, Box<IntExpr>),
|
||||
Sub(Box<IntExpr>, Box<IntExpr>),
|
||||
Mul(Box<IntExpr>, Box<IntExpr>),
|
||||
Div(Box<IntExpr>, Box<IntExpr>),
|
||||
Mod(Box<IntExpr>, Box<IntExpr>),
|
||||
Ternary(Box<BoolExpr>, Box<IntExpr>, Box<IntExpr>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum BoolVar {
|
||||
IsWeekday,
|
||||
IsWeekend,
|
||||
IsLeapYear,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum BoolExpr {
|
||||
Lit(bool),
|
||||
Var(BoolVar),
|
||||
Paren(Box<BoolVar>),
|
||||
Eq(Box<IntExpr>, Box<IntExpr>),
|
||||
Neq(Box<IntExpr>, Box<IntExpr>),
|
||||
Lt(Box<IntExpr>, Box<IntExpr>),
|
||||
Lte(Box<IntExpr>, Box<IntExpr>),
|
||||
Gt(Box<IntExpr>, Box<IntExpr>),
|
||||
Gte(Box<IntExpr>, Box<IntExpr>),
|
||||
Not(Box<BoolExpr>),
|
||||
And(Box<BoolExpr>, Box<BoolExpr>),
|
||||
Or(Box<BoolExpr>, Box<BoolExpr>),
|
||||
Xor(Box<BoolExpr>, Box<BoolExpr>),
|
||||
BEq(Box<BoolExpr>, Box<BoolExpr>),
|
||||
BNeq(Box<BoolExpr>, Box<BoolExpr>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct FormulaSpec {
|
||||
start: Option<BoolExpr>, // None: *
|
||||
start_time: Option<NaiveTime>,
|
||||
offset: Option<Delta>,
|
||||
end: Option<Delta>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Spec {
|
||||
Date(DateSpec),
|
||||
// Formula(FormulaSpec),
|
||||
Weekday(WeekdaySpec),
|
||||
Formula(FormulaSpec),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
@ -62,15 +168,15 @@ struct Done {
|
|||
#[derive(Debug)]
|
||||
struct Task {
|
||||
title: String,
|
||||
when: Option<Spec>,
|
||||
when: Vec<Spec>,
|
||||
done: Vec<Done>,
|
||||
desc: Option<String>,
|
||||
dones: Vec<Done>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Note {
|
||||
title: String,
|
||||
when: Spec,
|
||||
when: Vec<Spec>, // Not empty
|
||||
desc: Option<String>,
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue