Package: x-wr-timezone
Some calendar providers introduce the non-standardX-WR-TIMEZONEparameter
to ICS calendar files.
Strict interpretations according to RFC 5545 ignore theX-WR-TIMEZONEparameter.
This causes the times of the events to differ from those
which make use ofX-WR-TIMEZONE.This module aims to bridge the gap by converting calendars
usingX-WR-TIMEZONEto a strict RFC 5545 calendars.
So, let’s put our heads together and solve this problem for everyone!Some features of the module are:Easy install with Python’spip.Command line conversion of calendars.Piping of calendar files withwgetorcurl.Some of the requirements are:Calendars withoutX-WR-TIMEZONEare kept unchanged.Passing calendars twice to this module does not change them.InstallInstall usingpip:python3-mpipinstallx-wr-timezoneSupportDonate using GitHub SponsorsDonate using Open CollectiveDonate using thanks.devCommand Line UsageYou can standardize the calendars using your command line interface.
The examples assume thatin.icsis a calendar which may useX-WR-TIMEZONE, whereasout.icsdoes not requireX-WR-TIMEZONEfor proper display.catin.is|x-wr-timezone>out.icsx-wr-timezonein.icsout.icscurlhttps://example.org/in.ics|x-wr-timezone>out.icswget-O-https://example.org/in.ics|x-wr-timezone>out.icsYou can get usage help on the command line:x-wr-timezone--helpPythonAfter you have installed the library, you can import it.importx_wr_timezoneThe functionto_standard()converts anicalendarobject.x_wr_timezone.to_standard(an_icalendar)Here is a full example which does about as much as this module is supposed to do:importicalendar# installed with x_wr_timezoneimportx_wr_timezonewithopen("in.ics",'rb')asfile:calendar=icalendar.from_ical(file.read())new_calendar=x_wr_timezone.to_standard(calendar)# you could use the new_calendar variable nowwithopen('out.ics','wb')asfile:file.write(new_calendar.to_ical())to_standard(calendar, timezone=None)has these parameters:calendaris theicalendar.Calendarobject.timezoneis an optional time zone. By default, the time zone incalendar['X-WR-TIMEZONE']is used to check if the calendar needs
changing.
Whentimezoneis notNonehowever,calendar['X-WR-TIMEZONE']will not be tested and it is assumed that thecalendarshould be
changed as ifcalendar['X-WR-TIMEZONE']had the value oftimezone.
This does not add or change the value ofcalendar['X-WR-TIMEZONE'].
You would need to do that yourself.timezonecan be a string like"UTC"or"Europe/Berlin"or
apytz.timezoneor something thatdatetimeaccepts as a time zone..Return value: Thecalendarargument is not modified at all. The calendar
returned has the attributes and subcomponents of thecalendaronly
changed and copied where needed to return the proper value. As such,
the returned calendar might be identical to the one passed to the
function as thecalendarargument. Keep that in mind if you modify the
return value.DevelopmentClone therepositoryor its fork andcdx-wr-timezone.Optional: Install virtualenv and Python3 and create a virtual environment:pipinstallvirtualenvvirtualenv-ppython3ENVsourceENV/bin/activate# you need to do this for each shellInstall the packages and this module so it can be edited:pipinstall-rtest-requirements.txt-e.Run the tests:pytestTo test all functions:pytest--x-wr-timezoneallTesting withtoxYou can usetoxto test the package in different Python versions.toxThis tests all the different functionalities:tox----x-wr-timezoneallNew ReleasesTo release new versions,edit the Changelog Sectionedit setup.py, the__version__variablecreate a commit and push itWait forCI teststo finish the build.runpython3setup.pytag_and_deploynotify the issues about their releaseTestingThis project’s development is driven by tests.
Tests assure a consistent interface and less knowledge lost over time.
If you like to change the code, tests help that nothing breaks in the future.
They are required in that sense.
Example code and ics files can be transferred into tests and speed up fixing bugs.You can view the tests in thetest folder.
If you have a calendar ICS file for which this library does not
generate the desired output, you can add it to thetest/calendarsfolder and write tests for what you expect.
If you like,open an issuefirst, e.g. to discuss the changes and
how to go about it.Changelogv0.0.6Obsolete Python 3.7Support Python 3.11Fix localization issue for pytz when datetime has no timezoneRun tests on GitHub ActionsRequire icalendar 5.0.11 for testsFix pytz localization issue when dateime is not in UTC and has no time zone.v0.0.5Revisit README and CLI and fix spelling mistakes.Modified behavior to treat events without time zone found in a calendar using the X-WR-TIMEZONE property, seePull Request 7v0.0.4Test automatic deployment with Gitlab CI.v0.0.3Usetzname()function ofdatetimeto test for UTC. This helps support zoneinfo time zones.Split up visitor class and rename it to walker.v0.0.2Implement thetimezoneargument.Do not modify the value of thecalendarargument and only copy it where needed.v0.0.1Initial release supports DTSTART, DTEND, EXDATE, RDATE, RECURRENCE-ID attributes of events.Command line interface asx-wr-timezone.Related WorkThis module was reated beause of these issues:icalendar#343python-recurring-ical-events#71Related SoftwareThis module uses theicalendarlibrary for parsing calendars.
This library is used bypython-recurring-ical-eventsto get events at specific dates.LicenseThis software is licensed under LGPLv3, see the LICENSE file.