[scripts/pyprint] support datetime objects

This commit is contained in:
Mike Fährmann
2025-07-27 00:11:53 +02:00
parent 07af386700
commit c3d385bce0

View File

@@ -94,4 +94,11 @@ def pyprint(obj, indent=0, lmax=16):
return "set()"
return f'''{{{", ".join(pyprint(v, indent+4) for v in obj)}}}'''
if obj.__class__.__name__ == "datetime":
if (off := obj.utcoffset()) is not None:
obj = obj.replace(tzinfo=None, microsecond=0) - off
elif obj.microsecond:
obj = obj.replace(microsecond=0)
return f'''"dt:{obj}"'''
return f'''{obj}'''