x-wr-timezone

2.0.1 · active · verified Sun Apr 12

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.

Warnings

Install

Imports

Quickstart

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.

import icalendar
import x_wr_timezone

# Example: Create a dummy in.ics with X-WR-TIMEZONE for demonstration
# In a real scenario, you would load an existing .ics file.
ics_content_in = """BEGIN:VCALENDAR
PRODID:-//Google Inc//Google Calendar 70.9054//EN
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:PUBLISH
X-WR-CALNAME:Test Calendar
X-WR-TIMEZONE:America/New_York
BEGIN:VEVENT
DTSTART:20260412T100000
DTEND:20260412T110000
DTSTAMP:20260412T000000Z
UID:dummy_event_1@example.com
SUMMARY:Test Event with X-WR-TIMEZONE
END:VEVENT
END:VCALENDAR"""

with open("in.ics", 'w') as f:
    f.write(ics_content_in)

print("Created 'in.ics' with non-standard X-WR-TIMEZONE.")

# Load the calendar from the (dummy) file
with open("in.ics", 'rb') as file:
    calendar = icalendar.from_ical(file.read())

# Standardize the calendar
# This will convert X-WR-TIMEZONE into an RFC 5545 compliant VTIMEZONE component
new_calendar = x_wr_timezone.to_standard(calendar)

# Save the standardized calendar to a new file
with open("out.ics", 'wb') as file:
    file.write(new_calendar.to_ical())

print("Processed 'in.ics' and saved standardized calendar to 'out.ics'.")
print("You can inspect 'out.ics' to see the added VTIMEZONE component.")

view raw JSON →