Skip to content

Commit 3bb5be2

Browse files
committed
Keep the sign of a negative timestamp between -1 and 0 in the OpenMetrics parser
Signed-off-by: Christopher Krah <48338417+chrikrah@users.noreply.github.com>
1 parent 36dce79 commit 3bb5be2

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎prometheus_client/openmetrics/parser.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@ def _parse_timestamp(timestamp):
9191
try:
9292
# aaaa.bbbb. Nanosecond resolution supported.
9393
parts = timestamp.split('.', 1)
94-
return Timestamp(int(parts[0]), int(parts[1][:9].ljust(9, "0")))
94+
sec = int(parts[0])
95+
nsec = int(parts[1][:9].ljust(9, "0"))
96+
if sec == 0 and parts[0].startswith('-'):
97+
# int("-0") is 0, so carry the sign the way Timestamp(-0.5, 500000000) does.
98+
return Timestamp(-nsec / 1e9, nsec)
99+
return Timestamp(sec, nsec)
95100
except ValueError:
96101
# Float.
97102
ts = float(timestamp)

0 commit comments

Comments
 (0)