summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2014-07-09 17:55:18 -0400
committerThomas Bruederli <bruederli@kolabsys.com>2014-07-09 17:55:18 -0400
commit2e506e215f44a6df7299ee0a424931b95fd5062c (patch)
treeedee74fdbdf7481037f601b8a04c5c286eab3c23
parent3e492389ad7f2d628134b3471bc2e4e054b7d204 (diff)
downloadpykolab-2e506e215f44a6df7299ee0a424931b95fd5062c.tar.gz
Shift event end date by one day when converting all-day events from/to iCal
-rw-r--r--pykolab/xml/event.py9
-rw-r--r--tests/unit/test-003-event.py20
2 files changed, 28 insertions, 1 deletions
diff --git a/pykolab/xml/event.py b/pykolab/xml/event.py
index de9e4d9..8550714 100644
--- a/pykolab/xml/event.py
+++ b/pykolab/xml/event.py
@@ -419,7 +419,11 @@ class Event(object):
return self.get_created()
def get_ical_dtend(self):
- return self.get_end()
+ dtend = self.get_end()
+ # shift end by one day on all-day events
+ if not hasattr(dtend, 'hour'):
+ dtend = dtend + datetime.timedelta(days=1)
+ return dtend
def get_ical_dtstamp(self):
try:
@@ -632,6 +636,9 @@ class Event(object):
att = self.add_attendee(address, name=name, rsvp=rsvp, role=role, participant_status=partstat, cutype=cutype, params=params)
def set_ical_dtend(self, dtend):
+ # shift end by one day on all-day events
+ if not hasattr(dtend, 'hour'):
+ dtend = dtend - datetime.timedelta(days=1)
self.set_end(dtend)
def set_ical_dtstamp(self, dtstamp):
diff --git a/tests/unit/test-003-event.py b/tests/unit/test-003-event.py
index 81337d9..2c5a478 100644
--- a/tests/unit/test-003-event.py
+++ b/tests/unit/test-003-event.py
@@ -1,3 +1,4 @@
+import re
import datetime
import pytz
import sys
@@ -218,6 +219,25 @@ METHOD:REQUEST
self.assertEqual(parts[3]['Content-ID'].strip('<>'), attachments[0].uri()[4:])
self.assertEqual(parts[4]['Content-ID'].strip('<>'), attachments[1].uri()[4:])
+ def test_018_ical_allday_events(self):
+ ical = """BEGIN:VEVENT
+UID:ffffffff-f783-4b58-b404-b1389bd2ffff
+DTSTAMP;VALUE=DATE-TIME:20140407T122311Z
+CREATED;VALUE=DATE-TIME:20140407T122245Z
+DTSTART;VALUE=DATE:20140823
+DTEND;VALUE=DATE:20140824
+SUMMARY:All day
+DESCRIPTION:One single day
+TRANSP:OPAQUE
+CLASS:PUBLIC
+END:VEVENT
+"""
+ event = event_from_ical(ical)
+ self.assertEqual(str(event.get_start()), "2014-08-23")
+ self.assertEqual(str(event.get_end()), "2014-08-23")
+ self.assertEqual(str(event.get_ical_dtend()), "2014-08-24")
+ self.assertTrue(re.match('.*<dtend>\s*<date>2014-08-23</date>', str(event), re.DOTALL))
+
def test_019_as_string_itip(self):
self.event.set_summary("test")
self.event.set_start(datetime.datetime(2014, 05, 23, 11, 00, 00, tzinfo=pytz.timezone("Europe/London")))