Skip to content
Merged
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
8 changes: 6 additions & 2 deletions src/operations_center/backends/worker_backend_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
"codex": "codex_cli",
"openai": "codex_cli",
}
_TIMEZONE_RESET_RE = re.compile(r"resets\s+(\d{1,2}:\d{2}(?:am|pm))\s+\(([^)]+)\)", re.IGNORECASE)
_TIMEZONE_RESET_RE = re.compile(
r"resets\s+(\d{1,2}(?::\d{2})?(?:am|pm))\s+\(([^)]+)\)",
re.IGNORECASE,
)
_ISO_RESET_RE = re.compile(
r"resets?(?:\s+at)?\s+(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2})?Z)",
re.IGNORECASE,
Expand Down Expand Up @@ -219,7 +222,8 @@ def parse_worker_backend_reset(
except ZoneInfoNotFoundError:
return None
now_local = current.astimezone(tz)
parsed = datetime.strptime(time_str, "%I:%M%p") # noqa: DTZ007
time_fmt = "%I:%M%p" if ":" in time_str else "%I%p"
parsed = datetime.strptime(time_str, time_fmt) # noqa: DTZ007
reset_local = now_local.replace(
hour=parsed.hour,
minute=parsed.minute,
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/backends/test_worker_backend_selector_cov.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,15 @@ def test_parse_timezone_reset_later_today() -> None:
assert (local.hour, local.minute) == (14, 30)


def test_parse_timezone_reset_without_minutes_later_today() -> None:
out = "You've hit your weekly limit · resets 9am (America/New_York)"
result = parse_worker_backend_reset(out, "claude_code", now=NOW)
assert result is not None
assert result.tzinfo == UTC
local = result.astimezone(__import__("zoneinfo").ZoneInfo("America/New_York"))
assert (local.hour, local.minute) == (9, 0)


def test_parse_timezone_reset_rolls_to_next_day() -> None:
# 8:00am EDT when it is already ~08:00 EDT -> should roll forward a day.
out = "resets 8:00am (America/New_York)"
Expand Down
Loading