use ical::tree::cst::IcalCst;
fn main() {
let broken = concat!(
"BEGIN:VCALENDAR\r\n",
"VERSION:2.0\r\n",
"BEGIN:VEVENT\r\n",
"SUMMARY;PARTSTAT=ACCEPTED:Planning\r\n",
"DTSTART:20260105T090000Z\r\n",
"RRULE:FREQ=MONTHLY;BYWEEKNO=3\r\n",
"BEGIN:VTIMEZONE\r\n",
"TZID:Europe/Paris\r\n",
"END:VTIMEZONE\r\n",
"END:VEVENT\r\n",
"END:VCALENDAR\r\n",
);
let cst = IcalCst::parse(broken).unwrap();
assert_eq!(cst.to_string(), broken);
println!("what a strict server would reject:");
match cst.decode().validate() {
Ok(_) => println!(" nothing"),
Err(problems) => {
for problem in &problems {
println!(" {problem}");
}
}
}
let repaired = concat!(
"BEGIN:VCALENDAR\r\n",
"VERSION:2.0\r\n",
"PRODID:-//Example//EN\r\n",
"BEGIN:VEVENT\r\n",
"UID:planning@example.com\r\n",
"DTSTAMP:20260101T000000Z\r\n",
"SUMMARY:Planning\r\n",
"DTSTART:20260105T090000Z\r\n",
"RRULE:FREQ=YEARLY;BYWEEKNO=3\r\n",
"X-INTERNAL-ID:4711\r\n",
"END:VEVENT\r\n",
"END:VCALENDAR\r\n",
);
let cst = IcalCst::parse(repaired).unwrap();
let valid = cst.decode().validate().expect("a conformant calendar");
println!("\nvalidated: {} component(s)", valid.components.len());
print!("{}", IcalCst::from(valid));
}