Skip to content

Commit

Permalink
Handle None in publish_time_to_datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
mberk committed Jun 5, 2023
1 parent aca7776 commit 9cbf875
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion betfairutil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2745,7 +2745,11 @@ def g():
return df


def publish_time_to_datetime(publish_time: int) -> datetime.datetime:
def publish_time_to_datetime(
publish_time: Optional[int],
) -> Optional[datetime.datetime]:
if publish_time is None:
return
return datetime.datetime.utcfromtimestamp(publish_time / 1000).replace(
tzinfo=datetime.timezone.utc
)
Expand Down
4 changes: 4 additions & 0 deletions tests/test_non_prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -1301,3 +1301,7 @@ def test_get_total_volume_traded_from_prices_file(
f.write("\n")
total_volume_traded = get_total_volume_traded_from_prices_file(path_to_prices_file)
assert total_volume_traded is None


def test_publish_time_to_datetime():
assert publish_time_to_datetime(None) is None

0 comments on commit 9cbf875

Please sign in to comment.