Fix MS Exchange to JSCalendar conversion (closes #1 closes #2)

This commit is contained in:
Maurus Decimus
2026-06-04 12:18:56 +02:00
parent c89c5af37c
commit e49a7db278
5 changed files with 215 additions and 109 deletions
+41
View File
@@ -14,6 +14,27 @@ pub fn windows_to_iana(windows_name: &str) -> Option<&'static str> {
None
}
pub fn resolve_to_iana(value: &str) -> Option<String> {
use calcard::common::timezone::Tz;
use std::str::FromStr;
let key = value.trim();
if key.is_empty() {
return None;
}
if let Some(rest) = key.strip_prefix("tzone://Microsoft/") {
return rest
.eq_ignore_ascii_case("Utc")
.then(|| "Etc/UTC".to_owned());
}
if let Some(iana) = windows_to_iana(key) {
return Some(iana.to_owned());
}
Tz::from_str(key)
.ok()
.and_then(|tz| tz.name().map(|name| name.into_owned()))
}
const TABLE: &[(&str, &str)] = &[
("UTC", "Etc/UTC"),
("Coordinated Universal Time", "Etc/UTC"),
@@ -248,6 +269,26 @@ mod tests {
);
}
#[test]
fn resolve_handles_windows_iana_offset_and_microsoft_tzone() {
assert_eq!(
resolve_to_iana("Romance Standard Time").as_deref(),
Some("Europe/Paris")
);
assert_eq!(
resolve_to_iana("Europe/Paris").as_deref(),
Some("Europe/Paris")
);
assert_eq!(resolve_to_iana("UTC").as_deref(), Some("Etc/UTC"));
assert_eq!(
resolve_to_iana("tzone://Microsoft/Utc").as_deref(),
Some("Etc/UTC")
);
assert_eq!(resolve_to_iana("tzone://Microsoft/Custom"), None);
assert_eq!(resolve_to_iana("Made Up Zone"), None);
assert_eq!(resolve_to_iana(""), None);
}
#[test]
fn coordinated_universal_time_alias_resolves_to_utc() {
assert_eq!(