Repository: pimutils/khal

Issue:
Double issue: invalid time range parsing + warning message display
Two problems are shown in the attached screenshot:
- when entering this event (using only default values, especially the start and end hours 8:00 to 9:00), the time range is not understood by khal
- warning messages are displayed (very shortly, less than 1 sec) in the middle of the screen, and are erased as soon as the screen is being refreshed, which prevents the user to see them

![screenshot_20170608_082535](https://user-images.githubusercontent.com/412628/26914970-5213000a-4c24-11e7-86a0-877a53979524.png)


Discussion:

Patch:
diff --git a/khal/ui/editor.py b/khal/ui/editor.py
index 4333004..94cadca 100644
--- a/khal/ui/editor.py
+++ b/khal/ui/editor.py
@@ -235,7 +235,7 @@ class StartEndEditor(urwid.WidgetWrap):
             return endval
 
     def _end_date_change(self, date):
-        self._enddt = self.localize_end(dt.datetime.combine(date, self._start_time))
+        self._enddt = self.localize_end(dt.datetime.combine(date, self._end_time))
         self.on_end_date_change(date)
 
     def toggle(self, checkbox, state):
@@ -277,25 +277,23 @@ class StartEndEditor(urwid.WidgetWrap):
             self.widgets.endtime = urwid.Text('')
         elif state is False:
             timewidth = self._timewidth + 1
-            edit = ValidatedEdit(
+            raw_start_time_widget = ValidatedEdit(
                 dateformat=self.conf['locale']['timeformat'],
                 EditWidget=TimeWidget,
                 validate=self._validate_start_time,
                 edit_text=self.startdt.strftime(self.conf['locale']['timeformat']),
             )
-            edit = urwid.Padding(
-                edit, align='left', width=self._timewidth + 1, left=1)
-            self.widgets.starttime = edit
+            self.widgets.starttime = urwid.Padding(
+                raw_start_time_widget, align='left', width=self._timewidth + 1, left=1)
 
-            edit = ValidatedEdit(
+            raw_end_time_widget = ValidatedEdit(
                 dateformat=self.conf['locale']['timeformat'],
                 EditWidget=TimeWidget,
                 validate=self._validate_end_time,
                 edit_text=self.enddt.strftime(self.conf['locale']['timeformat']),
             )
-            edit = urwid.Padding(
-                edit, align='left', width=self._timewidth + 1, left=1)
-            self.widgets.endtime = edit
+            self.widgets.endtime = urwid.Padding(
+                raw_end_time_widget, align='left', width=self._timewidth + 1, left=1)
 
         columns = NPile([
             self.checkallday,


Test patch:
diff --git a/tests/ui/test_editor.py b/tests/ui/test_editor.py
index 080a00d..27b7fa5 100644
--- a/tests/ui/test_editor.py
+++ b/tests/ui/test_editor.py
@@ -4,12 +4,21 @@ import icalendar
 from khal.ui.editor import RecurrenceEditor, StartEndEditor
 
 from ..utils import BERLIN, LOCALE_BERLIN
+from .canvas_render import CanvasTranslator
 
 CONF = {'locale': LOCALE_BERLIN, 'keybindings': {}, 'view': {'monthdisplay': 'firstday'}}
 
 START = BERLIN.localize(dt.datetime(2015, 4, 26, 22, 23))
 END = BERLIN.localize(dt.datetime(2015, 4, 27, 23, 23))
 
+palette = {
+    'date header focused': 'blue',
+    'date header': 'green',
+    'default': 'black',
+    'editf': 'red',
+    'edit': 'blue',
+}
+
 
 def test_popup(monkeypatch):
     """making sure the popup calendar gets callend with the right inital value
@@ -65,3 +74,60 @@ def test_check_understood_rrule():
     assert not RecurrenceEditor.check_understood_rrule(
         icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TH;BYSETPOS=3')
     )
+
+
+def test_editor():
+    """test for the issue in #666"""
+    editor = StartEndEditor(
+        BERLIN.localize(dt.datetime(2017, 10, 2, 13)),
+        BERLIN.localize(dt.datetime(2017, 10, 4, 18)),
+        conf=CONF
+    )
+    assert editor.startdt == BERLIN.localize(dt.datetime(2017, 10, 2, 13))
+    assert editor.enddt == BERLIN.localize(dt.datetime(2017, 10, 4, 18))
+    assert editor.changed is False
+    for _ in range(3):
+        editor.keypress((10, ), 'tab')
+    for _ in range(3):
+        editor.keypress((10, ), 'shift tab')
+    assert editor.startdt == BERLIN.localize(dt.datetime(2017, 10, 2, 13))
+    assert editor.enddt == BERLIN.localize(dt.datetime(2017, 10, 4, 18))
+    assert editor.changed is False
+
+
+def test_convert_to_date():
+    """test for the issue in #666"""
+    editor = StartEndEditor(
+        BERLIN.localize(dt.datetime(2017, 10, 2, 13)),
+        BERLIN.localize(dt.datetime(2017, 10, 4, 18)),
+        conf=CONF
+    )
+    canvas = editor.render((50, ), True)
+    assert CanvasTranslator(canvas, palette).transform() == (
+        '[ ] Allday\nFrom: \x1b[31m2.10.2017 \x1b[0m \x1b[34m13:00 \x1b[0m\n'
+        'To:   \x1b[34m04.10.2017\x1b[0m \x1b[34m18:00 \x1b[0m\n'
+    )
+
+    assert editor.startdt == BERLIN.localize(dt.datetime(2017, 10, 2, 13))
+    assert editor.enddt == BERLIN.localize(dt.datetime(2017, 10, 4, 18))
+    assert editor.changed is False
+    assert editor.allday is False
+
+    # set to all day event
+    editor.keypress((10, ), 'shift tab')
+    editor.keypress((10, ), ' ')
+    for _ in range(3):
+        editor.keypress((10, ), 'tab')
+    for _ in range(3):
+        editor.keypress((10, ), 'shift tab')
+
+    canvas = editor.render((50, ), True)
+    assert CanvasTranslator(canvas, palette).transform() == (
+        '[X] Allday\nFrom: \x1b[34m02.10.2017\x1b[0m  \n'
+        'To:   \x1b[34m04.10.2017\x1b[0m  \n'
+    )
+
+    assert editor.changed is True
+    assert editor.allday is True
+    assert editor.startdt == dt.date(2017, 10, 2)
+    assert editor.enddt == dt.date(2017, 10, 4)