Repository: pimutils/khal

Issue:
`khal list week` crashes 
Since https://github.com/pimutils/khal/commit/48020f06560f3ffd0d7845d24b6464ad8f7dd3c0 `khal list week` crashes like this:

	Traceback (most recent call last):
	  File "/home/untitaker/.local/bin/khal", line 9, in <module>
		load_entry_point('khal', 'console_scripts', 'khal')()
	  File "/home/untitaker/projects/click/click/core.py", line 716, in __call__
		return self.main(*args, **kwargs)
	  File "/home/untitaker/projects/click/click/core.py", line 696, in main
		rv = self.invoke(ctx)
	  File "/home/untitaker/projects/click/click/core.py", line 1065, in invoke
		return _process_result(sub_ctx.command.invoke(sub_ctx))
	  File "/home/untitaker/projects/click/click/core.py", line 892, in invoke
		return ctx.invoke(self.callback, **ctx.params)
	  File "/home/untitaker/projects/click/click/core.py", line 534, in invoke
		return callback(*args, **kwargs)
	  File "/home/untitaker/projects/click/click/decorators.py", line 17, in new_func
		return f(get_current_context(), *args, **kwargs)
	  File "/home/untitaker/projects/khal/khal/cli.py", line 315, in klist
		env={"calendars": ctx.obj['conf']['calendars']}
	  File "/home/untitaker/projects/khal/khal/controllers.py", line 262, in khal_list
		start, end = start_end_from_daterange(daterange, conf['locale'], td)
	  File "/home/untitaker/projects/khal/khal/controllers.py", line 144, in start_end_from_daterange
		daterange, locale, default_timedelta=default_timedelta)
	  File "/home/untitaker/projects/khal/khal/aux.py", line 350, in guessrangefstr
		if len(end) == 0:
	TypeError: object of type 'datetime.datetime' has no len()

I feel like it is time to implement #169 with the `parsedatetime`.


Comments:

Patch:
diff --git a/khal/aux.py b/khal/aux.py
index 6d61e1c..45bec4d 100644
--- a/khal/aux.py
+++ b/khal/aux.py
@@ -340,6 +340,7 @@ def guessrangefstr(daterange, locale, default_timedelta=None, adjust_reasonably=
                     start = datetime.today() - \
                         timedelta(days=(today_weekday - locale['firstweekday']))
                     end = start + timedelta(days=7)
+                    return start, end, True
             else:
                 split = start.split(" ")
                 start, allday = guessdatetimefstr(split, locale)
@@ -358,7 +359,6 @@ def guessrangefstr(daterange, locale, default_timedelta=None, adjust_reasonably=
                 start -= timedelta(days=(start.weekday() - locale['firstweekday']))
                 end = start + timedelta(days=7)
             else:
-
                 try:
                     delta = guesstimedeltafstr(end)
                     end = start + delta


Test patch:
diff --git a/tests/aux_test.py b/tests/aux_test.py
index 9aafcbf..bc43fc8 100644
--- a/tests/aux_test.py
+++ b/tests/aux_test.py
@@ -183,6 +183,11 @@ class TestGuessRangefstr(object):
         assert (datetime(2015, 12, 28), datetime(2016, 1, 4), True) == \
             guessrangefstr('1.1.2016 week', locale=locale_de, default_timedelta="1d")
 
+    @freeze_time('20160216')
+    def test_week(self):
+        assert (datetime(2016, 2, 15), datetime(2016, 2, 22), True) == \
+            guessrangefstr('week', locale=locale_de, default_timedelta="1d")
+
     def test_invalid(self):
         with pytest.raises(ValueError):
             guessrangefstr('3d', locale=locale_de, default_timedelta="1d")