1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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())
}
}
|