MCPcopy Create free account
hub / github.com/apache/impala / parse_duration_string_ms

Function parse_duration_string_ms

tests/util/parse_util.py:92–103  ·  view source on GitHub ↗

Parses a duration string of the form 1h2h3m4s5.6ms4.5us7.8ns into milliseconds.

(duration)

Source from the content-addressed store, hash-verified

90
91
92def parse_duration_string_ms(duration):
93 """Parses a duration string of the form 1h2h3m4s5.6ms4.5us7.8ns into milliseconds."""
94 pattern = r'(?P<value>[0-9]+\.?[0-9]*?)(?P<units>\D+)'
95 matches = list(re.finditer(pattern, duration))
96 assert matches, 'Failed to parse duration string %s' % duration
97
98 times = {'h': 0, 'm': 0, 's': 0, 'ms': 0}
99 for match in matches:
100 parsed = match.groupdict()
101 times[parsed['units']] = float(parsed['value'])
102
103 return (times['h'] * 60 * 60 + times['m'] * 60 + times['s']) * 1000 + times['ms']
104
105
106def parse_duration_string_ns(duration):

Calls

no outgoing calls