From 7412ef5162c7d3c61618a828d4994330051089ae Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sat, 19 Sep 2020 04:01:33 -0700 Subject: [PATCH] Let parse_unit_string try int before float. --- etiquette/helpers.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/etiquette/helpers.py b/etiquette/helpers.py index 084a6a5..8fa5e11 100644 --- a/etiquette/helpers.py +++ b/etiquette/helpers.py @@ -293,14 +293,19 @@ def now(timestamp=True): def parse_unit_string(s): ''' - Try to parse the string as a float, or bytestring, or hms. + Try to parse the string as an int, float, or bytestring, or hms. ''' if s is None: return None + s = s.strip() + if ':' in s: return hms_to_seconds(s) + elif all(c in '0123456789' for c in s): + return int(s) + elif all(c in '0123456789.' for c in s): return float(s)