Skip to content

feat(dates): every date and time through one Intl formatter, in the visitor's own format - #509

Merged
Ardnived merged 16 commits into
mainfrom
feat/shared-time-format
Nov 26, 2026
Merged

Ardnived merged 16 commits into
mainfrom
feat/shared-time-format

Conversation

@Ardnived

@Ardnived Ardnived commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Every date and time on screen now goes through @/lib/time, in the visitor's browser region: en-GB reads "17:45–18:45" and "Wed 18 Nov", en-US reads "5:45 – 6:45 PM" and "Wed, Nov 18".
  • A browser whose first language is not the page's keeps its own clock on an English page: cs-CZ and de-DE, de, en-US, en read "17:45", and pt-BR also reads "17:45".
  • Joined at review: distances follow the same locale, so they are miles for a UK or US region and kilometres elsewhere. This was the owner's call.

Change outline

Flow — where the format locale comes from

The format locale is now worked out once, in useLocale(), and every formatter takes it. Before this, each one received the page locale (en), which meant US English for everyone.

 useLocale()                                       src/hooks/use-locale.ts
   locale                                          # page locale: en, pt-BR …
+  formatLocale = regionalLocale(locale, navigator.languages)
+    first browser language is the page's → that tag as given (en-GB, en-US, pt-PT)
+    another language first → page language in that region (cs-CZ → en-CZ)
+      CLDR has no English for it → also state its clock (pt-BR → en-BR-u-hc-h23)
 useEventDisplay / EventListItem / SearchFilters / ActiveFilterPills / RegistrationForm / CalendarView
-  dt.setLocale(locale).toLocaleString({…}), Info.weekdays, DATE_MED, TIME_SIMPLE
+  formatDate · formatWeekday · weekdayNames · formatMonth · formatRelativeDate
+  formatTimeRange · formatTimePeriods · formatDistance        ← all take formatLocale

Behaviour — formatTimeRange

Times use the locale's own timeStyle: 'short', so whole hours keep their minutes. A range that wraps past midnight now keeps both day periods.

 formatTimeRange(start, end, locale)              src/lib/time.ts
-  hour + (minute only when needed)                # "6 – 7 PM", UK "18–19"
+  timeStyle: 'short', one cached formatter per locale   # "6:00 – 7:00 PM", "18:00–19:00"
   pin both ends to one day, then formatRangeToParts
+  end before start and only one dayPeriod left (5 PM → noon)
+    → each end written whole, joined by the locale's own mark   # "5:00 PM – 12:00 PM"
   otherwise the locale's own range                # "17:00–12:00 Uhr" keeps its suffix

Behaviour — dates, the calendar grid, distances

  • Dates: a year shows only outside the current year.
  • Calendar grid: Schedule-X follows the region.
  • Distances: miles come from the tag's region.
 formatDate(at, locale, { weekday })              src/lib/time.ts
-  year always (header), never (cards)
+  year only when at.year ≠ this year
 scheduleXLocale(formatLocale)                    src/lib/shape/calendar.ts (was SX_LOCALES in CalendarView)
+  English → en-GB or en-US by the tag's date order (en-CZ → en-GB)
+  else by language: de → de-DE …, pt → pt-BR (any Portuguese browser)
 usesMiles(locale)                                src/lib/distance.ts
-  exact tag in { en-us, en-gb }
+  tag's region is US or GB                       # de-GB, en-GB-u-hc-h23 → miles; en → km

Unchanged on purpose

The #380 clock rule is untouched. An in-person time names its city's clock only when the visitor's clock differs. An online class always names the visitor's clock, and the host line names the host's city too (option A).

Preview

Preview pending. Once the PR's Workers preview publishes, these routes show the change:

  • /gb/south-east/london/1817: the class time and next-session date
  • /search?format=online: the visitor's clock named on every online class
  • /calendar?region=gb: the header date and the grid's times
  • the filter form's time-of-day readout (Evening + Night + Morning)

Every page follows the reviewer's own browser language and time zone.

Test results

  • Lean gate (.claude/skills/pr-prep/check.sh, lint + typecheck + test:run) ✓: 207 files passed.
  • src/lib/time.test.ts and src/lib/events.time.test.ts cover both clocks, cs-CZ, pt-BR, es-MX, de-DE, de, en-US, en against en-US, de-DE, the wrap past midnight in en-US, en-GB and de, the year rule, and Schedule-X locales including pt-PT. src/lib/distance.test.ts covers the region rule.
  • These specs were seen failing without their fix: both wrap-past-midnight cases, and the Portuguese grid locale.
  • The affected component specs also pass under an en-GB machine locale (LANG=en_GB.UTF-8, 117 files). Their useLocale mocks now pin formatLocale.
  • git grep -n -e hour12 -e "'a'" -e toLocaleTimeString -- src ':!src/lib/time.ts' finds nothing new.
  • Build: left to CI.

Manual verification

  1. With browser language en-GB and time zone Europe/London, /gb/south-east/london/1817 reads "Every Friday · 17:45–18:45". With time zone Europe/Prague it reads "17:45–18:45 London time".
  2. With browser languages cs-CZ, and also de-DE, de, en-US, en, it reads "17:45–18:45 London time". With pt-BR it reads "17:45 – 18:45", and with es-MX "5:45 – 6:45 PM". (I checked all of these locally in Chromium.)
  3. With browser language en-US, it reads "5:45 – 6:45 PM". /search?format=online names the visitor's clock on every online class.
  4. With en-GB, /calendar?region=gb shows the same 24-hour clock as the class pages.
  5. A distance on a nearby-class row reads miles under en-GB or en-US, and km under en-CZ.

Notes for reviewer

  • This PR differs from the ticket:
    • Formatters not added yet: main has no add-a-class TimeStep, WeekList or DayHeading, so formatDayHeading, formatLongDate, formatDateRange and formatTime are not here yet. They arrive with those cards.
    • The ticket's Evening + Morning tag: on main those two periods don't form one range, so the wrap-past-midnight fix shows on selections that include Night (Evening + Night + Morning).
  • Sign-up dates: they drop the CSS capitalize. formatRelativeDate already sentence-cases ("Next week"), and capitalize would title-case every word, including lowercase month names in other languages.
  • Dismissed findings:
    • Whole-day filter shows a single time: timePeriodRanges returns [] for a whole-day cover, so this never reaches the formatter.
    • A 24-hour session collapses to one time: this predates the PR, and an occurrence spans at most one night (withEndTime).
    • Browser tags passed through verbatim: navigator.languages never carries extensions in practice, and every consumer takes a full tag.
    • dayFirst and usesMiles cost per call: about 30 µs per calendar mount and about 1 µs per list row. Not cached.
  • Date ranges across New Year: in the active-filter pill, each end gets its own year rule, so a range reads "20 Dec – 3 Jan 2027". This is kept as the ticket's year rule.
  • Follow-up: fix(dates): a region with no English data keeps its date order and clock #511 covers the two known gaps. A region CLDR has no English for (pt-BR, ru-RU) gets US month-first dates, and the en-AU grid's clock differs from its lists.
Detail
  • The approach is ported from f0f237d, 96088e4 and 7a75a04 on ux/all-proposals, trimmed to what main has callers for. The forced English hour12 those built on (1d58d7d, 5488ec0) was never on main.
  • Self-review:
    • /simplify ran with four angles. As a result, formatLocale moved into useLocale(), the wrap guard reads Intl's own parts instead of a 12-hour proxy (which restored German's "Uhr"), and duplicate tests and helpers were removed.
    • A local adversarial review (review-pr) found no blockers. Following it, scheduleXLocale moved beside the calendar shaping code, and the src/AGENTS.md rule names the module rather than listing its exports.
    • /code-review medium ran too. As a result, any Portuguese browser maps to Schedule-X pt-BR, navigator.languages is guarded, and spec comments no longer name a person.
  • No security-review trigger path or sink was in the diff.
  • Docs: a "Dates and times" rule in src/AGENTS.md, a formatLocale note in docs/rules/i18n-and-state.md, and a CHANGELOG.md entry (visible behaviour, with no parameter, origin or CSP change).

🤖 Generated with Claude Code

Ardnived and others added 7 commits November 26, 2026 11:26
…isitor's own format

Dates and times now go through src/lib/time.ts in regionalLocale(locale):
the browser's first language decides, so an en-GB browser reads
"17:45–18:45" and "Wed 18 Nov", en-US "5:45 – 6:45 PM" and "Wed, Nov 18",
and a browser whose first language is another keeps that language's clock
on the English page (cs-CZ "17:45", a Brazilian browser on en-BR-u-hc-h23).

- Times use timeStyle 'short', so whole hours keep their minutes.
- A range that wraps past midnight and runs 12 hours or more writes both
  day periods ("5:00 PM – 12:00 PM", not "5:00 – 12:00 PM").
- A year joins a date only when it is not this year.
- Callers: useEventDisplay, the filter time labels, ActiveFilterPills,
  SearchFilters (weekdayNames instead of luxon's Info.weekdays), the
  registration dates, and the calendar header; the Schedule-X grid runs
  regional English as en-GB or en-US by date order (scheduleXLocale).
- Distances follow the same locale: miles for a UK or US region.
- src/AGENTS.md gains the "Dates and times" rule.

Main's #380 clock rule is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- useLocale() returns formatLocale, so callers stop deriving regionalLocale
  themselves, and formatTimePeriods takes it like its siblings. The specs'
  useLocale mocks pin it, so they no longer read the machine's own locale
  (use-event-display.test.ts failed on an en-GB machine).
- formatTimeRange: the wrap-past-midnight join fires only when formatRange
  actually collapsed a day period, reading the separator off the same parts;
  a 24-hour locale keeps its own range and suffix ("17:00–12:00 Uhr").
- wallClock replaces events.ts's hourClock; formatDate drops its test-only
  `now` for luxon's Settings.now; usesMiles and dayFirst lose catches that
  guarded nothing; scheduleXLocale loses an unreachable row.
- Shorter comments and src/AGENTS.md rule; duplicate tests removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The regional locale hands Schedule-X the browser's own Portuguese tag
(pt-PT, pt), which matched no entry and fell back to en-US. Key the
table by language so every Portuguese tag runs pt-BR, as main did.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sydevs-dispatcher

sydevs-dispatcher Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

🤖 no session running
conflict held since 22:25Z, waiting for the base to settle

recent dispatches
  • 20:49Z review-pr · attempt 3 · session · timed out
  • 20:49Z review-pr · attempt 3 · session
  • 20:02Z review-pr · attempt 2 · session · timed out
  • 20:02Z review-pr · attempt 2 · session
  • 18:32Z review-pr · attempt 1 · session · timed out

Written by the sydevs dispatcher. Sessions never edit this comment.

@sydevs-dispatcher sydevs-dispatcher Bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 26, 2026
@sydevs-dispatcher sydevs-dispatcher Bot moved this from Pending to Working in SYDevelopers Technical Roadmap Nov 26, 2026
Ardnived and others added 3 commits November 26, 2026 12:01
…ng, not the formatters

scheduleXLocale is calendar configuration with one caller, so it moves from
lib/time.ts into lib/shape/calendar.ts beside the other Schedule-X helpers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
sahajatlas-design 40ea153 Nov 26 2026, 10:30 PM

@sydevs-dispatcher sydevs-dispatcher Bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Nov 26, 2026
@sydevs-dispatcher sydevs-dispatcher Bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Nov 26, 2026
Ardnived and others added 4 commits November 26, 2026 14:09
…t stop

The walk presses Tab once per tabbable element, but a roving-tabindex
group (#501's weekday picker) is one Tab stop holding seven, so on
molecules--form-field the walk outlasted the page, wrapped to ff-name and
reported it as a backwards jump. main has failed the gate since #501
and #510 landed together.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A stop the page rendered after the audit carries no data-a11y-order, and
Number(null) is 0, so views--event-·-sticky-register failed tab-order at
random whenever the audit read the story before it finished rendering.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sydevs-dispatcher sydevs-dispatcher Bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 26, 2026
@sydevs-dispatcher

Copy link
Copy Markdown
Contributor

The session for review-pr did not finish after 3 attempts. I have stopped retrying. A mention (@sydevs-bot) or a push from you starts me again.

🤖 sydevs dispatcher

# Conflicts:
#	src/components/molecules/EventListItem/EventListItem.tsx
@sydevs-dispatcher sydevs-dispatcher Bot moved this from Awaiting to Pending in SYDevelopers Technical Roadmap Nov 26, 2026
# Conflicts:
#	CHANGELOG.md
#	src/components/molecules/SearchFilters/SearchFilters.test.tsx
#	src/components/molecules/SearchFilters/SearchFilters.tsx
@Ardnived
Ardnived merged commit c218394 into main Nov 26, 2026
14 checks passed
@Ardnived
Ardnived deleted the feat/shared-time-format branch November 26, 2026 22:31
@sydevs-dispatcher sydevs-dispatcher Bot moved this from Pending to Done in SYDevelopers Technical Roadmap Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

1 participant