2
0
mirror of https://github.com/xcat2/confluent.git synced 2026-09-04 20:17:58 +00:00

Read a fractional second as a fraction

parse_time read the digits after the decimal point as whole milliseconds, so
'.5' became 5ms instead of 500ms. Only a three digit fraction came out right,
and a BMC may write either.

'.5', '.50' and '.500' are all 500ms now, '.125' is 125ms. Every other format
parse_time accepts is untouched.
This commit is contained in:
Markus Hilger
2026-08-31 23:22:41 +02:00
parent 7ba1798848
commit 2e7ce63b51
+4 -3
View File
@@ -42,9 +42,10 @@ def parse_time(timeval):
secs = secs * 60 * positive
ms = None
if '.' in timeval:
timeval, ms = timeval.split('.', 1)
ms = int(ms)
ms = timedelta(0, 0, 0, ms)
# A decimal fraction of a second. Read as whole
# milliseconds, '.5' came out as five of them.
timeval, fraction = timeval.split('.', 1)
ms = timedelta(seconds=float('0.' + fraction))
retval = datetime.strptime(timeval, '%Y-%m-%dT%H:%M:%S')
if ms:
retval += ms