[Vobject] bug with timezone ?

Vivian Brégier Vivian.Bregier at are-ata.org
Tue Sep 2 10:38:57 CDT 2014


Hi,

I am using vobject library to write ics file from a script, and I think I
ran into a bug.

Here is a small code that reproduces the bug on my machine (python-vobject
0.8.1c, pytz 2012c)

$ cat test.py
#! /usr/bin/python

import pytz
import vobject
import datetime
tz = pytz.timezone("Europe/Paris")
cal = vobject.iCalendar()
evt = cal.add("vevent")
start = datetime.datetime(2014, 9, 1, 10, 0, tzinfo = tz)
end = datetime.datetime(2014, 9, 1, 11, 0, tzinfo = tz)
evt.add("dtstart").value = start
evt.add("dtend").value = end
print start
print end
cal.serialize()
print "OK"

$ ./test.py
2014-09-01 10:00:00+00:09
2014-09-01 11:00:00+00:09
Traceback (most recent call last):
  File "./test.py", line 15, in <module>
    cal.serialize()
  File "/usr/lib/pymodules/python2.7/vobject/base.py", line 186, in
serialize
    return behavior.serialize(self, buf, lineLength, validate)
  File "/usr/lib/pymodules/python2.7/vobject/behavior.py", line 147, in
serialize
    cls.generateImplicitParameters(obj)
  File "/usr/lib/pymodules/python2.7/vobject/icalendar.py", line 875, in
generateImplicitParameters
    obj.add(TimezoneComponent(tzinfo=getTzid(tzid)))
  File "/usr/lib/pymodules/python2.7/vobject/icalendar.py", line 75, in
__init__
    self.tzinfo = tzinfo
  File "/usr/lib/pymodules/python2.7/vobject/base.py", line 499, in
__setattr__
    prop.fset(self, value)
  File "/usr/lib/pymodules/python2.7/vobject/icalendar.py", line 145, in
settzinfo
    transition = getTransition(transitionTo, year, tzinfo)
  File "/usr/lib/pymodules/python2.7/vobject/icalendar.py", line 1897, in
getTransition
    uncorrected = firstTransition(generateDates(year, month, day), test)
  File "/usr/lib/pymodules/python2.7/vobject/icalendar.py", line 1857, in
firstTransition
    if not test(dt):
  File "/usr/lib/pymodules/python2.7/vobject/icalendar.py", line 1884, in
test
    def test(dt): return tzinfo.dst(dt) != zeroDelta
  File "/usr/lib/python2.7/dist-packages/pytz/tzinfo.py", line 445, in dst
    dt = self.localize(dt, is_dst)
  File "/usr/lib/python2.7/dist-packages/pytz/tzinfo.py", line 327, in
localize
    raise NonExistentTimeError(dt)
pytz.exceptions.NonExistentTimeError: 2000-03-26 02:00:00


If I change the timezone to tz = pytz.timezone("UTC"), it works right

$ cat test_UTC.py
#! /usr/bin/python

import pytz
import vobject
import datetime
tz = pytz.timezone("UTC")
cal = vobject.iCalendar()
evt = cal.add("vevent")
start = datetime.datetime(2014, 9, 1, 10, 0, tzinfo = tz)
end = datetime.datetime(2014, 9, 1, 11, 0, tzinfo = tz)
evt.add("dtstart").value = start
evt.add("dtend").value = end
print start
print end
cal.serialize()
print "OK"

$ ./test_UTC.py
2014-09-01 10:00:00+00:00
2014-09-01 11:00:00+00:00
OK


Regards,
-- 
Vivian Brégier
http://www.are-ata.org/Vivian.vcf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.skyhouseconsulting.com/pipermail/vobject/attachments/20140902/3560c6d9/attachment.html>


More information about the VObject mailing list