From 2b7f6d78ad91bd83fb0977e6b535350e5500dc8b Mon Sep 17 00:00:00 2001 From: Hartmut Goebel Date: Mon, 29 Nov 2021 23:16:32 +0100 Subject: [PATCH 1/2] Improve log message for unknown timezone Closes #174. --- vobject/icalendar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vobject/icalendar.py b/vobject/icalendar.py index 325bae7..5640a77 100644 --- a/vobject/icalendar.py +++ b/vobject/icalendar.py @@ -80,7 +80,7 @@ def getTzid(tzid, smart=True): tz = timezone(tzid) registerTzid(toUnicode(tzid), tz) except UnknownTimeZoneError as e: - logging.error(e) + logging.error("Unknown Timezone: %r", e.args[0]) except ImportError as e: logging.error(e) return tz From 265020d097f8c35630bdf488a42d3242ed0998b1 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Wed, 10 Sep 2025 01:35:25 +1000 Subject: [PATCH 2/2] Add support for zoneinfo tzinfo sub-classes. zoneinfo was added to the stdlib in 3.9, and is perhaps the most likely source of tzinfo objects now. Use its 'key' attribute to get a unique timezone identifier, rather than falling back to the tzname, which isn't unique (eg. IST = Ireland, Israel, and India). Fixes #117. --- vobject/icalendar.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/vobject/icalendar.py b/vobject/icalendar.py index 5640a77..52ff94b 100644 --- a/vobject/icalendar.py +++ b/vobject/icalendar.py @@ -335,6 +335,10 @@ def pickTzid(tzinfo, allowUTC=False): if tzinfo is None or (not allowUTC and tzinfo_eq(tzinfo, utc)): return None + # Try a zoneinfo (CPython 3.9+) first. + if hasattr(tzinfo, 'key'): + return toUnicode(tzinfo.key) + # Try pytz tzid key if hasattr(tzinfo, 'tzid'): return toUnicode(tzinfo.tzid)