Skip to content

Conversation

@da4089
Copy link

@da4089 da4089 commented Feb 23, 2024

@da4089 da4089 added this to the v1.0 milestone Mar 19, 2024
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)):

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