INNER CODE UNIT · Python
timestamp
pab1it0/prometheus-mcp-server · src/prometheus_mcp_server/server.py:335
def timestamp(value: str) -> float:
try:
return float(value)
except ValueError:
return datetime.fromisoformat(value.replace("Z", "+00:00")).timestamp()
try:
end_seconds = timestamp(end)
window_ms = round((end_seconds - timestamp(start)) * 1000)
if window_ms <= 0:
return None
end_input = datetime.fromtimestamp(end_seconds, timezone.utc).isoformat(timespec="milliseconds")
try:
step_seconds = float(step)
except ValueError:
units = {"y": 31536000, "w": 604800, "d": 86400, "h": 3600,
"m": 60, "s": 1, "ms": 0.001}
parts = re.findall(r"(\d+)(ms|[ywdhms])", step)