From c3d385bce0775a44d88d1caa7d0325a9e0377079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sun, 27 Jul 2025 00:11:53 +0200 Subject: [PATCH] [scripts/pyprint] support datetime objects --- scripts/pyprint.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/pyprint.py b/scripts/pyprint.py index a946709b..2d5cb795 100644 --- a/scripts/pyprint.py +++ b/scripts/pyprint.py @@ -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}'''