Skip to content

Commit

Permalink
fix timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
marph91 committed Aug 31, 2024
1 parent beb4bdf commit 2b4509b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions joppy/data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,21 @@ def __post_init__(self) -> None:
# Exclude integer and empty string IDs.
if value and isinstance(value, str) and not is_id_valid(value):
raise ValueError("Invalid ID:", value)
elif field_.name.endswith("_time") or field_.name in (
"todo_due",
"todo_completed",
elif (
field_.name.endswith("_time")
or field_.name.endswith("Time")
or field_.name
in (
"todo_due",
"todo_completed",
)
):
try:
value_int = int(value)
casted_value = (
None
if value_int == 0
else datetime.fromtimestamp(value_int / 1000.0)
else datetime.utcfromtimestamp(value_int / 1000.0)
)
setattr(self, field_.name, casted_value)
except ValueError:
Expand Down

0 comments on commit 2b4509b

Please sign in to comment.