From 3c5be0300f281d809cbe2ecdf52a4ef34598f084 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 21 Nov 2021 18:12:11 +0100 Subject: Show static events on the calendar --- src/model/event.rs | 39 +++++++++++++++++++++++++++++++++++++++ src/model/mod.rs | 1 + 2 files changed, 40 insertions(+) create mode 100644 src/model/event.rs create mode 100644 src/model/mod.rs (limited to 'src/model') 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, + }, +} + +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; -- cgit v1.2.3