summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksander Machniak <machniak@kolabsys.com>2019-04-12 10:34:58 +0000
committerAleksander Machniak <machniak@kolabsys.com>2019-04-12 10:34:58 +0000
commit23e2c4637f55514e5aa3e687df28e355b0f00488 (patch)
tree4d5ef02916312300398330497a62e65e235ed3c3
parentc5e12dc1cf8d93d3fa408d57938b93fda506330a (diff)
downloadpykolab-23e2c4637f55514e5aa3e687df28e355b0f00488.tar.gz
Be more forgiving on dummy entries in DTSTAMP,LAST-MODIFIED and CREATED (Bifrost#T123747)
Instead of throwing an error when parsing iTip data that contains e.g. 00000000T000000, which will converted to datetime.time object by icalendar lib, convert them to datetime.date (1970-01-01 or "utc now").
-rw-r--r--pykolab/xml/event.py4
-rw-r--r--pykolab/xml/utils.py26
-rw-r--r--tests/unit/test-003-event.py18
3 files changed, 27 insertions, 21 deletions
diff --git a/pykolab/xml/event.py b/pykolab/xml/event.py
index 102ebce..276bb6f 100644
--- a/pykolab/xml/event.py
+++ b/pykolab/xml/event.py
@@ -822,7 +822,7 @@ class Event(object):
raise ValueError, _("Invalid classification %r") % (classification)
def set_created(self, _datetime=None):
- if _datetime == None:
+ if _datetime is None or isinstance(_datetime, datetime.time):
_datetime = datetime.datetime.utcnow()
self.event.setCreated(xmlutils.to_cdatetime(_datetime, False, True))
@@ -1012,7 +1012,7 @@ class Event(object):
if isinstance(_datetime, datetime.datetime):
valid_datetime = True
- if _datetime == None:
+ if _datetime is None or isinstance(_datetime, datetime.time):
valid_datetime = True
_datetime = datetime.datetime.utcnow()
diff --git a/pykolab/xml/utils.py b/pykolab/xml/utils.py
index d98575e..535e95c 100644
--- a/pykolab/xml/utils.py
+++ b/pykolab/xml/utils.py
@@ -85,28 +85,16 @@ def to_cdatetime(_datetime, with_timezone=True, as_utc=False):
datetime = _datetime.replace(tzinfo=pytz.utc)
with_timezone = False
- (
- year,
- month,
- day,
- ) = (
- _datetime.year,
- _datetime.month,
- _datetime.day,
- )
+ # Sometimes we deal with dummy 00000000T000000 values from iCalendar
+ # in such cases we end up with datetime.time objects
+ if not hasattr(_datetime, 'year'):
+ (year, month, day) = (1970, 1, 1)
+ else:
+ (year, month, day) = (_datetime.year, _datetime.month, _datetime.day)
if hasattr(_datetime, 'hour'):
- (
- hour,
- minute,
- second
- ) = (
- _datetime.hour,
- _datetime.minute,
- _datetime.second
- )
+ (hour, minute, second) = (_datetime.hour, _datetime.minute, _datetime.second)
_cdatetime = kolabformat.cDateTime(year, month, day, hour, minute, second)
-
else:
_cdatetime = kolabformat.cDateTime(year, month, day)
diff --git a/tests/unit/test-003-event.py b/tests/unit/test-003-event.py
index 09ab17d..9959ec6 100644
--- a/tests/unit/test-003-event.py
+++ b/tests/unit/test-003-event.py
@@ -1005,6 +1005,24 @@ END:VEVENT
self.assertEqual(rdates, ["20140530T110000", "20140620T110000", "20140815T100000"])
+ def test_029_dummy_datetime(self):
+ ical = """
+BEGIN:VEVENT
+UID:8515D49BA15EFF7DB34F080877BE11F5-D1F2672D6F04F316
+DTSTAMP:00000000T000000
+DTSTART:20190514T060000
+DTEND:20190514T073000
+SUMMARY:Summary
+SEQUENCE:1
+CREATED:00000000T000000
+LAST-MODIFIED:00000000T000000
+ORGANIZER:MAILTO:tests@test.com
+END:VEVENT
+"""
+ event = event_from_ical(ical)
+ self.assertEqual(str(event.get_lastmodified()), "1970-01-01 00:00:00+00:00")
+
+
def _find_prop_in_list(self, diff, name):
for prop in diff:
if prop['property'] == name: