refactored to make it more input-agnostic

This commit is contained in:
_ 2025-08-14 03:33:12 +00:00
parent dfbf23ed6a
commit 92c30167df
2 changed files with 40 additions and 24 deletions

View file

@ -1,6 +1,6 @@
//! Structs and functions specific to gathering input from ics files, which is a popular format that Google Calendar happens to put out
use super::{CalendarUi, DatePerhapsTime, Downloadable, EventInstance, Parameters, RecurrenceKey};
use super::{CalendarUi, DatePerhapsTime, Downloadable, EventInstance, Parameters};
use anyhow::{Context as _, Result, anyhow};
use base64::Engine as _;
use chrono::TimeZone as _;
@ -163,11 +163,17 @@ fn ical_event_instances(
None
};
let recurrence_id = ev
.get_recurrence_id()
.as_ref()
.map(|x| normalize_date_perhaps_time(x, params.tz))
.transpose()?;
Ok::<_, anyhow::Error>(EventInstance {
calendar_ui: config_ical.ui.clone(),
dtstart,
location: ev.get_location().map(|s| s.to_string()),
recurrence_id: ev.get_recurrence_id(),
recurrence_id,
summary: ev.get_summary().map(|s| s.to_string()),
uid,
url,
@ -177,6 +183,13 @@ fn ical_event_instances(
instances
}
/// Used to link recurrence exceptions to the original events they replace
#[derive(Eq, Ord, PartialOrd, PartialEq)]
struct RecurrenceKey<'a> {
recurrence_id: DatePerhapsTime,
uid: &'a str,
}
impl Calendar {
pub(crate) fn read_from_str(config: Config, s: &str) -> Result<Self> {
let cal = s.parse().map_err(|s| anyhow!("parse error {s}"))?;