fix: Handles floats in more places (#1110)

This commit is contained in:
Isaac Sanders 2026-01-30 06:37:41 -06:00 committed by GitHub
parent ff26c4c713
commit 67b0bf3339
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View File

@ -103,13 +103,15 @@ def requests_headers() -> dict[str, str]:
return {"User-Agent": template}
def date_parser(timestamp: int | str | None) -> str | None:
def date_parser(timestamp: int | float | str | None) -> str | None:
"""return formatted date string"""
if timestamp is None:
return None
if isinstance(timestamp, int):
date_obj = datetime.fromtimestamp(timestamp, tz=timezone.utc)
elif isinstance(timestamp, float):
date_obj = datetime.fromtimestamp(int(timestamp), tz=timezone.utc)
elif isinstance(timestamp, str) and timestamp.isdigit():
date_obj = datetime.fromtimestamp(int(timestamp), tz=timezone.utc)
elif isinstance(timestamp, str):

View File

@ -33,6 +33,13 @@ def test_date_parser_with_digit():
assert date_parser(timestamp) == expected_date
def test_date_parser_with_float():
"""iso timestamp"""
date_float = 1766210400.0
expected_date = "2025-12-20T06:00:00+00:00"
assert date_parser(date_float) == expected_date
def test_date_parser_with_str():
"""iso timestamp"""
date_str = "2021-05-21"