The x-wr-timezone library helps make iCalendar (ICS) files, particularly those generated by Google Calendar, compliant with the RFC 5545 standard. Google Calendar often includes a non-standard `X-WR-TIMEZONE` property, which strict parsers ignore, leading to incorrect event times. This Python module converts such calendars to a standard format by adding a `VTIMEZONE` component. The current version is 2.0.1, and it maintains an active development status with updates driven by the underlying `icalendar` library.
pip install x-wr-timezoneVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to load an iCalendar file containing the non-standard `X-WR-TIMEZONE` property, process it using `x_wr_timezone.to_standard()`, and save the resulting RFC 5545 compliant calendar. The example first creates a simple `in.ics` file for demonstration purposes.
Use `x_wr_timezone.to_standard()` to convert calendars containing `X-WR-TIMEZONE` to include RFC 5545-compliant `VTIMEZONE` components.
Always capture the return value of `to_standard()`, e.g., `new_calendar = x_wr_timezone.to_standard(original_calendar)`.
Carefully consider whether the `timezone` parameter should be used. If the `X-WR-TIMEZONE` property itself dictates the desired target, omit the `timezone` parameter. If a specific target timezone is required regardless of `X-WR-TIMEZONE`, pass it explicitly.
Refer to the `icalendar` documentation for specific version compatibility. For `icalendar` versions 5.0 and above, Python 3.7+ is required. Ensure you are using `icalendar.from_ical()` and `calendar_object.to_ical()` methods.
Install the library using `pip install x-wr-timezone` and ensure your import statement uses the correct module name, e.g., `from x_wr_timezone import convert`.
First, parse your ICS string into a `Calendar` object using `from icalendar import Calendar; cal = Calendar.from_ical(ics_string)` before passing `cal` to `convert`.
Use the correct import statement for the main conversion function: `from x_wr_timezone import convert`.
Ensure that the input ICS string is a syntactically valid iCalendar format that `icalendar.Calendar.from_ical()` can parse successfully before attempting to convert it.