mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-01-08 01:39:46 -06:00
* feat: add stream sub on top level * feat: clean up examples * chore: gen * feat: move stream onto the runs client in ts * fix: examples * chore: gen * fix: circular import issues * chore: lint * feat: first pass at Next app * fix: pull next out to top level * fix: all the things * fix: get it all wired up * fix: imports * fix: lint rule * fix: just use js * fix: revert tsconfig changes * fix: check in pages * fix: hangup event in streaming impl * chore: gen * chore: generate again, remove lots of nextjs stuff * fix: one more ignore * fix: gen * fix: ignore * fix: ugh * fix: simplify a bunch * fix: lint * fix: rm gen cruft * fix: changelog * feat: implement list with pagination * feat: add some tests * feat: add warnings * fix: update workflow / task methods * chore: version * feat: retries
68 lines
1.9 KiB
Python
68 lines
1.9 KiB
Python
from datetime import datetime, timedelta, timezone
|
|
from zoneinfo import ZoneInfo
|
|
|
|
from hatchet_sdk.utils.datetimes import partition_date_range
|
|
|
|
|
|
def test_partition_date_ranges_single_day() -> None:
|
|
since = datetime(2025, 1, 1, 1, 2, 3, tzinfo=timezone.utc)
|
|
until = datetime(2025, 1, 1, 3, 14, 15, tzinfo=timezone.utc)
|
|
partitioned = partition_date_range(
|
|
since,
|
|
until,
|
|
)
|
|
|
|
assert len(partitioned) == 1
|
|
assert partitioned[0] == (since, until)
|
|
|
|
|
|
def test_partition_date_ranges_multi_day() -> None:
|
|
since = datetime(2025, 1, 1, 1, 2, 3, tzinfo=timezone.utc)
|
|
until = datetime(2025, 1, 4, 3, 14, 15, tzinfo=timezone.utc)
|
|
partitioned = partition_date_range(
|
|
since,
|
|
until,
|
|
)
|
|
|
|
assert len(partitioned) == 4
|
|
assert partitioned[0] == (
|
|
since,
|
|
datetime(2025, 1, 2, tzinfo=timezone.utc),
|
|
)
|
|
assert partitioned[1] == (
|
|
datetime(2025, 1, 2, tzinfo=timezone.utc),
|
|
datetime(2025, 1, 3, tzinfo=timezone.utc),
|
|
)
|
|
assert partitioned[2] == (
|
|
datetime(2025, 1, 3, tzinfo=timezone.utc),
|
|
datetime(2025, 1, 4, tzinfo=timezone.utc),
|
|
)
|
|
assert partitioned[3] == (
|
|
datetime(2025, 1, 4, tzinfo=timezone.utc),
|
|
until,
|
|
)
|
|
|
|
|
|
def test_partition_date_ranges_non_utc() -> None:
|
|
since = datetime(2025, 1, 1, 22, 2, 3, tzinfo=ZoneInfo("America/New_York"))
|
|
until = datetime(2025, 1, 4, 3, 14, 15, tzinfo=timezone.utc)
|
|
|
|
partitioned = partition_date_range(
|
|
since,
|
|
until,
|
|
)
|
|
|
|
assert len(partitioned) == 3
|
|
assert partitioned[0] == (
|
|
since.astimezone(timezone.utc),
|
|
datetime(2025, 1, 3, tzinfo=timezone.utc),
|
|
)
|
|
assert partitioned[1] == (
|
|
datetime(2025, 1, 3, tzinfo=timezone.utc),
|
|
datetime(2025, 1, 4, tzinfo=timezone.utc),
|
|
)
|
|
assert partitioned[2] == (
|
|
datetime(2025, 1, 4, tzinfo=timezone.utc),
|
|
until,
|
|
)
|