mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 21:42:34 +00:00
caldav: Add vtimezone repository to date timezone with timezone-id
This commit is contained in:
@@ -15,7 +15,6 @@ use rustical_store::Calendar;
|
||||
use rustical_store::auth::Principal;
|
||||
use rustical_xml::{EnumVariants, PropName};
|
||||
use rustical_xml::{XmlDeserialize, XmlSerialize};
|
||||
use std::str::FromStr;
|
||||
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, EnumVariants, PropName)]
|
||||
#[xml(unit_variants_ident = "CalendarPropName")]
|
||||
@@ -199,11 +198,15 @@ impl Resource for CalendarResource {
|
||||
CalendarProp::TimezoneServiceSet(_) => Err(rustical_dav::Error::PropReadOnly),
|
||||
CalendarProp::CalendarTimezoneId(timezone_id) => {
|
||||
if let Some(tzid) = &timezone_id {
|
||||
// Validate timezone id
|
||||
chrono_tz::Tz::from_str(tzid).map_err(|_| {
|
||||
rustical_dav::Error::BadRequest(format!("Invalid timezone-id: {tzid}"))
|
||||
})?;
|
||||
// TODO: Ensure that timezone is also updated (For now hope that clients play nice)
|
||||
// Validate timezone id and set timezone accordingly
|
||||
self.cal.timezone = Some(
|
||||
vzic_rs::VTIMEZONES
|
||||
.get(tzid)
|
||||
.ok_or(rustical_dav::Error::BadRequest(format!(
|
||||
"Invalid timezone-id: {tzid}"
|
||||
)))?
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
self.cal.timezone_id = timezone_id;
|
||||
Ok(())
|
||||
@@ -305,3 +308,12 @@ impl Resource for CalendarResource {
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn test_tzdb_version() {
|
||||
// Ensure that both chrono_tz and vzic_rs use the same tzdb version
|
||||
assert_eq!(chrono_tz::IANA_TZDB_VERSION, vzic_rs::IANA_TZDB_VERSION);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user