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

86
Cargo.lock generated
View file

@ -2,6 +2,92 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "autocfg"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]]
name = "chrono"
version = "0.4.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
dependencies = [
"libc",
"num-integer",
"num-traits",
"time",
"winapi",
]
[[package]]
name = "libc"
version = "0.2.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a60553f9a9e039a333b4e9b20573b9e9b9c0bb3a11e201ccc48ef4283456d673"
[[package]]
name = "num-integer"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"
dependencies = [
"autocfg",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
dependencies = [
"autocfg",
]
[[package]]
name = "time"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
dependencies = [
"libc",
"wasi",
"winapi",
]
[[package]]
name = "today"
version = "0.1.0"
dependencies = [
"chrono",
]
[[package]]
name = "wasi"
version = "0.10.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

View file

@ -4,3 +4,4 @@ version = "0.1.0"
edition = "2018"
[dependencies]
chrono = "0.4.19"

View file

@ -24,7 +24,7 @@ DATE 2021-12-07 16:00
Including empty lines (not even whitespace) in-between
As long as the text stays indented, it's still part of it
BIRTHDAY John Doe (<age>)
BIRTHDAY John Doe
DATE 1987-05-12
BIRTHDAY Jane Doe

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),
}

View file

@ -1,3 +1,5 @@
mod commands;
fn main() {
println!("Hello, world!");
}