timefhuman icon indicating copy to clipboard operation
timefhuman copied to clipboard

Index out of range

Open esemeniuc opened this issue 6 years ago • 3 comments

When running timefhuman('last wednesday of july'), I get the following error:

Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from timefhuman import timefhuman
>>> timefhuman('last wednesday of july')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/eric.semeniuc/.ansible/py3/lib/python3.6/site-packages/timefhuman/main.py", line 58, in timefhuman
    tokens = timefhuman_tokens(string, now)
  File "/home/eric.semeniuc/.ansible/py3/lib/python3.6/site-packages/timefhuman/main.py", line 75, in timefhuman_tokens
    tokens = categorize(tokens, now)
  File "/home/eric.semeniuc/.ansible/py3/lib/python3.6/site-packages/timefhuman/categorize.py", line 35, in categorize
    tokens = maybe_substitute_using_month(tokens, now)
  File "/home/eric.semeniuc/.ansible/py3/lib/python3.6/site-packages/timefhuman/categorize.py", line 193, in maybe_substitute_using_month
    next_candidate = tokens[index+1]
IndexError: list index out of range
>>> 

Platform: Ubuntu 18.04 x64, installed using pip3

Also happens with timefhuman('last wednesday in july')

esemeniuc avatar Jul 11 '19 00:07 esemeniuc

@esemeniuc Thanks for reporting! The parser is looking for "last " and reaches the end of the string without finding a day of week. I'll mark this as a feature request.

alvinwan avatar Jul 13 '19 21:07 alvinwan

I also got this error when trying to run timefhuman('last day of december') or timefhuman('last week of november')

so +1 for this feature request.

Avi-avidan avatar Nov 25 '20 08:11 Avi-avidan

Thanks for reporting -- this will be helpful the next chance I get to work on this.

alvinwan avatar Nov 26 '20 06:11 alvinwan