Skip to content

Commit

Permalink
Add time validator for auto-conversion from float to datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
MHHukiewitz committed Nov 24, 2023
1 parent eb6027e commit 046fb18
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions aleph_message/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,13 @@ def check_confirmed(cls, v, values):
raise ValueError("Message cannot be 'confirmed' without 'confirmations'")
return v

@validator("time")
def check_time(cls, v):
if isinstance(v, float):
v = datetime.datetime.fromtimestamp(v)
assert isinstance(v, datetime.datetime)
return v

class Config:
extra = Extra.forbid

Expand Down

0 comments on commit 046fb18

Please sign in to comment.