1use crate::time::EventTime;
2use std::ops::Add;
3
4#[derive(Clone, Debug)]
5pub struct CalendarEvent<'a> {
6 pub title: &'a str,
7 pub start: EventTime,
8 pub end: Option<EventTime>,
9 pub url: Option<&'a str>,
10 pub uid: Option<&'a str>,
11 pub desc: Option<&'a str>,
12 pub busy: Option<bool>,
13 pub stat: Option<EventStatus>,
14 pub r_rule: Option<&'a str>,
15 pub guests: Option<Vec<&'a str>>,
16 pub all_day: Option<bool>,
17 pub location: Option<&'a str>,
18 pub duration: Option<chrono::Duration>,
19 pub organizer: Option<EventOrganizer<'a>>,
20}
21impl<'a> CalendarEvent<'a> {
22 pub fn end_date(&self) -> EventTime {
23 if let Some(end) = self.end {
24 return end;
25 }
26
27 let dur = if self.all_day.unwrap_or(false) {
28 Some(chrono::Duration::days(1))
29 } else {
30 self.duration
31 };
32
33 if let Some(dur) = dur {
34 match self.start {
35 EventTime::Utc(x) => EventTime::Utc(x.add(dur)),
36 EventTime::Local(x) => EventTime::Local(x.add(dur)),
37 }
38 } else {
39 self.start.clone()
40 }
41 }
42 pub fn is_all_day(&self) -> bool {
43 self.all_day.unwrap_or(false)
44 }
45}
46
47#[derive(Copy, Clone, Debug)]
48pub enum EventStatus {
49 Confirmed,
50 Tentative,
51 Cancelled,
52}
53#[derive(Clone, Debug)]
54pub struct EventOrganizer<'a> {
55 pub name: &'a str,
56 pub email: &'a str,
57}