Skip to content

Commit a466b7c

Browse files
authored
Merge pull request #1501 from pwilke/fix-windows-vtimezone-import
fix: match Windows-style VTIMEZONE to its event on import
2 parents 2de9c1e + 6e64e1e commit a466b7c

4 files changed

Lines changed: 23 additions & 5 deletions

File tree

‎AUTHORS.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,6 @@ Alnoman Kamil - noman [at] kamil [dot] gr - https://kamil.gr
6060
Leonardo Taccari - iamleot [at] gmail [dot] com
6161
Jorenar - dev [at] jorenar [dot] com - https://jorenar.com
6262
John Wassilak - john [at] wassilak [dot] com
63+
Pierre Wilke - wilke.pierre [at] gmail [dot] com
6364
Muhammad Umar Nadeem
6465
Aleksei Stepanov - penguinolog [at] gmail [dot] com

‎CHANGELOG.rst‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ unreleased
1414
* FIX place ``monthdisplay`` in the ``[view]`` section of the sample configuration
1515
* FIX ``khal import --format``/``-f`` was accepted and then ignored, always
1616
falling back to ``view.event_format``
17+
* FIX importing an ``.ics`` with a Windows-style timezone name (e.g. from
18+
Outlook/Exchange, ``W. Europe Standard Time``) no longer emits a spurious
19+
"Cannot find timezone [...] this could be a bug" warning; the ``VTIMEZONE``
20+
is now matched to its event and kept in the imported event
1721
* CHANGE if ``datetimeformat`` or ``longdatetimeformat`` are not set, they now
1822
default to ``dateformat`` (or ``longdateformat``) followed by ``timeformat``
1923
instead of ``%c``, so ``khal new`` understands start and end times written in

‎khal/icalendar.py‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,17 @@ def split_ics(ics: str, random_uid: bool = False, default_timezone=None) -> list
5757
# Standard Time' for 'Pacific/Auckland' in Olson format), we convert any
5858
# Windows format timezones to Olson.
5959
if item.name == "VTIMEZONE":
60+
# Store the VTIMEZONE under its original TZID. Depending on the
61+
# icalendar version, an event's datetime may keep the (possibly
62+
# Windows-style) TZID as its tzinfo name, so this key is what the
63+
# lookup in ics_from_list() uses.
64+
tzs[item["TZID"]] = item
65+
# Also store it under the Olson name so events that reference the
66+
# timezone by its Olson equivalent (or whose tzinfo icalendar has
67+
# already normalized to Olson) can find it too.
6068
if item["TZID"] in icalendar.timezone.windows_to_olson.WINDOWS_TO_OLSON:
61-
key = icalendar.timezone.windows_to_olson.WINDOWS_TO_OLSON[item["TZID"]]
62-
else:
63-
key = item["TZID"]
64-
tzs[key] = item
69+
olson = icalendar.timezone.windows_to_olson.WINDOWS_TO_OLSON[item["TZID"]]
70+
tzs[olson] = item
6571

6672
if item.name == "VEVENT":
6773
if "UID" not in item:

‎tests/icalendar_test.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,15 @@ def test_split_ics_missing_timezone():
110110
def test_windows_timezone(caplog):
111111
"""Test if a windows tz format works"""
112112
cal = _get_text("tz_windows_format")
113-
split_ics(cal)
113+
vevents = split_ics(cal)
114+
# No "cannot find timezone" warning should be emitted: the VTIMEZONE is
115+
# present in the file, under its (Windows-style) TZID. Check for both the
116+
# Olson name and the original Windows TZID, since the datetime's tzinfo may
117+
# keep either depending on the icalendar version.
114118
assert "Cannot find timezone `Pacific/Auckland`" not in caplog.text
119+
assert "Cannot find timezone `New Zealand Standard Time`" not in caplog.text
120+
# and the VTIMEZONE must be carried over into the split output
121+
assert "BEGIN:VTIMEZONE" in vevents[0]
115122

116123

117124
def test_split_ics_without_uid():

0 commit comments

Comments
 (0)