Skip to content

Give slot dates and times a language - #895

Merged
richshaw merged 18 commits into
mainfrom
claude/issue-622-slot-format
Nov 14, 2026
Merged

richshaw merged 18 commits into
mainfrom
claude/issue-622-slot-format

Conversation

@richshaw

Copy link
Copy Markdown
Owner

Part of #622: slot dates and times take a language. The other formatters follow in the next PR; the image check is #890.

Merge after #894.

The stack

PR 6 of the localization stack (#619). Based on #894 (claude/issue-624-precompile); review against that branch.

The problem

Every slot date and time is printed in US English: formatSlotDate names en-US, and formatSlotTime writes a 12-hour clock by hand ("18:30" → "6:30 PM"). A Swedish reader expects "lör 3 maj" and "18:30". The same functions run on the server (public page, Responses tab, emails, the edit and cancelled pages), in the browser (Build tab) and in the worker (reminders), so they need the reader's language passed in before any of those can be translated.

The fix

  • src/lib/slot-label.ts: formatSlotDate(iso, locale) and formatSlotTime(hhmm, locale), with locale required, so TypeScript found every caller.
    • A date is built from its parts with Date.UTC and formatted with timeZone: TIME_ZONE ('UTC', from src/i18n/config.ts, which says why), so neither the server's zone nor the browser's can move it. Before, it was built at local midnight and formatted in the local zone, which agreed but depended on both steps using the same zone.
    • English keeps today's output byte for byte. Its date goes through Intl with 'en' (the same pattern as en-US); its time keeps the hand-written 12-hour clock with the no-break space before AM/PM, because Intl's English puts a different space there depending on the runtime's ICU (Node's is U+202F).
    • Other languages use Intl: the date with the same weekday/month/day: short options, the time with timeStyle: 'short', which gives each language its own clock ("18:30", and "09:05" rather than hour: 'numeric''s "9:05" in Swedish).
  • Everything that prints a slot's values takes locale and passes it on: renderFieldValue, slotDetails, summarizeSlotValues, formatGroupLabel, buildMetaSegments, prettyHeader (locale before the optional label), and the commitment services editLimitsForCommitment and cancelledCommitmentState (and their private slotName), which take it as a parameter.
  • Every caller passes 'en' for now: SignupViewBody (once, as a local locale, threaded through groupSlots, nameGroupFor and titleFor), WysiwygSlot, WysiwygGroup, the Responses tab, slotText for the emails, and the edit page. Three callers the issue doesn't list: TimeSelect (the Build tab's time picker), share-message.ts (the share panel's dates and time) and buildMetaSegments in slot-format.ts.
  • formatSlotDate now formats only a stored YYYY-MM-DD and returns null for anything else. It used to fall back to new Date(iso) for any other string, in the host's zone, which is the zone dependence the issue rules out. No caller relied on it: renderFieldValue and share-message.ts both checked isRealDate first, so renderFieldValue loses its now-redundant check.

Checked against the issue

No CHANGELOG entry: nothing anyone sees or sets up changes.

Tests

  • slot-label.test.ts: the English strings the tests already pinned are unchanged ('Sat, Apr 25', '6:30 PM', '12:00 AM', …), now with 'en'. New: Swedish dates ('lör 3 maj') and times ('18:30', '09:05', '00:00'), through formatSlot*, renderFieldValue and slotDetails; impossible dates (2026-02-31, 2026-13-01) still null in both languages and shown as typed by renderFieldValue; a timestamp and a typed "Sat, Nov 14" now null. The existing time-zone test now also checks Swedish under America/Los_Angeles and Pacific/Auckland, and a new one checks that times keep their hour under both.
  • slot-summary.test.ts, prettyHeader.test.ts: one Swedish case each, so the locale is shown to reach the formatter.
  • commitments.db.test.ts: a dated slot's name from editLimitsForCommitment in English (Juice · Mon, May 3) and Swedish (Juice · mån 3 maj), and from cancelledCommitmentState in Swedish once cancelled.
  • The new tests failed against the old slot-label.ts for the right reason (English output where Swedish was expected, a timestamp formatted rather than null).

Ran in this session, all passing:

  • pnpm lint, pnpm format:check, pnpm typecheck, pnpm knip, pnpm test (194 files, 2340 tests).
  • The formatter tests again with TZ=America/Los_Angeles and TZ=Pacific/Auckland set for the whole run (slot-label, slot-summary, prettyHeader, slot-format, share-message; 119 tests each).
  • pnpm test:db (40 files, 680 tests).
  • pnpm build && pnpm budgets. I also built Precompile the message catalogs at build time #894's head and measured both exactly: every page is within 21 bytes of gzipped first-load JavaScript of before (the Build tab +21, / +16, /s/[slug] and preview +15, the Responses tab −9), so no budget changes.
  • e2e against the production build, with the container's Playwright config: time-format.spec.ts unchanged and passing ("6:30 PM" in the builder and on the public page), plus public-commit, edit-token, responses, slot-row-layout, reminder-field and the two help walkthroughs that pin dates (create-and-publish-a-signup, take-someone-off-a-slot).

Generated by Claude Code

claude and others added 13 commits November 13, 2026 22:31
Part of #620: the core. next-intl and use-intl 4.14.9, pinned together
(icu-minify too, through an override), with next.config.mjs wrapped in
next-intl's plugin. src/messages/en.json is the English catalog, and
next-intl's AppConfig is typed from it, through the declaration the
plugin writes, so a missing key or a wrong argument fails typecheck.

src/i18n holds the pure locale config (CATALOG_LOCALES, SHIPPED), a
synchronous translator on use-intl/core with English filled in under
any other language, the server wrapper that logs what goes wrong, the
request config the plugin needs, and an English translator for tests
that throws.

The site footer's labels are the first text in the catalog, so the
translator is proven in a server component, on static and dynamic
pages. A new check runs it under the worker's toolchain. No page's
first-load JavaScript changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt
A local ESLint plugin in eslint.config.mjs, with one rule so far:
opensignup/no-catalogs-in-client. In a file that opens with a 'use client'
directive, it reports any import of a catalog in src/messages, or of the
translators that load every catalog (src/i18n/translator.ts, server.ts and
testing/translator.ts), since either would put that text in the browser's
JavaScript. It reads the directive rather than matching paths, follows
@/ and relative paths, re-exports, import(), require() and import paths
built from a template, and lets type-only imports through, since those are
compiled away. The message says why and what to do instead.

The tests lint fixtures through the repo's own config, so they also prove
the rule is on for the app's files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt
A unit test over src/messages/ checks every catalog against en.json:
completeness per namespace, enforced for each language in SHIPPED for the
namespaces its audience reads; every message compiles with icu-minify;
placeholders, tags and select branches match English, and each placeholder
takes the value English is passed; no key English lacks; and no English
message the app doesn't use.

Which keys the app uses comes from the type checker: a call whose signature
is use-intl's Translator, its namespace from the keys it accepts, its key
from the type of its argument, so helpers, props, aliases and typed tables
are all seen, and a key or namespace it can't read fails the check.

The audience namespaces move from a comment to AUDIENCE_NAMESPACES in
src/i18n/config.ts. src/types/next-intl.d.ts imports next-intl, because an
augmentation alone doesn't load its module: without it, code with no test
importing next-intl typed every message key as a plain string.

icu-minify is a devDependency at exactly 4.14.9, the version next-intl and
use-intl resolve, and the pnpm override now points at it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt
Two rules, on only for the files and folders listed in TRANSLATED in
eslint.config.mjs, which so far is the site footer:

- react/jsx-no-literals with noStrings and ignoreProps, for JSX text;
- opensignup/no-literal-text-props, a local rule for a string on
  aria-label, aria-description, title, placeholder, alt or label.
  noAttributeStrings would also flag every className and href.

TRANSLATED takes paths as they are on disk. filesAt escapes them for
the config's globs, since an unescaped src/app/s/[slug]/** matches
src/app/s/s/ and not the [slug] folder, and stops lint when a path
doesn't exist. The footer's license line is exempt with a comment.

Also, from #891's review: no-catalogs-in-client follows a + chain that
starts with a string, as it does a template, and denies every module in
src/i18n/ to client files except those in CLIENT_SAFE_I18N (config),
rather than listing the modules that load catalogs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt
A translation that kept a select's argument but dropped the select
(`Status: {status}` for English's `{status, select, open {Open} ...}`)
passed, and would show participants the code's value. The check now
reports `{status} isn't a select here, but is in English`.

From the same review:
- The check's program types translators against the en.json it just
  loaded, written over src/messages/en.d.json.ts, so a stale declaration
  no longer gives misleading lines. findUsedKeys now builds the program
  itself, and the fallback for a stale declaration is gone, with its edge
  case that could pick the wrong section. messages-declaration.test.ts
  still fails on a stale file.
- Code in any `testing` folder and in src/mcp/evals doesn't count as a use.
- `t?.('key')` is seen.
- A test for the dot-in-key check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt
Turn on next-intl's experimental message precompiling, so the first
client component with translated text ships a small formatter instead of
use-intl's ICU parser: measured here at 3,470 bytes gzipped against
12,353 without it.

Under precompile the plugin's loader compiles every catalog the Next
build imports, the server's too, and a message with an argument, plural
or tag becomes an array. withEnglishUnder treated every object as a
section and went into those arrays, so each such message would have
rendered as its key path in the web process while vitest and the worker,
which read the raw JSON, stayed green. A message is now a string or an
array, and only a section is merged into.

The footer's "{INSTANCE_NAME} · AGPL-3.0" line becomes a message with an
argument, the first the app has, and a production-build e2e checks it on
a prerendered page, a page rendered per request and the public signup
page. A unit test runs next-intl's own loader over every catalog and
checks each message formats the same precompiled as from the raw JSON.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt
…ext-lint

Brings in #892's review fixes (a7a10ed) so this PR stays on top of #892's final state.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt
formatSlotDate and formatSlotTime now take the reader's language as a
required `locale`, and so does everything that prints a slot's values:
renderFieldValue, slotDetails, summarizeSlotValues, formatGroupLabel,
buildMetaSegments, prettyHeader, and the two commitment services that name a
slot for the edit and cancelled pages. Every caller passes 'en' for now, so
nothing anyone sees changes.

A date is built from its parts as a UTC moment and formatted in UTC, so no
zone can move it to another day. English keeps today's output exactly,
including the hand-written 12-hour clock with its no-break space before
AM/PM; other languages get Intl's own ("lör 3 maj", "18:30" in Swedish).

formatSlotDate now formats only a stored YYYY-MM-DD. It used to fall back to
`new Date()` for any other string, in the host's zone; no caller relied on
that, as both checked isRealDate first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt
filesAt escaped the characters a glob reads specially but not the
backslash it escapes them with, so a listed folder named `a\b` became
the glob `a\b/**`, which matches `ab/` and not `a\b/`. The backslash is
now escaped in the same pass as the rest.

filesAt takes an optional root so a test can list a real folder with a
backslash in its name, made in a temporary directory, and check the glob
with ESLint's own matcher.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt
@richshaw richshaw added pipeline:tophat pipeline:working A session is working on it right now labels Nov 14, 2026 — with Claude
@richshaw
richshaw requested a balanced review from Copilot November 14, 2026 00:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

…mpile

Brings in #893's later commits (#892's final code, main, and the filesAt escaping fix) so this PR stays on top of #893.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt
…-format

Keeps this PR on top of #894's current branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt
main now holds #893 (7a9fada), whose final code this branch already had. The only conflict was the footer line #893 exempted from lint and this PR turns into a message; this branch's version is kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt
…-format

Keeps this PR on top of #894's current branch, which now has main (#893) merged in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt
Base automatically changed from claude/issue-624-precompile to main November 14, 2026 00:29

Copy link
Copy Markdown
Owner Author

Tophat: passed

Ran 86a0365 locally with pnpm dev and the worker, Postgres 16, Chromium at 1280×900 and 390×844 (device scale 2). For a like-for-like comparison I ran the PR's base, #894 at 9ca3cb6, as a second dev server against the same database, so every page, email and export below was compared on identical data. The PR's own diff against its base is byte-identical to the builder's commit (20409b8, 18 files, +344/−190). Since then the head moved to ee870e1, a merge of #894's branch: its tree is identical to 86a0365 (and #894's new head 1559802 has 9ca3cb6's tree), so this result holds for ee870e1 too.

Test data (made up): "Snack duty — Spring season", grouped by date, with What/Date/Time fields and slots at 12:00 AM (midnight), 12:00 PM, 6:30 PM, 9:05 AM and 11:59 PM, a date-only slot, a slot on 1 Jan, one on a US DST-change day, and one with no date; plus an ungrouped "Carpool" signup whose slots share one date and time; plus a sheet with legacy values in the date field (see the last row).

Check Result What I saw
Public page /s/[slug], desktop and phone ✅ Visible text and the <main> HTML (aria-labels included, e.g. Sign up for Sun, Nov 15, Evening cleanup, 6:30 PM) byte-identical to the base, before and after sign-ups. Only the footer commit SHA differs. The no-break space before AM/PM is still there.
Sign-up dialog and its confirmation ✅ Dialog heading Sun, Nov 15 · 6:30 PM / Sat, Nov 21 · 9:05 AM and "We've saved your spot for Sun, Nov 15 · Evening cleanup · 6:30 PM" identical; only the participant's address, the edit link and the spots-left count differ (two sign-ups)
Participant's edit page, and the cancelled page ✅ Same commitment URL rendered on both servers: text and HTML identical (Evening cleanup · Sun, Nov 15 · 6:30 PM; after cancelling through the UI, Your spot was cancelled / Morning juice · Sat, Nov 21 · 9:05 AM)
Build tab: group headers, slot rows, TimeSelect ✅ Text and HTML identical. Opened the slot editor on the 6:30 PM slot: the picker's 97 options (No time, 12:00 AM … 11:45 PM) and the selected 6:30 PM identical
Preview ✅ Screenshots pixel-identical to the base, both signups, desktop and phone
Responses tab and CSV export ✅ Slot column (Evening cleanup · Sun, Nov 15 · 6:30 PM) identical. CSV byte-identical and still raw values (2026-11-15,18:30)
Share message ✅ Sat, Nov 14 to Sun, Mar 14 · 49 spots open and Sat, Nov 28, 11:00 AM · 3 spots open, the same on both
Confirmation emails (server log) ✅ Subjects identical, e.g. You're signed up: Snack duty — Spring season · Morning juice · Sat, Nov 21 · 9:05 AM. The log only previews 600 characters, so I also rendered every commitment's confirmation, reminder and "Time changed" email (text and HTML) with both checkouts' own code: byte-identical (Date: Sun, Nov 15 / Time: 12:00 AM)
Worker reminder for a slot inside 24 hours ✅ Signed one participant up through each server on the midnight slot and on a date-only slot for today, backdated the sign-ups past the one-hour guard, and ran pnpm reminders:due --dispatch with the base's worker, then with the PR's. Same subjects: Reminder: … · Midnight setup · Sun, Nov 15 · 12:00 AM and Reminder: … · Bring napkins · Sat, Nov 14
TZ=America/Los_Angeles ✅ Restarted both servers and the worker with it, and set the browser to the same zone: every page, the editor, the picker and the share text matched the UTC run exactly. A real reminder from the PR's worker in that zone still read Sun, Nov 15 · 12:00 AM and Sat, Nov 14 (no day moved back). Emails rendered under LA and Pacific/Auckland were byte-identical to UTC, and a browser in Auckland with a Swedish browser language still showed the same English
formatSlotDate now formats only YYYY-MM-DD ✅ Its only callers are renderFieldValue and the share message, and both already checked isRealDate on the base, so nothing shown changes. The API refuses a non-date value in a date field, and so does retyping a text field that holds one (conflict). To cover legacy rows I wrote Sat, Nov 14, 2026-11-15T00:00:00Z and 2026-02-31 straight into a date field in my test database: on both servers the public page, Build tab, Preview and emails show them as typed (2026-11-15T00:00:00Z stays as it is), identically
Console and server errors ✅ No browser console errors in any run. Server logs show only the same dev noise on both checkouts (pino's MaxListeners warning, and the health check's pgboss.job miss before the worker first ran on a new database)

Also ran the formatter unit tests (slot-label, slot-summary, share-message, slot-format, prettyHeader, 119 tests) under TZ set to UTC, America/Los_Angeles and Pacific/Auckland: all pass.

Not checked in the app: the Magic Compose questions also use TimeSelect, but they need an AI provider. It's the same component, checked above in the Build tab.

No visible change, so ux=no. Screenshots (base and PR side by side) are in https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt.


Generated by Claude Code

@richshaw richshaw left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: passed (round 1)

The PR gives formatSlotDate and formatSlotTime a required locale and passes it through everything that prints a slot's values. Every caller passes 'en', and the commitment services take the locale as a parameter rather than reading it from anywhere. For this part of the issue the PR does what the outline asks, and does it carefully. A date is built with Date.UTC from its validated parts and formatted with timeZone: TIME_ZONE, so the machine's time zone can't move it. (isRealDate refuses years before 1900, which also keeps Date.UTC away from its habit of reading years 0–99 as 1900–1999.) English keeps the hand-written 12-hour clock with its no-break space, and other languages go through Intl.

I compared the old and new English output for every day from 1900 to 2100 and every minute of the day. I also put odd stored values through renderFieldValue: timestamps, typed dates, days that don't exist, years before 1900, numbers and padded strings. I ran all of it with TZ set to UTC, America/Los_Angeles, Pacific/Auckland and Pacific/Kiritimati. All 74,872 outputs matched except one, and that one is a fix. Kiritimati skipped 31 December 1994, so the old code's local midnight rolled over and printed 1994-12-31 as "Sun, Jan 1". The new code prints "Sat, Dec 31".

formatSlotDate now formats only YYYY-MM-DD, and nobody sees a difference:

  • its only callers are renderFieldValue and share-message.ts, and both already checked isRealDate first;
  • nothing in scripts/ or tests/ calls it;
  • the tophat put old non-date values into a date field, and both versions show them as typed.

Blocking (0)

Optional (3):

  • locale is a plain string (src/lib/slot-label.ts:38,57, src/components/build-wysiwyg/prettyHeader.ts:18). That leaves three gaps. None of them can happen while every caller passes 'en':

    • The English clock is used only for exactly 'en'. A regional tag like 'en-US' would go to Intl and get the runtime's U+202F before PM (Node's does), which is the difference the code comment says this branch avoids.
    • A malformed tag makes the Intl.DateTimeFormat constructor throw RangeError in the middle of a render.
    • locale now sits in front of prettyHeader's optional fieldLabel, so a call written the old way, prettyHeader(raw, type, label), still type-checks and reads the label as the locale.

    Narrowing the type to the catalog's locales once sv joins CATALOG_LOCALES would close all three; resolveLocale in #625 is where the values will come from. string is right for now, because the Swedish tests couldn't be written against CatalogLocale yet.

  • Hydration, for later. Three Build tab components format during render, and they are client components: TimeSelect, WysiwygSlot and WysiwygGroup (through prettyHeader). With 'en', the server and browser output can't differ: the English time is written out by hand, and the English date already went through Intl on both sides before this PR. The first PR that passes a signup's language to these components will need to format on the server and pass the text in, or make sure both ICUs agree. #622's "Watch for" section records this. #634, the next issue to touch the Build tab, doesn't mention it.

  • The PR body is out of date. It still says Merge after #894 and "Based on #894 … review against that branch". #894 has merged and this PR is now against main. The merge line no longer holds anything up, but the stack section could say the PR is now on main.

Earlier threads: none. Copilot couldn't review (out of quota), so this review went ahead without it.

Checks:

  • CI is green on 325f17a (run 43536124067: lint, format, typecheck, knip, unit and database tests, build, budgets and e2e, plus CodeQL).
  • Tophat: it passed at 86a0365, and that result covers this head. 325f17a, ee870e1 and 86a0365 have the same tree (7096ee2). The merge of main since then brought in only #894's squash, and the shared check counts 0 runtime hunks since the tophat.
  • Formatter tests, run locally: slot-label, slot-summary, prettyHeader, slot-format and share-message (119 tests) pass with TZ set to UTC, America/Los_Angeles, Pacific/Auckland and Asia/Kolkata.
  • Time-zone tests: removing timeZone from either formatter makes a test fail ('Fri, Apr 24' for the date, '16:30' for the time), so these tests really check what they claim.
  • Speed: a quick benchmark shows an English date costs the same as before.

https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt


Generated by Claude Code

@richshaw
richshaw merged commit bf10cdd into main Nov 14, 2026
5 checks passed
@richshaw
richshaw deleted the claude/issue-622-slot-format branch November 14, 2026 00:53
@richshaw richshaw removed pipeline:merge pipeline:working A session is working on it right now labels Nov 14, 2026 — with Claude
richshaw pushed a commit that referenced this pull request Nov 14, 2026
#896 merged, so main now holds this branch's base. The one conflict,
src/lib/slot-label.ts, is between #895 and #896 as squashed on main and
the same commits in this branch's history; main's copy equals #896's
head, so the branch's copy (with TIME_ZONE from its new module) stands.
The merged tree is identical to the branch's before the merge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants