aboutsummaryrefslogtreecommitdiff
path: root/aero-proto/src/dav/controller.rs
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2024-05-23 10:01:43 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2024-05-23 10:01:43 +0200
commitff823a10f049e06c711537560ba10f3dc826afcd (patch)
tree25000784fef0758b7aad1990d3d14ecbe7eae46d /aero-proto/src/dav/controller.rs
parent7687065bfc824127fda657363894a30268e95385 (diff)
downloadaerogramme-ff823a10f049e06c711537560ba10f3dc826afcd.tar.gz
aerogramme-ff823a10f049e06c711537560ba10f3dc826afcd.zip
improve ical date parsing
Diffstat (limited to 'aero-proto/src/dav/controller.rs')
-rw-r--r--aero-proto/src/dav/controller.rs30
1 files changed, 18 insertions, 12 deletions
diff --git a/aero-proto/src/dav/controller.rs b/aero-proto/src/dav/controller.rs
index 0a47cf4..4cf520e 100644
--- a/aero-proto/src/dav/controller.rs
+++ b/aero-proto/src/dav/controller.rs
@@ -380,6 +380,22 @@ fn apply_filter<'a>(
})
}
+fn ical_parse_date(dt: &str) -> Option<chrono::DateTime<chrono::Utc>> {
+ tracing::trace!(raw_time = dt, "VEVENT raw time");
+ let tmpl = match dt.chars().last() {
+ Some('Z') => cal::UTC_DATETIME_FMT,
+ Some(_) => {
+ tracing::warn!(raw_time=dt, "floating datetime is not properly supported yet");
+ cal::FLOATING_DATETIME_FMT
+ },
+ None => return None
+ };
+
+ NaiveDateTime::parse_from_str(dt, tmpl)
+ .ok()
+ .map(|v| v.and_utc())
+}
+
fn prop_date(
properties: &[icalendar::parser::Property],
name: &str,
@@ -388,12 +404,7 @@ fn prop_date(
.iter()
.find(|candidate| candidate.name.as_str() == name)
.map(|p| p.val.as_str())
- .map(|raw_time| {
- tracing::trace!(raw_time = raw_time, "VEVENT raw time");
- NaiveDateTime::parse_from_str(raw_time, cal::ICAL_DATETIME_FMT)
- .ok()
- .map(|v| v.and_utc())
- })
+ .map(ical_parse_date)
.flatten()
}
@@ -412,12 +423,7 @@ fn is_properties_match(props: &[icalendar::parser::Property], filters: &[cal::Pr
// check value
match &pattern.time_or_text {
Some(cal::TimeOrText::Time(time_range)) => {
- let maybe_parsed_date = NaiveDateTime::parse_from_str(
- prop.val.as_str(),
- cal::ICAL_DATETIME_FMT,
- )
- .ok()
- .map(|v| v.and_utc());
+ let maybe_parsed_date = ical_parse_date(prop.val.as_str());
let parsed_date = match maybe_parsed_date {
None => return false,