aboutsummaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
Diffstat (limited to 'src/model')
-rw-r--r--src/model/event.rs39
-rw-r--r--src/model/mod.rs1
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;