From 03ce10b6ddb54cfff34d9268ab12a3fb435e8acc Mon Sep 17 00:00:00 2001 From: Lennart <18233294+lennart-k@users.noreply.github.com> Date: Sat, 26 Oct 2024 14:43:27 +0200 Subject: [PATCH] CalDateTime: Add timezone guessing from TZID as well as some error handling --- crates/store/src/timestamp.rs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/crates/store/src/timestamp.rs b/crates/store/src/timestamp.rs index b305ce0..3ded9c2 100644 --- a/crates/store/src/timestamp.rs +++ b/crates/store/src/timestamp.rs @@ -70,6 +70,7 @@ impl CalDateTime { return Ok(None); }; + // Use the TZID parameter from the property let timezone = if let Some(tzid) = &prop .params .clone() @@ -91,20 +92,30 @@ impl CalDateTime { if let Ok(tz) = olson_name.parse::() { Some(tz) } else { - // TODO: handle invalid timezone name - None + return Err(Error::InvalidIcs(format!( + "Timezone has X-LIC-LOCATION property to specify a timezone from the Olson database, however it's value {olson_name} is invalid" + ))); } } else { - // No name, we would have to parse it ourselves :( - // TODO: implement - None + // If the TZID matches a name from the Olson database (e.g. Europe/Berlin) we + // guess that we can just use it + if let Ok(tz) = tzid.parse::() { + Some(tz) + } else { + // TODO: Too bad, we need to manually parse it + // For now it's just treated as localtime + None + } } } else { - // ERROR: invalid timezone specified - // For now just assume naive datetime? - None + // TZID refers to timezone that does not exist + return Err(Error::InvalidIcs(format!( + "No timezone specified with TZID={tzid}" + ))); } } else { + // No explicit timezone specified. + // This is valid and will be localtime or UTC depending on the value None };