Ensure DTSTAMP is in UTC, as per RFC 5545 § 3.1

This commit is contained in:
Matteo Settenvini 2022-07-29 12:32:25 +02:00
parent 32ccc1ed72
commit 096db12c74
Signed by: matteo
GPG key ID: 8576CC1AD97D42DF
2 changed files with 376 additions and 371 deletions

View file

@ -3,7 +3,8 @@
use {
crate::recipe::Recipe,
chrono::{DateTime, Local, NaiveDate, NaiveDateTime, NaiveTime, TimeZone},
chrono::{DateTime, Local, NaiveDate, NaiveDateTime, NaiveTime, TimeZone, Utc},
ics::escape_text,
ics::properties as calprop,
ics::Event as CalEvent,
std::rc::Rc,
@ -49,13 +50,13 @@ impl<'a> From<Event> for CalEvent<'a> {
fn from(ev: Event) -> Self {
let start_time = ev.ends_at - ev.recipe.total_time();
let mut event = ics::Event::new(ev.uid.clone(), dt_fmt(&Local::now()));
event.push(calprop::Summary::new(ev.recipe.name.clone()));
let mut event = ics::Event::new(ev.uid.clone(), dt_utc_fmt(&Utc::now()));
event.push(calprop::Summary::new(escape_text(ev.recipe.name.clone())));
event.push(calprop::Description::new(format!(
"cookbook@{}",
ev.recipe.id
)));
event.push(calprop::Location::new(ev.recipe.url.clone()));
event.push(calprop::Location::new(escape_text(ev.recipe.url.clone())));
event.push(calprop::DtStart::new(dt_fmt(
&Local.from_local_datetime(&start_time).unwrap(),
)));
@ -68,7 +69,7 @@ impl<'a> From<Event> for CalEvent<'a> {
let alarm = ics::Alarm::display(
calprop::Trigger::new("-P15M"),
calprop::Description::new(ev.recipe.name.clone()),
calprop::Description::new(escape_text(ev.recipe.name.clone())),
);
event.add_alarm(alarm);
event
@ -78,3 +79,7 @@ impl<'a> From<Event> for CalEvent<'a> {
fn dt_fmt(datetime: &DateTime<Local>) -> String {
datetime.format("%Y%m%dT%H%M%S").to_string()
}
fn dt_utc_fmt(datetime: &DateTime<Utc>) -> String {
datetime.format("%Y%m%dT%H%M%SZ").to_string()
}