Repository navigation
fix(DateInput, DateTimeInput, DateRangeInput, Calendar): follow the provider locale for date formatting and parsing - #5120
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsCalendar (@astryxdesign/core) · View in Storybook
DateInput (@astryxdesign/core) · View in Storybook
DateRangeInput (@astryxdesign/core) · View in Storybook
DateTimeInput (@astryxdesign/core) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: 1 accessibility violation(s) found — 1 critical. DateRangeInput - 1 issue(s)
Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
98f90f0 to
88b71d6
Compare
88b71d6 to
98f90f0
Compare
|
Apologies — while exploring how to split the provider-locale migration and lint enforcement into a stacked set of PRs, my coding agent incorrectly force-rebased this branch and changed the PR description before we had provided proper review feedback. I’ve restored the original branch head, |
nynexman4464
left a comment
There was a problem hiding this comment.
Thanks for taking on the date-specific part of #5074. We’ve since been mapping the broader ambient-locale problem across the package, and this PR fits cleanly as the Calendar/date-input/date-helper slice:
- provider-locale utilities are being handled separately;
- Table, Timestamp, PowerSearch, Charts, and speech defaults are separate non-date work;
- this PR owns date formatting and ambiguous numeric day/month parsing;
- raw-Intl lint enforcement comes afterward, once the migrations are in place;
- compact weekday labels remain separate in #5190.
Keeping the helper locale parameters optional makes sense for source compatibility; we don’t need a codemod or breaking migration here.
Before landing, I think this needs:
- Gregorian calendar pinning in
plainDateFormatandisLocaleDayFirst, because AstryxPlainDateis Gregorian. - Provider-change rerender coverage rather than only initial-provider coverage.
- A little more component-level coverage for the independently wired paths—at minimum Calendar/month navigation and the DateRangeInput/DateTimeInput committed display paths—so the helper tests don’t mask a caller that forgot to thread
locale. - Narrower wording around parsing: this makes ambiguous ASCII numeric input follow D/M versus M/D ordering. It does not yet localize month-name parsing, non-Latin digits, or arbitrary locale date strings.
Once those are addressed, this should be the date-migration piece we build the later enforcement on. Adoption of the new useLocale helper can be a maintainer follow-up rather than additional scope for this contribution.
| return new Intl.DateTimeFormat(undefined, options).format( | ||
| plainDateToDate(pd), | ||
| ); | ||
| return new Intl.DateTimeFormat(locale, options).format(plainDateToDate(pd)); |
There was a problem hiding this comment.
Thanks for threading the locale through here. One calendar-model issue: PlainDate and Calendar’s arithmetic/grid are Gregorian, but Intl.DateTimeFormat(locale, options) honors the locale’s default calendar or a -u-ca-* extension. For example, fa-IR can render this Gregorian date as a Persian-calendar date while Calendar still displays and navigates Gregorian fields.
Could we pin the formatter to Gregorian and add a non-Gregorian-default locale regression test?
new Intl.DateTimeFormat(locale, {
...options,
calendar: 'gregory',
})The isLocaleDayFirst probe in dateParser.ts should make the same assumption.
| expect(screen.getByDisplayValue('Jan 25, 2026')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('follows the InternationalizationProvider locale (#5074)', () => { |
There was a problem hiding this comment.
Could this test rerender the same component from one provider locale to another—for example en-US → es-ES—and assert that the displayed value changes? That proves the provider remains the live source after mount and catches a missing memo/callback dependency, rather than only proving that an initial Spanish locale is accepted.
…rovider locale for date formatting and parsing plainDateFormat (backing formatSharedDate, used by DateInput, DateTimeInput, DateRangeInput, and Calendar) called new Intl.DateTimeFormat(undefined, options), which resolves to the host/browser locale. dateParser's isLocaleDayFirst, which disambiguates numeric input like "3/4/2026" as day-first or month-first, had the same problem. A tree wrapped in an InternationalizationProvider with a non-English locale still formatted and parsed dates using the host locale. Added an optional trailing locale parameter to plainDateFormat, formatSharedDate, isLocaleDayFirst, and parseDateInput, and threaded it from every consumer by reading InternationalizationContext.locale at each component/hook. Optional and additive, so no signature changes for any other caller. Part of meta#5074, which also covers Timestamp's relative-time and absolute-date formatting and PowerSearch's date/number formatting and hardcoded copy. Those need their own investigation and will follow as separate PRs.
98f90f0 to
2e8b639
Compare
Summary
Part of #5074, which covers several locale-ignoring paths across
Calendar,DateInput/DateTimeInput,Timestamp, andPowerSearch. This PR scopes to the sharedplainDate/dateParserutilities and their direct consumers (DateInput,DateTimeInput,DateRangeInput,Calendar, and the exporteduseCalendarNavigationhook).Timestamp's relative-time and absolute-date formatting, andPowerSearch, need their own investigation and will follow as separate PRs. (Follows #5117, which already coveredCalendar's weekday header names.)Evidence
plainDateFormat(packages/core/src/utils/plainDate.ts), which backsformatSharedDateand is used directly byDateRangeInputandCalendar:undefinedresolves to the host/browser locale.formatSharedDateis the shared entry pointDateInput's display path uses (per its own doc comment, it's also the single source of truthTimestamp'sformatTimestampswitch maps onto).Separately,
dateParser.ts'sisLocaleDayFirst(used to disambiguate genuinely ambiguous numeric input like"3/4/2026"as day-first or month-first) had the same problem:A tree wrapped in
InternationalizationProvider locale="es-ES"still formatted committed dates and disambiguated ambiguous typed input using the host locale, not the provider's.Fix
Added an optional trailing
locale?: Localeparameter toplainDateFormat,formatSharedDate,isLocaleDayFirst, andparseDateInput(threaded down to the internalparseNumericDatehelper). Optional and additive, so no signature changes for any other caller of these exported utilities.Threaded the locale through every consumer by reading
InternationalizationContext.localeat each component/hook (DateInput,DateTimeInput,DateRangeInput,Calendar's three functions, anduseCalendarNavigation), matching the exact patternuseDirectionalready uses fordirection.getTimeZoneParts(also inplainDate.ts) deliberately hardcodes'en-US'for stable digit parsing, per its own doc comment, and is correctly left untouched, it's not locale-display output.Test notes
Added regression tests:
dateParser.test.ts: the ambiguous"3/4/2026"case resolves to month-first foren-USand day-first fores-ES.plainDate.test.ts:formatSharedDatewithlocale="es-ES"produces"25 de enero de 2026"fordate_long.DateInput.test.tsx: a component-level test rendering insideInternationalizationProvider locale="es-ES"confirms the committed display value follows the provider.Verified each new test fails without the corresponding fix (falls back to host-locale output) and passes with it restored. Full suite across the five touched components/utilities (453 tests) passes.
Test plan
vitest runonDateInput,DateTimeInput,DateRangeInput,Calendar,dateParser.test.ts,plainDate.test.ts: 453/453 passingeslintclean on touched files (two pre-existing, unrelatedborderVarsunused-var warnings confirmed present before this change)tsc --noEmit: no new errors on touched files