From aeb85f69a089bcb08ae7989f96abf89a89cdf9a9 Mon Sep 17 00:00:00 2001
From: Christian Geier <geier@lostpackets.de>
Date: Fri, 13 Feb 2015 23:59:49 +0100
Subject: [PATCH] fix for EXDATEs with TZ info and DTSTART without
The was a problem when DTSTART was localized, but EXDATEs are not (but
in Zulu time). This is easy to fix, but a problem may arise. If khal
does not understand the timezone (because icalendar does not yet support
it) it therefore applies the configured default_timezone. If
default_timezone is not the proper timezone for this event, the EXDATEs
will not be removed (but I guess the wrong offset is the bigger problem
anyway).
The same applies for RDATEs.
this should close #158 on github
---
khal/khalendar/aux.py | 5 ++---
tests/ics/event_dtr_no_tz_exdatez.ics | 12 ++++++++++++
tests/khalendar_aux_test.py | 16 ++++++++++++++++
3 files changed, 30 insertions(+), 3 deletions(-)
create mode 100644 tests/ics/event_dtr_no_tz_exdatez.ics
diff --git a/khal/khalendar/aux.py b/khal/khalendar/aux.py
index 9875cc9deb93..e5f4d657dabd 100644
--- a/khal/khalendar/aux.py
+++ b/khal/khalendar/aux.py
@@ -87,7 +87,7 @@ def expand(vevent, default_tz, href=''):
else:
rdates = vevent['RDATE']
rdates = [leaf.dt for tree in rdates for leaf in tree.dts]
- rdates = localize_strip_tz(rdates, events_tz)
+ rdates = localize_strip_tz(rdates, events_tz or default_tz)
dtstartl += rdates
# remove excluded dates
@@ -97,8 +97,7 @@ def expand(vevent, default_tz, href=''):
else:
exdates = vevent['EXDATE']
exdates = [leaf.dt for tree in exdates for leaf in tree.dts]
-
- exdates = localize_strip_tz(exdates, events_tz)
+ exdates = localize_strip_tz(exdates, events_tz or default_tz)
dtstartl = [start for start in dtstartl if start not in exdates]
if events_tz is not None:
diff --git a/tests/ics/event_dtr_no_tz_exdatez.ics b/tests/ics/event_dtr_no_tz_exdatez.ics
new file mode 100644
index 000000000000..c5d446e27988
--- /dev/null
+++ b/tests/ics/event_dtr_no_tz_exdatez.ics
@@ -0,0 +1,12 @@
+BEGIN:VCALENDAR
+VERSION:2.0
+BEGIN:VEVENT
+UID:5624b646-ba12-4dbd-ba9f-8d66319b0776
+RRULE:FREQ=MONTHLY;COUNT=6
+SUMMARY:Conf Call
+DESCRIPTION:event with not understood timezone for dtstart and zulu time form exdate
+DTSTART;TZID="LOLOLOL":20120403T100000
+DTEND;TZID="LOLOLOL":20120403T103000
+EXDATE:20120603T080000Z
+END:VEVENT
+END:VCALENDAR
diff --git a/tests/khalendar_aux_test.py b/tests/khalendar_aux_test.py
index 1984e36c5892..8b56d7967a74 100644
--- a/tests/khalendar_aux_test.py
+++ b/tests/khalendar_aux_test.py
@@ -430,6 +430,22 @@ class TestExpandNoRR(object):
dtstart = aux.expand(vevent, berlin)
assert len(dtstart) == 3
+ def test_expand_rrule_exdate_z(self):
+ """event with not understood timezone for dtstart and zulu time form
+ exdate
+ """
+ vevent = _get_vevent_file('event_dtr_no_tz_exdatez')
+ dtstart = aux.expand(vevent, berlin)
+ assert len(dtstart) == 5
+ dtstarts = [start for start, end in dtstart]
+ assert dtstarts == [
+ berlin.localize(datetime.datetime(2012, 4, 3, 10, 0)),
+ berlin.localize(datetime.datetime(2012, 5, 3, 10, 0)),
+ berlin.localize(datetime.datetime(2012, 7, 3, 10, 0)),
+ berlin.localize(datetime.datetime(2012, 8, 3, 10, 0)),
+ berlin.localize(datetime.datetime(2012, 9, 3, 10, 0)),
+ ]
+
vevent_until_notz = """BEGIN:VEVENT
SUMMARY:until 20. Februar
--
2.1.0