oliver-zehentleitner / maity

clean-up: hub-wide: RFC 3339 parsing without the .replace(Z) workaround, in nine places; placements._stamp is views.ts

Sign in to report

tsk-kfpz2m8we8f1 Open

From the clean-up audit tsk-hgnbapyw7hnh (findings A3-9, A9-18), read at 80647565. Line numbers are at that SHA; check them against current main first. Paths are under hub/src/maity_hub/.

What is wrong

Nine places parse an RFC 3339 time with datetime.fromisoformat(value.replace("Z", "+00:00")). The workaround was only needed before Python 3.11; the hub requires Python 3.12 or newer (hub/pyproject.toml:11), and fromisoformat accepts a trailing Z itself. clock.py has rfc3339() for writing but no parser, so each module writes its own.

Sites

  • forge.py:1002-1009 _moment (:1007) and github_app.py:234-240 _expiry (:238): the same parser twice.
  • ktw.py:260, maintenance.py:49, notifications/preferences.py:227, placements.py:999, routes/ticker.py:237, ticker.py:689.
  • routes/limit.py:42 upper-cases the text first (text.upper().replace(...)); check why before folding it in (probably to accept a lower-case t or z), and keep that behaviour.
  • placements.py:1144-1145 _stamp is views.py:38-39 ts under another name (writing, not parsing).

Proposal

  • Either add clock.parse_rfc3339(value) -> datetime | None (None for a non-string or a parse error, as _moment does) and use it at all nine sites, or drop the .replace and call datetime.fromisoformat directly. forge._moment and github_app._expiry become one call either way.
  • Replace placements._stamp with views.ts (or clock.rfc3339 with a None check if importing views would make a cycle).

Effort and risk

  • Effort S. Risk low: on 3.12, fromisoformat gives the same result with or without the .replace. The forge and ticker tests cover the GitHub timestamps.

Order

  • forge.py and github_app.py are reworked by tsk-e77g3nhqqnex item 1 (one GitHub transport), and placements.py by tsk-j0vqtv3zhacw; rebase rather than conflict.

Open question

  • One helper in clock.py, or plain datetime.fromisoformat at each site? The helper also gives one place for the "None on a bad value" rule that _moment, _expiry and routes/ticker.py:237 each write out.

Covered elsewhere

  • None. Searched: rfc3339, fromisoformat. tsk-e77g3nhqqnex and tsk-j0vqtv3zhacw list A3-9 and A9-18 as left for this card.

Effort sum: S (1 point).

Notes

  1. Maity Coder Claude 003 · Nov 13, 2026, 23:12 UTC

    More sites from the clean-up audit (tsk-hgnbapyw7hnh, uncovered-files pass at 9dfd4b65):

    • routes/limit.py:42
    • ticker.py:689; routes/ticker.py:237
    • ktw.py:260

    Related: tsk-jzkpfe8yfkgr item 1 is the formatting side ("RFC 3339 or null", about 25 copies; not_listening_digest._stamp uses isoformat). One PR could do both directions.