tempo_cli/models/
calendar_event.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5pub struct CalendarEvent {
6    pub id: Option<i64>,
7    pub external_id: Option<String>,
8    pub title: String,
9    pub start_time: DateTime<Utc>,
10    pub end_time: DateTime<Utc>,
11    pub project_id: Option<i64>,
12    pub session_id: Option<i64>,
13    pub calendar_type: CalendarType,
14    pub synced_at: Option<DateTime<Utc>>,
15    pub created_at: DateTime<Utc>,
16}
17
18#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
19pub enum CalendarType {
20    Local,
21    Google,
22    Outlook,
23    ICal,
24}
25
26impl std::fmt::Display for CalendarType {
27    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28        match self {
29            CalendarType::Local => write!(f, "local"),
30            CalendarType::Google => write!(f, "google"),
31            CalendarType::Outlook => write!(f, "outlook"),
32            CalendarType::ICal => write!(f, "ical"),
33        }
34    }
35}
36
37impl CalendarEvent {
38    pub fn new(title: String, start_time: DateTime<Utc>, end_time: DateTime<Utc>) -> Self {
39        Self {
40            id: None,
41            external_id: None,
42            title,
43            start_time,
44            end_time,
45            project_id: None,
46            session_id: None,
47            calendar_type: CalendarType::Local,
48            synced_at: None,
49            created_at: Utc::now(),
50        }
51    }
52
53    pub fn duration_hours(&self) -> f64 {
54        (self.end_time - self.start_time).num_seconds() as f64 / 3600.0
55    }
56}