aboutsummaryrefslogtreecommitdiff
path: root/aero-dav
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2024-05-22 15:02:53 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2024-05-22 15:02:53 +0200
commit6ca7082197aa60288c3295387bfdf47d8adbed2d (patch)
tree4f6e47bae54106f4144620839a41aa91a91f597e /aero-dav
parent194e34d4e1b28957d8310ea1205989fadb1b44c7 (diff)
downloadaerogramme-6ca7082197aa60288c3295387bfdf47d8adbed2d.tar.gz
aerogramme-6ca7082197aa60288c3295387bfdf47d8adbed2d.zip
fix: parsing components & times
Diffstat (limited to 'aero-dav')
-rw-r--r--aero-dav/src/caldecoder.rs18
-rw-r--r--aero-dav/src/calencoder.rs33
-rw-r--r--aero-dav/src/caltypes.rs3
3 files changed, 29 insertions, 25 deletions
diff --git a/aero-dav/src/caldecoder.rs b/aero-dav/src/caldecoder.rs
index b4391a4..1de4552 100644
--- a/aero-dav/src/caldecoder.rs
+++ b/aero-dav/src/caldecoder.rs
@@ -287,7 +287,7 @@ impl QRead<Property> for Property {
.is_some()
{
let dtstr = xml.tag_string().await?;
- let dt = NaiveDateTime::parse_from_str(dtstr.as_str(), ICAL_DATETIME_FMT)?.and_utc();
+ let dt = NaiveDateTime::parse_from_str(dtstr.as_str(), CALDAV_DATETIME_FMT)?.and_utc();
xml.close().await?;
return Ok(Property::MaxDateTime(dt));
}
@@ -653,8 +653,8 @@ impl QRead<Expand> for Expand {
_ => return Err(ParsingError::MissingAttribute),
};
- let start = NaiveDateTime::parse_from_str(rstart.as_str(), ICAL_DATETIME_FMT)?.and_utc();
- let end = NaiveDateTime::parse_from_str(rend.as_str(), ICAL_DATETIME_FMT)?.and_utc();
+ let start = NaiveDateTime::parse_from_str(rstart.as_str(), CALDAV_DATETIME_FMT)?.and_utc();
+ let end = NaiveDateTime::parse_from_str(rend.as_str(), CALDAV_DATETIME_FMT)?.and_utc();
if start > end {
return Err(ParsingError::InvalidValue);
}
@@ -672,8 +672,8 @@ impl QRead<LimitRecurrenceSet> for LimitRecurrenceSet {
_ => return Err(ParsingError::MissingAttribute),
};
- let start = NaiveDateTime::parse_from_str(rstart.as_str(), ICAL_DATETIME_FMT)?.and_utc();
- let end = NaiveDateTime::parse_from_str(rend.as_str(), ICAL_DATETIME_FMT)?.and_utc();
+ let start = NaiveDateTime::parse_from_str(rstart.as_str(), CALDAV_DATETIME_FMT)?.and_utc();
+ let end = NaiveDateTime::parse_from_str(rend.as_str(), CALDAV_DATETIME_FMT)?.and_utc();
if start > end {
return Err(ParsingError::InvalidValue);
}
@@ -691,8 +691,8 @@ impl QRead<LimitFreebusySet> for LimitFreebusySet {
_ => return Err(ParsingError::MissingAttribute),
};
- let start = NaiveDateTime::parse_from_str(rstart.as_str(), ICAL_DATETIME_FMT)?.and_utc();
- let end = NaiveDateTime::parse_from_str(rend.as_str(), ICAL_DATETIME_FMT)?.and_utc();
+ let start = NaiveDateTime::parse_from_str(rstart.as_str(), CALDAV_DATETIME_FMT)?.and_utc();
+ let end = NaiveDateTime::parse_from_str(rend.as_str(), CALDAV_DATETIME_FMT)?.and_utc();
if start > end {
return Err(ParsingError::InvalidValue);
}
@@ -918,13 +918,13 @@ impl QRead<TimeRange> for TimeRange {
let start = match xml.prev_attr("start") {
Some(r) => {
- Some(NaiveDateTime::parse_from_str(r.as_str(), ICAL_DATETIME_FMT)?.and_utc())
+ Some(NaiveDateTime::parse_from_str(r.as_str(), CALDAV_DATETIME_FMT)?.and_utc())
}
_ => None,
};
let end = match xml.prev_attr("end") {
Some(r) => {
- Some(NaiveDateTime::parse_from_str(r.as_str(), ICAL_DATETIME_FMT)?.and_utc())
+ Some(NaiveDateTime::parse_from_str(r.as_str(), CALDAV_DATETIME_FMT)?.and_utc())
}
_ => None,
};
diff --git a/aero-dav/src/calencoder.rs b/aero-dav/src/calencoder.rs
index 4467f7c..f145628 100644
--- a/aero-dav/src/calencoder.rs
+++ b/aero-dav/src/calencoder.rs
@@ -178,7 +178,7 @@ impl QWrite for Property {
let start = xml.create_cal_element("min-date-time");
let end = start.to_end();
- let dtstr = format!("{}", dt.format(ICAL_DATETIME_FMT));
+ let dtstr = format!("{}", dt.format(CALDAV_DATETIME_FMT));
xml.q.write_event_async(Event::Start(start.clone())).await?;
xml.q
.write_event_async(Event::Text(BytesText::new(dtstr.as_str())))
@@ -189,7 +189,7 @@ impl QWrite for Property {
let start = xml.create_cal_element("max-date-time");
let end = start.to_end();
- let dtstr = format!("{}", dt.format(ICAL_DATETIME_FMT));
+ let dtstr = format!("{}", dt.format(CALDAV_DATETIME_FMT));
xml.q.write_event_async(Event::Start(start.clone())).await?;
xml.q
.write_event_async(Event::Text(BytesText::new(dtstr.as_str())))
@@ -493,11 +493,11 @@ impl QWrite for Expand {
let mut empty = xml.create_cal_element("expand");
empty.push_attribute((
"start",
- format!("{}", self.0.format(ICAL_DATETIME_FMT)).as_str(),
+ format!("{}", self.0.format(CALDAV_DATETIME_FMT)).as_str(),
));
empty.push_attribute((
"end",
- format!("{}", self.1.format(ICAL_DATETIME_FMT)).as_str(),
+ format!("{}", self.1.format(CALDAV_DATETIME_FMT)).as_str(),
));
xml.q.write_event_async(Event::Empty(empty)).await
}
@@ -508,11 +508,11 @@ impl QWrite for LimitRecurrenceSet {
let mut empty = xml.create_cal_element("limit-recurrence-set");
empty.push_attribute((
"start",
- format!("{}", self.0.format(ICAL_DATETIME_FMT)).as_str(),
+ format!("{}", self.0.format(CALDAV_DATETIME_FMT)).as_str(),
));
empty.push_attribute((
"end",
- format!("{}", self.1.format(ICAL_DATETIME_FMT)).as_str(),
+ format!("{}", self.1.format(CALDAV_DATETIME_FMT)).as_str(),
));
xml.q.write_event_async(Event::Empty(empty)).await
}
@@ -523,11 +523,11 @@ impl QWrite for LimitFreebusySet {
let mut empty = xml.create_cal_element("limit-freebusy-set");
empty.push_attribute((
"start",
- format!("{}", self.0.format(ICAL_DATETIME_FMT)).as_str(),
+ format!("{}", self.0.format(CALDAV_DATETIME_FMT)).as_str(),
));
empty.push_attribute((
"end",
- format!("{}", self.1.format(ICAL_DATETIME_FMT)).as_str(),
+ format!("{}", self.1.format(CALDAV_DATETIME_FMT)).as_str(),
));
xml.q.write_event_async(Event::Empty(empty)).await
}
@@ -737,18 +737,21 @@ impl QWrite for TimeRange {
match self {
Self::OnlyStart(start) => empty.push_attribute((
"start",
- format!("{}", start.format(ICAL_DATETIME_FMT)).as_str(),
+ format!("{}", start.format(CALDAV_DATETIME_FMT)).as_str(),
+ )),
+ Self::OnlyEnd(end) => empty.push_attribute((
+ "end",
+ format!("{}", end.format(CALDAV_DATETIME_FMT)).as_str(),
)),
- Self::OnlyEnd(end) => {
- empty.push_attribute(("end", format!("{}", end.format(ICAL_DATETIME_FMT)).as_str()))
- }
Self::FullRange(start, end) => {
empty.push_attribute((
"start",
- format!("{}", start.format(ICAL_DATETIME_FMT)).as_str(),
+ format!("{}", start.format(CALDAV_DATETIME_FMT)).as_str(),
+ ));
+ empty.push_attribute((
+ "end",
+ format!("{}", end.format(CALDAV_DATETIME_FMT)).as_str(),
));
- empty
- .push_attribute(("end", format!("{}", end.format(ICAL_DATETIME_FMT)).as_str()));
}
}
xml.q.write_event_async(Event::Empty(empty)).await
diff --git a/aero-dav/src/caltypes.rs b/aero-dav/src/caltypes.rs
index 717086b..924b651 100644
--- a/aero-dav/src/caltypes.rs
+++ b/aero-dav/src/caltypes.rs
@@ -3,7 +3,8 @@
use super::types as dav;
use chrono::{DateTime, Utc};
-pub const ICAL_DATETIME_FMT: &str = "%Y%m%dT%H%M%SZ";
+pub const ICAL_DATETIME_FMT: &str = "%Y%m%dT%H%M%S";
+pub const CALDAV_DATETIME_FMT: &str = "%Y%m%dT%H%M%SZ";
//@FIXME ACL (rfc3744) is missing, required
//@FIXME Versioning (rfc3253) is missing, required