Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions vobject/icalendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ def pickTzid(tzinfo, allowUTC=False):
"""
Given a tzinfo class, use known APIs to determine TZID, or use tzname.
"""
if str(tzinfo) == 'UTC':
return None
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest merging this clause into the next which has a comment about UTC.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested a merger of this with the following line, as you suggested. I guess an error from the test suite in branch-0.9:

======================================================================
ERROR: test_pytz_timezone_serializing (__main__.TestIcalendar)
Serializing with timezones from pytz test
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests.py", line 727, in test_pytz_timezone_serializing
    tz.serialize()
  File "/Users/d/work/personal/vobject-tmp/vobject/base.py", line 258, in serialize
    return behavior.serialize(self, buf, lineLength, validate, *args, **kwargs)
  File "/Users/d/work/personal/vobject-tmp/vobject/behavior.py", line 157, in serialize
    cls.validate(obj, raiseException=True)
  File "/Users/d/work/personal/vobject-tmp/vobject/icalendar.py", line 1073, in validate
    raise ValidateError(m)
vobject.base.ValidateError: 'VTIMEZONE components must contain a valid TZID'

----------------------------------------------------------------------

I haven't had a chance to look into this yet. It's quite possible that the test case is incorrect.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My patch was:

--- a/vobject/icalendar.py
+++ b/vobject/icalendar.py
@@ -332,7 +332,7 @@ class TimezoneComponent(Component):
         """

         # If tzinfo is UTC, we don't need a TZID
-        if tzinfo is None or (not allowUTC and tzinfo_eq(tzinfo, utc)):
+        if tzinfo is None or str(tzinfo) == 'UTC' or (not allowUTC and tzinfo_eq(tzinfo, utc)):
             return None

         # Try pytz tzid key

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is strange! Just to exclude a weird case: Have you tried

if str(tzinfo) == 'UTC' of tzinfo is None or (not allowUTC and tzinfo_eq(tzinfo, utc)):

if tzinfo is None or (not allowUTC and tzinfo_eq(tzinfo, utc)):
# If tzinfo is UTC, we don't need a TZID
return None
Expand Down