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