fix: Handles floats in more places (#1110)
This commit is contained in:
parent
ff26c4c713
commit
67b0bf3339
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Reference in New Issue