Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pytz dependency #77

Merged
merged 1 commit into from
Jun 3, 2020
Merged

Add pytz dependency #77

merged 1 commit into from
Jun 3, 2020

Conversation

silaslenz
Copy link
Contributor

Radicale requires pytz for timezone support. As is adding events with for example DTSTART;TZID=Europe/Stockholm;VALUE=DATE-TIME:20200527T101010 results in ERROR:root:No module named 'pytz', similar to here https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=886425

@tomsquest
Copy link
Owner

Hi,
Thanks for reporting it.

I saw this comment by the author of Radicale:

pytz is an optional dependency of vobject. It shouldn't be required, when your iCalendar files are valid
Kozea/Radicale#816

So:

  • first: do adding pytz solve the problem?
  • what client are you using?

I have no strong opinion on pytz, the goal is not to have the smallest of the smallest image.

Thanks,
Tom

@silaslenz
Copy link
Contributor Author

silaslenz commented May 31, 2020

I've used the caldav and icalendar Python packages. Seems like Radicale is actually able to add the event even without pytz, but does print the above mentioned error.

I tried adding an event with and without pytz installed, and with it adds a VTIMEZONE-component to the calendar, see files:
with_pytz.txt
no_pytz.txt

So according to https://icalendar.org/validator.html Radicale creates invalid ical files without pytz (or maybe py-icalendar should have added the VTIMEZONE-component and Radicale is only able to fix it if pytz is installed?).

I was using this code to add the events:

import caldav
import uuid
import pytz
import icalendar
import datetime

new_calendar = icalendar.Calendar()
event = icalendar.Event()
event.add('uid', uuid.uuid4())
event.add('summary', "test event")
event.add('dtstamp', datetime.datetime.now(tz=pytz.timezone("Europe/Stockholm")))
event.add('dtstart', datetime.datetime.now(tz=pytz.timezone("Europe/Stockholm")))
event.add('dtend', datetime.datetime.now(tz=pytz.timezone("Europe/Stockholm"))+datetime.timedelta(minutes=30))
new_calendar.add_component(event)

calendar = caldav.DAVClient("http://admin:admin@localhost:5232/admin/5367c792-5f90-c3c5-cad7-8e0960b6d1aa/").principal().calendars()[0]
calendar.add_event(new_calendar.to_ical())

And calendar.date_search(datetime.datetime.now(tz=pytz.timezone("Europe/Stockholm")),datetime.datetime.now(tz=pytz.timezone("Europe/Stockholm"))) to find them again. This didn't work without pytz, probably because it is searching at some offset due to the missing timezone information. It finds the event if i search for a wider timespan.

@tomsquest
Copy link
Owner

Thanks for the detailed answer.

I wonder : why is the code using Timezone instead of sending UTC ? That made the database (here radicale) agnostic of the consumer location/timezone (and this is what I have used at work in all case).

There was some comments, in Radicale, that basically said that the iCalendar spec requires UTC.
There is also an answer on Stackoverflow saying to convert to utc using pytz.

@silaslenz
Copy link
Contributor Author

This isn't relevant for this particular example, but i also use recurring events, and as far as i understand they would become incorrect when switching to/from daylight saving time if using UTC. I'm basing that on this Stack overflow answer: https://stackoverflow.com/a/42941087

@tomsquest
Copy link
Owner

Hi @silaslenz ,

My comment got lost.

Thanks for the link to this SO answer ! I learnt about recurrence/UTC and daylight savings! Very appreciated.

I am merging this PR and will push a tag ASAP.

@tomsquest tomsquest merged commit 6e0f98b into tomsquest:master Jun 3, 2020
@silaslenz
Copy link
Contributor Author

Perfect! Thanks for the quick merge :)

@tomsquest
Copy link
Owner

tagged as 2.1.12.1
It should hit Docker Hub soon (ETA 30 minutes I think).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants