Skip to content

Commit 0a71785

Browse files
Fix: Always return None on parse errors.
Resolves wroberts#15
1 parent ef62cf1 commit 0a71785

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

pytimeparse2.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3131
# SOFTWARE.
3232

33-
__version__ = '1.3.0'
33+
__version__ = '1.3.1'
3434

3535
import typing
3636
import re
@@ -102,7 +102,7 @@ def _interpret_as_minutes(sval, mdict):
102102
return mdict
103103

104104

105-
def parse(sval: str, granularity: str = 'seconds') -> typing.Optional[typing.Union[int, float]]:
105+
def _parse(sval: str, granularity: str = 'seconds') -> typing.Optional[typing.Union[int, float]]:
106106
"""
107107
Parse a time expression, returning it as a number of seconds. If
108108
possible, the return value will be an `int`; if this is not
@@ -180,7 +180,11 @@ def parse(sval: str, granularity: str = 'seconds') -> typing.Optional[typing.Uni
180180
if v is not None
181181
])
182182

183+
return int(float(sval)) * sign
184+
185+
186+
def parse(sval: str, granularity: str = 'seconds') -> typing.Optional[typing.Union[int, float]]:
183187
try:
184-
return int(float(sval)) * sign
185-
except ValueError:
188+
return _parse(sval, granularity)
189+
except Exception:
186190
return None

0 commit comments

Comments
 (0)