fix(cron): improve timezone scheduling and tz propagation

This commit is contained in:
jopo
2026-02-16 17:49:19 -08:00
parent a219a91bc5
commit ae903e983c
3 changed files with 38 additions and 7 deletions

View File

@@ -32,7 +32,8 @@ def _compute_next_run(schedule: CronSchedule, now_ms: int) -> int | None:
try:
from croniter import croniter
from zoneinfo import ZoneInfo
base_time = time.time()
# Use the caller-provided reference time for deterministic scheduling.
base_time = now_ms / 1000
tz = ZoneInfo(schedule.tz) if schedule.tz else datetime.now().astimezone().tzinfo
base_dt = datetime.fromtimestamp(base_time, tz=tz)
cron = croniter(schedule.expr, base_dt)