wroberts / pytimeparse

A small Python module to parse various kinds of time expressions.
MIT License
287 stars 39 forks source link

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

Open Delgan opened 7 years ago

Delgan commented 7 years ago

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.