Skip to content

fix(dates): a region with no English data keeps its date order and clock #511

Backlog

Description

@Ardnived

Summary

On the English page, dates and times follow the visitor's browser region (#509), but two regions slip back to US formats:

  • No English data for the region. CLDR has no English for Brazil, Russia, Türkiye, Mexico, Egypt or China. A browser whose first language is pt-BR, ru-RU, tr-TR, es-MX, ar-EG or zh-CN gets its own clock, but US month-first dates: "Fri, Nov 13", where its own order is "Fri 13 Nov".
  • No Schedule-X strings for the region. Schedule-X bundles only en-GB and en-US English, so an en-AU, en-NZ or en-IN visitor's calendar grid runs as en-GB on a 24-hour clock ("17:45"), while the lists beside it read "5:45 pm".

Both come from one cause: a regional English tag that the data behind it can't serve. So they share one fix and one check.

Approach

1. Pick the English base by the browser's own date order (inBrowserRegion, src/lib/time.ts).

  • Today: inBrowserRegion builds en-<region> and adds -u-hc-<cycle> when the clock differs (en-BR-u-hc-h23). Intl then resolves en-BR to plain en, which is US date order.
  • Detect it: new Intl.DateTimeFormat(tag).resolvedOptions().locale has dropped the region (measured in Node 26 / ICU: en-BR, en-RU, en-TR, en-MX, en-EG and en-CN all resolve to en; en-CZ, en-DE and en-JP keep theirs).
  • Fix: when the region was dropped, base the tag on en-GB or en-US by the browser locale's own day/month order, then add -u-hc- as today: pt-BR becomes en-GB-u-hc-h23, zh-CN becomes en-US-u-hc-h23. The day-first probe already exists as dayFirst beside scheduleXLocale in src/lib/shape/calendar.ts; share it rather than copy it.
  • ⚠ Keep miles right. usesMiles (src/lib/distance.ts) reads the format locale's region, so a Brazilian en-GB-… tag would read miles. Carry the browser's real region where it can still be read, for example -u-rg-<region>zzzz. Check what Intl and luxon do with rg before relying on it. Otherwise give usesMiles the region another way. Miles stay limited to a US or UK region.

2. Keep the calendar grid on the lists' clock (scheduleXLocale, src/lib/shape/calendar.ts, and the patch patches/@[email protected]).

  • Today: scheduleXLocale maps any regional English to en-GB or en-US by date order. That keeps the date order, but gives the grid that locale's clock.
  • Why it can't just pass the tag: Schedule-X checks locale against ^[a-z]{2}-[A-Z]{2}$ (node_modules/@schedule-x/calendar/dist/core.js, around line 5065), and a tag with no bundled strings renders the raw keys. So it can't take en-AU or en-GB-u-hc-h12 as it stands.
  • Fix: let the grid carry the lists' hour cycle. Either relax that check in the existing patch so en-GB-u-hc-h12 passes and is used for time formatting while the strings stay under enGB, or set Schedule-X's own time-format options from the format locale's hourCycle. Pick whichever changes less of Schedule-X. Record the choice in the patch register (src/components/AGENTS.md § Patch register) if the patch grows.
  • Cover both directions: after the fix, the grid matches the lists for en-AU (12-hour), and for a 24-hour region that runs as en-US (zh-CN).

Tests: src/lib/time.test.ts (regionalLocale) and src/lib/shape/calendar.test.ts (scheduleXLocale) pin the cases below. src/lib/distance.test.ts pins miles for each new tag shape.

Acceptance criteria

  • On an English page, a browser whose first language is pt-BR, ru-RU or tr-TR reads dates day-first ("Fri 13 Nov") on its own 24-hour clock ("17:45").
  • es-MX and ar-EG read day-first dates on their own 12-hour clock.
  • zh-CN reads month-first dates on a 24-hour clock.
  • Regions CLDR has English for (en-CZ, en-DE, en-GB, en-US) read exactly as on main.
  • In the calendar grid, en-AU, en-NZ and en-IN read the same clock as the lists ("5:45 pm"). A 24-hour region that runs as en-US reads 24-hour times in the grid.
  • Distances still read miles only for a US or UK region. A pt-BR, ru-RU or en-AU browser reads kilometres.
  • No date pattern or am/pm is written by hand. Formatting stays in @/lib/time, and the Schedule-X mapping stays in src/lib/shape/calendar.ts.

Verification checklist

  • pnpm lint && pnpm typecheck && pnpm test:run pass, including the new cases in src/lib/time.test.ts, src/lib/shape/calendar.test.ts and src/lib/distance.test.ts.
  • pnpm dev, browser language pt-BR, time zone Europe/London: /gb/south-east/london/1817 reads "Every Friday · 17:45–18:45" and a next-session date like "Fri 27 Nov".
  • Same page with browser language en-AU: the time reads "5:45 – 6:45 pm". /calendar?region=gb shows the same 12-hour clock in the grid.
  • /calendar?region=gb with browser language zh-CN: the grid shows 24-hour times and month-first dates, matching the lists.
  • Browser language en-GB, then en-US: the class page and the calendar read exactly as before this change ("17:45–18:45" and "5:45 – 6:45 PM").

Notes

Blocked by: #509

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    Priority

    Low

    Hold Until

    None yet

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions