Repository: pimutils/khal

Issue:
iCal, DTSTART == DTEND
Currently, when DTSTART == DTEND khal shows things like:

```
Today:
20:00→ : "blah foo bar"
Tomorrow:
  → 20:00: "blah foo bar"
```

Google Agenda assume that event last 1 hour.
Neither behavior is perfect and both are better than omitting the event.
But khal output seems more confusing and by assuming that event last 24h give the visual impression that 2 distinct event happens (especially if other events happens in the timespan).

Assuming up the end-of-the-day, or, like Google 1 hour, could be better trade-off.


Discussion:
geier: looks good, thanks! Could you please add a warning to the user? 
hobarrera: LGTM

Patch:
diff --git a/AUTHORS.txt b/AUTHORS.txt
index 4c1283d..5123a7c 100644
--- a/AUTHORS.txt
+++ b/AUTHORS.txt
@@ -28,3 +28,4 @@ Troy Sankey - sankeytms [at] gmail [dot] com
 Mart Lubbers - mart [at] martlubbers [dot] net
 Paweł Fertyk - pfertyk [at] openmailbox [dot] org
 Moritz Kobel - moritz [at] kobelnet [dot] ch - http://www.kobelnet.ch
+Guilhem Saurel - guilhem [at] saurel [dot] me - https://saurel.me
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index fce5319..4dd4fcc 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -31,6 +31,8 @@ not released yet
 * `import` can now import multiple files at once (Christian Geier)
 * configuration file path $XDG_CONFIG_HOME/khal/config is now supported and
   $XDG_CONFIG_HOME/khal/khal.conf deprecated
+* events that start and end at the same time are now displayed as if their
+  duration was one hour instead of one day (Guilhem Saurel)
 
 ikhal
 -----
diff --git a/khal/khalendar/utils.py b/khal/khalendar/utils.py
index b03d7da..27e16bc 100644
--- a/khal/khalendar/utils.py
+++ b/khal/khalendar/utils.py
@@ -189,7 +189,7 @@ def sanitize(vevent, default_timezone, href='', calendar=''):
 
 def sanitize_timerange(dtstart, dtend, duration=None):
     '''return sensible dtstart and end for events that have an invalid or
-    missing DTEND, assuming the event just lasts one day.'''
+    missing DTEND, assuming the event just lasts one hour.'''
 
     if isinstance(dtstart, datetime) and isinstance(dtend, datetime):
         if dtstart.tzinfo and not dtend.tzinfo:
@@ -214,7 +214,11 @@ def sanitize_timerange(dtstart, dtend, duration=None):
             raise ValueError('The event\'s end time (DTEND) is older than '
                              'the event\'s start time (DTSTART).')
         elif dtend == dtstart:
-            dtend += timedelta(days=1)
+            logger.warning(
+                "Event start time and end time are the same. "
+                "Assuming the event's duration is one hour."
+            )
+            dtend += timedelta(hours=1)
 
     return dtstart, dtend
 


Test patch:
diff --git a/tests/khalendar_aux_test.py b/tests/khalendar_aux_test.py
index dbe60e9..6fe9316 100644
--- a/tests/khalendar_aux_test.py
+++ b/tests/khalendar_aux_test.py
@@ -736,6 +736,17 @@ END:VEVENT
 END:VCALENDAR
 """
 
+instant = """
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:instant123
+DTSTART;TZID=Europe/Berlin;VALUE=DATE-TIME:20170113T010000
+DTEND;TZID=Europe/Berlin;VALUE=DATE-TIME:20170113T010000
+SUMMARY:Really fast event
+END:VEVENT
+END:VCALENDAR
+"""
+
 
 class TestSanitize(object):
 
@@ -754,3 +765,9 @@ class TestSanitize(object):
     def test_duration(self):
         vevent = _get_vevent_file('event_dtr_exdatez')
         vevent = utils.sanitize(vevent, berlin, '', '')
+
+    def test_instant(self):
+        vevent = _get_vevent(instant)
+        assert vevent['DTEND'].dt - vevent['DTSTART'].dt == timedelta()
+        vevent = utils.sanitize(vevent, berlin, '', '')
+        assert vevent['DTEND'].dt - vevent['DTSTART'].dt == timedelta(hours=1)