use std::str::FromStr; use crate::synctoken::format_synctoken; use chrono::NaiveDateTime; use rustical_ical::CalendarObjectType; use serde::{Deserialize, Serialize}; #[derive(Debug, Default, Clone, Serialize, Deserialize)] pub struct CalendarMetadata { // Attributes that may be outsourced pub displayname: Option, pub order: i64, pub description: Option, pub color: Option, } #[derive(Debug, Default, Clone, Serialize, Deserialize)] pub struct Calendar { // Attributes that may be outsourced #[serde(flatten)] pub meta: CalendarMetadata, // Common calendar attributes pub principal: String, pub id: String, pub timezone_id: Option, pub deleted_at: Option, pub synctoken: i64, pub subscription_url: Option, pub push_topic: String, pub components: Vec, } impl Calendar { pub fn format_synctoken(&self) -> String { format_synctoken(self.synctoken) } pub fn get_timezone(&self) -> Option { self.timezone_id .as_ref() .and_then(|tzid| chrono_tz::Tz::from_str(tzid).ok()) } pub fn get_vtimezone(&self) -> Option<&'static str> { self.timezone_id .as_ref() .and_then(|tzid| vtimezones_rs::VTIMEZONES.get(tzid).cloned()) } }