diff options
author | Joris | 2021-11-21 18:12:11 +0100 |
---|---|---|
committer | Joris | 2021-11-21 18:12:11 +0100 |
commit | 3c5be0300f281d809cbe2ecdf52a4ef34598f084 (patch) | |
tree | 5de6256d0d20c8bb0c3e4d88e1f84e17f3f6a7fd /src/model | |
parent | 54bcca5c48b4586433a92fe4aad9cddd2e5500dc (diff) |
Show static events on the calendar
Diffstat (limited to 'src/model')
-rw-r--r-- | src/model/event.rs | 39 | ||||
-rw-r--r-- | src/model/mod.rs | 1 |
2 files changed, 40 insertions, 0 deletions
diff --git a/src/model/event.rs b/src/model/event.rs new file mode 100644 index 0000000..d1d9775 --- /dev/null +++ b/src/model/event.rs @@ -0,0 +1,39 @@ +use chrono::Timelike; +use chrono::{NaiveDate, NaiveTime}; + +#[derive(Debug, Clone)] +pub struct Event { + pub date: NaiveDate, + pub time: Time, + pub name: String, +} + +impl Event { + pub fn pprint(&self) -> String { + match self.time { + Time::AllDay => self.name.clone(), + Time::Time { start, end: None } => format!("{} {}", pprint_time(start), self.name), + Time::Time { + start, + end: Some(e), + } => format!("{}-{} {}", pprint_time(start), pprint_time(e), self.name), + } + } +} + +#[derive(Debug, Clone, Copy, PartialOrd, PartialEq, Eq, Ord)] +pub enum Time { + AllDay, + Time { + start: NaiveTime, + end: Option<NaiveTime>, + }, +} + +fn pprint_time(t: NaiveTime) -> String { + if t.minute() == 0 { + format!("{}h", t.hour()) + } else { + format!("{}h{}", t.hour(), t.minute()) + } +} diff --git a/src/model/mod.rs b/src/model/mod.rs new file mode 100644 index 0000000..53f1126 --- /dev/null +++ b/src/model/mod.rs @@ -0,0 +1 @@ +pub mod event; |