Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ dev = [
"types-pytz>=2025.2.0.20251108",
"pandas-stubs>=2.3.2.250926",
"pytest-asyncio>=1.3.0",
"freezegun>=1.5.5",
]

[tool.uv.sources]
Expand Down
27 changes: 27 additions & 0 deletions src/quartz_api/internal/backends/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import datetime as dt

from freezegun import freeze_time

from quartz_api.internal.backends.utils import get_window


def test_get_window_defaults() -> None:
with freeze_time("2023-01-01"):
start, end = get_window()
assert start == dt.datetime(2022, 12, 30, tzinfo=dt.UTC)
assert end == dt.datetime(2023, 1, 3, tzinfo=dt.UTC)


def test_get_window_with_params() -> None:
custom_start = dt.datetime(2023, 2, 1, 12, tzinfo=dt.UTC)
custom_end = dt.datetime(2023, 2, 5, 12, tzinfo=dt.UTC)
start, end = get_window(start=custom_start, end=custom_end)
assert start == custom_start
assert end == custom_end


def test_get_window_with_partial_params() -> None:
custom_start = dt.datetime(2023, 3, 1, 8, tzinfo=dt.UTC)
start, end = get_window(start=custom_start)
assert start == custom_start
assert end == custom_start + dt.timedelta(days=4)
27 changes: 14 additions & 13 deletions src/quartz_api/internal/backends/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
import datetime as dt


def get_window() -> tuple[dt.datetime, dt.datetime]:
def get_window(
start: dt.datetime | None = None, end: dt.datetime | None = None,
) -> tuple[dt.datetime, dt.datetime]:
"""Returns the start and end of the window for timeseries data."""
# Window start is the beginning of the day two days ago
start = (dt.datetime.now(tz=dt.UTC) - dt.timedelta(days=2)).replace(
hour=0,
minute=0,
second=0,
microsecond=0,
)
if start is None:
start = (dt.datetime.now(tz=dt.UTC) - dt.timedelta(days=2)).replace(
hour=0,
minute=0,
second=0,
microsecond=0,
)

# Window end is the beginning of the day two days ahead
end = (dt.datetime.now(tz=dt.UTC) + dt.timedelta(days=2)).replace(
hour=0,
minute=0,
second=0,
microsecond=0,
)
if end is None:
end = start + dt.timedelta(days=4)

return (start, end)
Loading