Design command data types

This design went through a few iterations, and this won't be the last.
This commit is contained in:
Joscha 2021-11-06 01:15:55 +01:00
parent 636c7e9ee7
commit 106111e7c6
5 changed files with 177 additions and 1 deletions

87
src/commands.rs Normal file
View file

@ -0,0 +1,87 @@
use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
#[derive(Debug)]
struct DateDelta {
years: i32,
months: i32,
weeks: i32,
days: i32,
}
#[derive(Debug)]
struct TimeDelta {
hours: i32,
minutes: i32,
}
#[derive(Debug)]
enum EndDate {
Fixed(NaiveDate),
Delta(DateDelta),
}
#[derive(Debug)]
enum EndTime {
Fixed(NaiveTime),
Delta(TimeDelta),
}
#[derive(Debug)]
struct DateSpec {
start: NaiveDate,
end: Option<EndDate>,
repeat: Option<DateDelta>,
}
#[derive(Debug)]
struct TimeSpec {
start: NaiveTime,
end: Option<EndTime>,
}
#[derive(Debug)]
struct WhenSpec {
date: DateSpec,
time: Option<TimeSpec>,
}
#[derive(Debug)]
struct Done {
refering_to: Option<NaiveDate>,
created_at: Option<NaiveDateTime>,
}
#[derive(Debug)]
struct Task {
title: String,
when: Option<WhenSpec>,
desc: Option<String>,
dones: Vec<Done>,
}
#[derive(Debug)]
struct Note {
title: String,
when: WhenSpec,
desc: Option<String>,
}
#[derive(Debug)]
enum BirthdaySpec {
Date(NaiveDate),
DateWithoutYear { month: u8, day: u8 },
}
#[derive(Debug)]
struct Birthday {
title: String,
when: BirthdaySpec,
desc: Option<String>,
}
#[derive(Debug)]
enum Command {
Task(Task),
Note(Note),
Birthday(Birthday),
}