From 67b0bf333918e60f0473986d9bdc30c1f8d645c8 Mon Sep 17 00:00:00 2001 From: Isaac Sanders <651597+isaacsanders@users.noreply.github.com> Date: Fri, 30 Jan 2026 06:37:41 -0600 Subject: [PATCH] fix: Handles floats in more places (#1110) --- backend/common/src/helper.py | 4 +++- backend/common/tests/test_src/test_helper.py | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/backend/common/src/helper.py b/backend/common/src/helper.py index 0bb43aca..c6f0f06c 100644 --- a/backend/common/src/helper.py +++ b/backend/common/src/helper.py @@ -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): diff --git a/backend/common/tests/test_src/test_helper.py b/backend/common/tests/test_src/test_helper.py index 73578a76..acc81e46 100644 --- a/backend/common/tests/test_src/test_helper.py +++ b/backend/common/tests/test_src/test_helper.py @@ -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"