From 2da76eb51a459de9eba6d5095a94b58aee07a80c Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sat, 4 May 2024 14:18:19 -0400 Subject: [PATCH] feat(aurora): subclassed jsonencoder to allow for custom behavior --- aurora/models.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/aurora/models.py b/aurora/models.py index 2b8fcb8..f875ce7 100644 --- a/aurora/models.py +++ b/aurora/models.py @@ -68,3 +68,11 @@ class Moderation(BaseModel): return cls(**case) return None + +class JSONEncoder(json.JSONEncoder): + def default(self, o): + if isinstance(o, datetime): + return o.timestamp() + if isinstance(o, timedelta): + return str(o) + return super().default(o)