pimutils / khal

:calendar: CLI calendar application
https://lostpackets.de/khal/
MIT License
2.58k stars 200 forks source link

daterange parsing error should include a hint #786

Open amandabee opened 6 years ago

amandabee commented 6 years ago

If I use the wrong formatting to ask for a list of events on some given future data, eg khal list 18-june-2018 10d I get a heap of errors that end with the very clear notice that khal wasn't able to parse the date range I provided:

amanda@mona:~$ khal list 18-june-2018 10d
Traceback (most recent call last):
  File "/usr/local/bin/khal", line 11, in <module>
    sys.exit(main_khal())
  File "/home/amanda/.local/lib/python3.5/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/amanda/.local/lib/python3.5/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/amanda/.local/lib/python3.5/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/amanda/.local/lib/python3.5/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/amanda/.local/lib/python3.5/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/amanda/.local/lib/python3.5/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/amanda/.local/lib/python3.5/site-packages/khal/cli.py", line 323, in klist
    env={"calendars": ctx.obj['conf']['calendars']}
  File "/home/amanda/.local/lib/python3.5/site-packages/khal/controllers.py", line 226, in khal_list
    default_timedelta_datetime=conf['default']['timedelta'],
  File "/home/amanda/.local/lib/python3.5/site-packages/khal/controllers.py", line 142, in start_end_from_daterange
    default_timedelta_datetime=default_timedelta_datetime,
  File "/home/amanda/.local/lib/python3.5/site-packages/khal/utils.py", line 438, in guessrangefstr
    raise ValueError('Could not parse `{}` as a daterange'.format(daterange))
ValueError: Could not parse `('18-june-2018', '10d')` as a daterange

Ideally khal would not show me the full traceback, but would be more precise about what it is looking for in a date. Something like:

ValueError: Could not parse ('18-june-2018', '10d') as a daterange -- "18-june-2018" is not a valid date. Khal expects dates in the format "18-may" Check the usage documentation for more examples of START and END date formats.

If I give a bad DELTA, eg. khal calendar 18-jun 1w I get a slightly different error, but it doesn't tell me that the delta is the problem:

critical: Could not parse ('18-jun', '1w') as a daterange

Something like "10w does not appear to be a valid END or DELTA value" would clue me into the fact that khal doesn't do weeks.

geier commented 6 years ago

Good suggestions!

varac commented 6 years ago

I second this, I already lost quite some time to figure out how to list events from lets say June last year. Please include more examples in the documentation, including hints how to specify date ranges. Thanks !

varac commented 6 years ago

So I see 3 possible places for better documentation regarding date ranges:

Aerex commented 5 years ago

Also, could you explain what is the correct format for khal datetime range. I know it uses the python strtime but I don't know how that works for a range. The documentation doesn't reall go into detail on this. I am simply trying to edit a start time for an event

amandabee commented 5 years ago

@Aerex if you haven't set the time format in your config, it uses the defaults datetimeformat is as described in the manual. In my config, however, I have this:

[locale]
timeformat = %H:%M
dateformat = %d-%b
longdateformat = %d-%b-%Y
datetimeformat = %d-%b-%Y %H:%M
longdatetimeformat = %d/%m/%Y %H:%M

So to add an event that runs from 10:15 to 11:45 on Nov 6 I'd use: khal new -a somecalendar 06/11/2018 10:15 06/11/2018 11:45 "Title of Event"

In general, however, an error that echos back the expected format would definitely clarify this, especially as %c isn't seamless to lookup in the Python strftime docs.

Honestly, a custom command to demo the expected formats (khal show timeformat) with today's date and time would be kind of sweet. But first a hint in the error message.

Aerex commented 5 years ago

@amandabee Thanks I will keep that in mind