[Vobject] Problem with Timezones and iCalendar

Alexander Johannes alex at nirgal.de
Wed Nov 24 01:16:38 CST 2010


Hello,

i'd like to create an iCalendar, whose Events are coming from a  
database¹. Unfortunately the date/time-entries are stored in local  
time without any Timezone-info. So i tried to utilize the pytz-Library  
(http://pytz.sourceforge.net), which takes care of the proper DST- 
handling. Feeding those dates into a vevent leads to an error.

Please consider the following minimal code:

import datetime
import pytz
import vobject

dt = datetime.datetime(2010,7,1,10,0,0)
de = pytz.timezone('Europe/Berlin')

cal = vobject.iCalendar()
event = cal.add('vevent')
event.add('dtstart').value = de.localize(dt)

cal.serialize()

It will give me the following error:

Traceback (most recent call last):
   File "vobject_error.py", line 12, in <module>
     cal.serialize()
   File "build/bdist.freebsd-7.2-RELEASE-p8-i386/egg/vobject/base.py",  
line 186, in serialize
   File "build/bdist.freebsd-7.2-RELEASE-p8-i386/egg/vobject/ 
behavior.py", line 147, in serialize
   File "build/bdist.freebsd-7.2-RELEASE-p8-i386/egg/vobject/ 
icalendar.py", line 863, in generateImplicitParameters
   File "build/bdist.freebsd-7.2-RELEASE-p8-i386/egg/vobject/ 
icalendar.py", line 75, in __init__
   File "build/bdist.freebsd-7.2-RELEASE-p8-i386/egg/vobject/base.py",  
line 497, in __setattr__
   File "build/bdist.freebsd-7.2-RELEASE-p8-i386/egg/vobject/ 
icalendar.py", line 145, in settzinfo
   File "build/bdist.freebsd-7.2-RELEASE-p8-i386/egg/vobject/ 
icalendar.py", line 1880, in getTransition
   File "build/bdist.freebsd-7.2-RELEASE-p8-i386/egg/vobject/ 
icalendar.py", line 1840, in firstTransition
   File "build/bdist.freebsd-7.2-RELEASE-p8-i386/egg/vobject/ 
icalendar.py", line 1867, in test
   File "build/bdist.freebsd-7.2-RELEASE-p8-i386/egg/pytz/tzinfo.py",  
line 401, in dst
   File "build/bdist.freebsd-7.2-RELEASE-p8-i386/egg/pytz/tzinfo.py",  
line 286, in localize
pytz.tzinfo.NonExistentTimeError: 2000-03-26 02:00:00

As you can see, the NonExistentTimeError is triggered by the date  
'2000-03-26 02:00:00', which is not the date, i have put into the  
event. So the iCalendar seems to do some additional timezone/dst- 
tinkering, which i cant quite figure out.
When i don't localize the date, the serialization is fine.

Maybe someone on the list can shed some light on what's going wrong  
here.

TIA,

Alex

¹) django with sqlite


More information about the VObject mailing list