55from datetime import date , timedelta , time
66from decimal import Decimal
77from typing import Any
8+ from datetime import datetime , timezone
89
910
1011def _quote_string (value : str ) -> str :
@@ -35,7 +36,7 @@ def decode_bitstring(data: bytes) -> str:
3536
3637
3738def interpret_time (value : int ) -> str :
38- t = timedelta (microseconds = value )
39+ t = timedelta (milliseconds = value )
3940 hours , remainder = divmod (t .seconds , 3600 )
4041 minutes , seconds = divmod (remainder , 60 )
4142
@@ -53,6 +54,11 @@ def interpret_real(value: Any) -> str:
5354 return value
5455
5556
57+ def interpret_timestamp_ms (value : int ) -> str :
58+ dt = datetime .fromtimestamp (value / 1000 , tz = timezone .UTC )
59+ return dt .strftime ("%Y-%m-%d %H:%M:%S.%f" )[:- 3 ] # Trim to milliseconds
60+
61+
5662def decode_uuid (value : dict [str , int ]) -> str :
5763 assert "upper" in value and "lower" in value , "Invalid GUID format"
5864
@@ -343,7 +349,7 @@ def e_to_s(expr: dict[str, Any]) -> str:
343349 elif expression ["value" ]["type" ]["id" ] == "TIMESTAMP_S" :
344350 return f"make_timestamp({ expression ['value' ]['value' ]} ::bigint*1000000)"
345351 elif expression ["value" ]["type" ]["id" ] == "TIMESTAMP_MS" :
346- return f"make_timestamp( { expression ['value' ]['value' ]} ::bigint) "
352+ return f"' { interpret_timestamp_ms ( expression ['value' ]['value' ]) } ' "
347353 elif expression ["value" ]["type" ]["id" ] == "TIMESTAMP_NS" :
348354 return f"make_timestamp_ns({ expression ['value' ]['value' ]} ::bigint)"
349355 # elif expression["value"]["type"]["id"] == "TIMESTAMP WITH TIME ZONE":
0 commit comments