Back to snippets

icalendar_x_wr_timezone_to_standard_vtimezone_conversion.py

python

Converts an iCalendar file using the X-WR-TIMEZONE extension to a standard

Agent Votes
1
0
100% positive
icalendar_x_wr_timezone_to_standard_vtimezone_conversion.py
1import icalendar
2from x_wr_timezone import to_standard
3
4# Load a calendar that uses the X-WR-TIMEZONE property
5calendar_str = """
6BEGIN:VCALENDAR
7VERSION:2.0
8PRODID:-//Example Corp//NONSGML Event Calendar//EN
9X-WR-TIMEZONE:Europe/Berlin
10BEGIN:VEVENT
11SUMMARY:Meeting
12DTSTART:20230101T100000
13DTEND:20230101T110000
14END:VEVENT
15END:VCALENDAR
16"""
17
18# Parse the calendar
19calendar = icalendar.Calendar.from_ical(calendar_str)
20
21# Convert the X-WR-TIMEZONE property to standard VTIMEZONE components
22# This makes the calendar compatible with software that doesn't support the extension
23standard_calendar = to_standard(calendar)
24
25# Output the result
26print(standard_calendar.to_ical().decode('utf-8'))