pytimeparse icon indicating copy to clipboard operation
pytimeparse copied to clipboard

ValueError is raised instead of returning None for 'parse(". day")'

Open Delgan opened this issue 8 years ago • 0 comments

Hello.

I just noticed a small bug. This is not very important, but it's a little inconsistent with the rest of the library which returns None when unable to parse the string.

>>> from pytimeparse import parse
>>> parse(". day")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/env/lib/python3.6/site-packages/pytimeparse/timeparse.py", line 176, in timeparse
    list(mdict.items()) if k != 'secs' and v is not None])) +
  File "/home/env/lib/python3.6/site-packages/pytimeparse/timeparse.py", line 176, in <listcomp>
    list(mdict.items()) if k != 'secs' and v is not None])) +
ValueError: could not convert string to float: '.'

Python 3.6.3 and pytimeparse 1.1.7.

I guess this is because of the regex [\d.]+ which do not filter out such wrongly formatted float values.

Delgan avatar Oct 14 '17 16:10 Delgan