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 <vuminhtang2212@gmail.com>
This commit is contained in:
Tang Vu
2026-03-26 03:25:44 +07:00
parent a0719bc2bf
commit a2bcc39e63

View File

@@ -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