fix(polls): stop scheduled polls shifting by the UTC offset - #204
Merged
Conversation
A poll scheduled for 9am went live at 5am. The poll form's datetime-local inputs produce a zoneless "2026-08-07T09:00", the page sent that string to the API verbatim, and parsePollTime read zoneless layouts with time.Parse, which labels them UTC. Philadelphia's offset is the whole error. The browser is the only side that knows which zone the editor typed in, so it now says: localInputToISO puts starts_at/ends_at through toISOString on both create and edit, matching what the article editor already does. The server no longer guesses. RFC3339 is the only accepted form; the old zoneless layouts are recognised solely to name the problem in the error, which the call sites now pass through instead of a bare "invalid starts_at" -- a stale browser tab gets a message that explains itself, not a silent 400. Frontend and server ship together, so don't cherry-pick the server half on its own. Polls saved before this are still shifted in the database; re-saving one through the form corrects it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Reported on Discord: a poll scheduled for 9am saved as 5am.
Cause
The poll form's
datetime-localinputs produce a zoneless"2026-08-07T09:00", and the page sent that string to the API verbatim.parsePollTimeaccepted zoneless layouts viatime.Parse, which labels them UTC — so 9am Philadelphia was stored as 09:00Z and rendered back as 5am. The four hours is just the EDT offset; in winter it would have been five.Fix
Frontend —
localInputToISOruns the local wall-clock string throughtoISOString()before sending, on both create and edit. The browser is the only side that knows which zone the editor typed in. This is the same helper the article editor has had all along; polls never got one. Empty still maps tonull, so "explicit null clears the date" on PATCH is unchanged.Server — RFC3339 is now the only accepted form. The three old zoneless layouts are still recognised, but only so the error can name the problem:
The four call sites were writing a bare
"invalid starts_at"; they now wrap the parse error, and the polls page already rendersbody.errorin its failure banner — so a stale browser tab hitting this gets a message that explains itself rather than a silent 400.Notes for the reviewer
Testing
TestParsePollTimecovers absent / clear / offset-preserved / zoneless-rejected / nonsense.go build,go vet ./..., the handler suite, and frontendtsc --noEmitall pass.🤖 Generated with Claude Code