Implement calendar property

This commit is contained in:
Jan-Henrik 2024-01-07 13:39:31 +01:00
parent 3d61b979c4
commit 018e219b04

View file

@ -33,10 +33,12 @@ struct CustomCalendarEntry {
location: String, location: String,
description: String, description: String,
isallday: bool, isallday: bool,
calendar: u64,
} }
async fn convert(urls: &[&str], days: Option<&String>) -> Result<CustomCalendar> { async fn convert(urls: &[&str], days: Option<&String>) -> Result<CustomCalendar> {
let mut entries = Vec::new(); let mut entries = Vec::new();
let mut calendar_index = 0;
for url in urls { for url in urls {
let url = urlencoding::decode(url)?.into_owned(); let url = urlencoding::decode(url)?.into_owned();
let ics_text = reqwest::get(url) let ics_text = reqwest::get(url)
@ -88,11 +90,14 @@ async fn convert(urls: &[&str], days: Option<&String>) -> Result<CustomCalendar>
location: event.get_location().unwrap_or("").to_string(), location: event.get_location().unwrap_or("").to_string(),
start: start.timestamp(), start: start.timestamp(),
end: end.timestamp(), end: end.timestamp(),
calendar: calendar_index,
isallday: start.time() == chrono::NaiveTime::from_hms_opt(0, 0, 0).unwrap() && end - start == chrono::Duration::days(1) // the event has a length of 24 hours and isallday: start.time() == chrono::NaiveTime::from_hms_opt(0, 0, 0).unwrap() && end - start == chrono::Duration::days(1) // the event has a length of 24 hours and
// starts at 00:00 // starts at 00:00
}); });
} }
} }
calendar_index += 1;
} }
Ok(CustomCalendar{entries}) Ok(CustomCalendar{entries})