pimutils / khal

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

search ignores dateformat #563

Closed WhyNotHugo closed 7 years ago

WhyNotHugo commented 7 years ago

The output of search seems to ignore my dateformat setting:

$ cat .config/khal/config
[calendars]

  [[birthdays]]
  path = ~/.local/share/contacts/cards/
  type = birthdays
  color = light magenta

  [[calendars]]
  path = ~/.local/share/calendars/*
  type = discover

[locale]
longdateformat = %a %Y-%m-%d
dateformat = %Y-%m-%d

[default]
timedelta = 8 days
$ khal search activistas
16.12. 18:00-16.12. 19:00 [REDACTED]
geier commented 7 years ago

do you not have (long)datetimeformat configured? I'm surprised this is working at all...

WhyNotHugo commented 7 years ago

Configuring longdatetimeformat helped. It seems I missed when this config option was introduced.


Slightly on topic (and slight off-topic) I do find that configuring so many formats is a bit redundant. Can't we change some defaults:

datetimeformat = dateformat + timeformat
longdatetimeformat = longdateformat + timeformat

I'm actually curious if anyone even uses a longdatetimeformat != longdateformat + timeformat.


As a second point, why not use as defaults what the user has configured on their system / their locale:

WhyNotHugo commented 7 years ago

khal at still fails, even with new settings:

[calendars]

  [[birthdays]]
  path = ~/.local/share/contacts/cards/
  type = birthdays
  color = light magenta

  [[calendars]]
  path = ~/.local/share/calendars/*
  type = discover

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

[default]
timedelta = 8 days
$ khal at 2016-12-16
Traceback (most recent call last):
  File "/usr/bin/khal", line 11, in <module>
    load_entry_point('khal==0.9.1', 'console_scripts', 'khal')()
  File "/usr/lib/python3.6/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3.6/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3.6/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/lib/python3.6/site-packages/khal/cli.py", line 565, in at
    env={"calendars": ctx.obj['conf']['calendars']}
  File "/usr/lib/python3.6/site-packages/khal/controllers.py", line 263, in khal_list
    start, end = start_end_from_daterange(daterange, conf['locale'], td)
  File "/usr/lib/python3.6/site-packages/khal/controllers.py", line 145, in start_end_from_daterange
    daterange, locale, default_timedelta=default_timedelta)
  File "/usr/lib/python3.6/site-packages/khal/utils.py", line 392, in guessrangefstr
    raise ValueError('Could not parse `{}` as a daterange'.format(daterange))
ValueError: Could not parse `('2016-12-16', '1m')` as a daterange
$ khal at 2016-12-16 2016-12-17
Traceback (most recent call last):
  File "/usr/bin/khal", line 11, in <module>
    load_entry_point('khal==0.9.1', 'console_scripts', 'khal')()
  File "/usr/lib/python3.6/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3.6/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3.6/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/lib/python3.6/site-packages/khal/cli.py", line 565, in at
    env={"calendars": ctx.obj['conf']['calendars']}
  File "/usr/lib/python3.6/site-packages/khal/controllers.py", line 263, in khal_list
    start, end = start_end_from_daterange(daterange, conf['locale'], td)
  File "/usr/lib/python3.6/site-packages/khal/controllers.py", line 145, in start_end_from_daterange
    daterange, locale, default_timedelta=default_timedelta)
  File "/usr/lib/python3.6/site-packages/khal/utils.py", line 392, in guessrangefstr
    raise ValueError('Could not parse `{}` as a daterange'.format(daterange))
ValueError: Could not parse `('2016-12-16', '2016-12-17', '1m')` as a daterange
geier commented 7 years ago

see #208 for getting rid of the datetime variants, note that at is supposed to be used with a datetime, not a date. the error message sucks though (or better: there is no error message).

WhyNotHugo commented 7 years ago

Ah, thanks. I'll try and have a look at this, maybe we can do something like:

try:
    return parse_as_datetime(input)
except:
    return parse_as_date(input)