mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 08:12:24 +00:00
CalDateTime: Add timezone guessing from TZID as well as some error handling
This commit is contained in:
@@ -70,6 +70,7 @@ impl CalDateTime {
|
|||||||
return Ok(None);
|
return Ok(None);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Use the TZID parameter from the property
|
||||||
let timezone = if let Some(tzid) = &prop
|
let timezone = if let Some(tzid) = &prop
|
||||||
.params
|
.params
|
||||||
.clone()
|
.clone()
|
||||||
@@ -91,20 +92,30 @@ impl CalDateTime {
|
|||||||
if let Ok(tz) = olson_name.parse::<Tz>() {
|
if let Ok(tz) = olson_name.parse::<Tz>() {
|
||||||
Some(tz)
|
Some(tz)
|
||||||
} else {
|
} else {
|
||||||
// TODO: handle invalid timezone name
|
return Err(Error::InvalidIcs(format!(
|
||||||
None
|
"Timezone has X-LIC-LOCATION property to specify a timezone from the Olson database, however it's value {olson_name} is invalid"
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// No name, we would have to parse it ourselves :(
|
// If the TZID matches a name from the Olson database (e.g. Europe/Berlin) we
|
||||||
// TODO: implement
|
// guess that we can just use it
|
||||||
|
if let Ok(tz) = tzid.parse::<Tz>() {
|
||||||
|
Some(tz)
|
||||||
|
} else {
|
||||||
|
// TODO: Too bad, we need to manually parse it
|
||||||
|
// For now it's just treated as localtime
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// ERROR: invalid timezone specified
|
|
||||||
// For now just assume naive datetime?
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// 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
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user