From a2bcc39e6360804986411aef720ec3a638b92b3d Mon Sep 17 00:00:00 2001 From: Tang Vu Date: Thu, 26 Mar 2026 03:25:44 +0700 Subject: [PATCH] refactor: crash in timestamp formatting when timezone_offset is none In `Timing.format_timestamp`, if `self.timezone_offset` is `None` (which is explicitly allowed by the `Optional[int]` type hint), it instantiates `TimeZone(None)`. When `datetime.fromtimestamp()` calls the `utcoffset()` method on this timezone object, it executes `timedelta(hours=self.offset)`, which evaluates to `timedelta(hours=None)`. This raises a `TypeError: unsupported type for timedelta hours component: NoneType`, causing the application to crash during export. Affected files: data_model.py Signed-off-by: Tang Vu --- Whatsapp_Chat_Exporter/data_model.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Whatsapp_Chat_Exporter/data_model.py b/Whatsapp_Chat_Exporter/data_model.py index 52f9bae..d8255ce 100644 --- a/Whatsapp_Chat_Exporter/data_model.py +++ b/Whatsapp_Chat_Exporter/data_model.py @@ -30,7 +30,8 @@ class Timing: """ if timestamp is not None: timestamp = timestamp / 1000 if timestamp > 9999999999 else timestamp - return datetime.fromtimestamp(timestamp, TimeZone(self.timezone_offset)).strftime(format) + tz = TimeZone(self.timezone_offset) if self.timezone_offset is not None else None + return datetime.fromtimestamp(timestamp, tz).strftime(format) return None