Repository navigation
Fix same-day notice expiry - #1027
Merged
Merged
Conversation
This was referenced Jul 25, 2026
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1024.
A notice with an
expires_atlater today kept being served as active until the next UTC day.Root cause
getActiveNoticesfilters withexpires_at > datetime('now'). Both sides are TEXT, so SQLite compares them byte-wise.datetime('now')emitsYYYY-MM-DD HH:MM:SS(space separator);expires_atwas stored as RFC3339 with aT, because the create route validates withz.string().datetime({ offset: true })and bound the value through unchanged.Tis0x54, space is0x20, so whenever the date halves matched, the ISO value always compared greater:Expiries on an earlier date compared correctly, which is why this survived — it looks right most of the time and fails on exactly the same-day window ("maintenance ends at 14:00 today") that same-day expiries exist for.
Fix
Normalize on write rather than patching the comparison:
datetime(?)on insert — converts any offset (or aZ) to the storage format, and is idempotent.idx_notices_expiresis finally sorted in the format the query actually compares against, which the string-vs-string version never was.The backfill is guarded with
AND datetime(expires_at) IS NOT NULL.datetime()returns NULL for an unparseable string and NULL in this column means never expires — without the guard a malformed timestamp would be silently promoted from "expired" to "permanent", the worst possible direction for a banner. Such a row is left as-is for a human to notice.Wire format change (worth a look)
Both timestamps are now projected as explicit-UTC RFC3339 (
strftime('%Y-%m-%dT%H:%M:%SZ', …)).Storage has to be space-separated for the comparison to work, but that format is a trap on the wire:
Date.parse("2026-07-25 14:30:00")is not ISO-8601, and V8 and JavaScriptCore both read it as local time, silently shifting the instant by each viewer's own UTC offset.I applied it to
created_atas well asexpires_at, which is slightly beyond the letter of #1024 — flagging it rather than burying it. The reasoning: they arrive in the same object, and returning one unambiguous field beside one that parses as local time is precisely how a timezone bug gets introduced later.created_atwas already being misparsed this way by both the website and the CLI; this fixes that too.Testing
backend/test/notice-expiry.test.ts— 15 tests against real in-memory SQLite, no mocks:datetime('now')on the same day, and the same instant throughdatetime()does not. If someone reverts the insert to binding the raw string, this fails.Z, a+02:00offset converted to UTC (14:30+02:00 → 12:30), null preserved, idempotent on already-normalized input…Z, null stays null, and the parsed instant is timezone-independentThe test imports
NOTICE_ACTIVE_FILTERandNOTICE_COLUMNSfrom the service rather than copying the SQL, so it can't drift from what the service actually runs. Those two fragments are newly exported for exactly that reason.bun test backend/test/— 796 passing.tsc --noEmitandbiome check src/clean.Note for the website
nemarOrg/website computes expiry client-side as a workaround for this bug (
isNoticeExpiredinsrc/lib/notices-api.ts). That code stays correct and becomes a harmless second opinion once this deploys — no coordinated change needed.