Skip to content

fix(DateInput, DateTimeInput, DateRangeInput, Calendar): follow the provider locale for date formatting and parsing - #5120

Merged
nynexman4464 merged 2 commits into
meta:mainfrom
HelloOjasMutreja:fix/plaindate-locale-formatting
Aug 21, 2026
Merged

nynexman4464 merged 2 commits into
meta:mainfrom
HelloOjasMutreja:fix/plaindate-locale-formatting

Conversation

@HelloOjasMutreja

@HelloOjasMutreja HelloOjasMutreja commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Part of #5074, which covers several locale-ignoring paths across Calendar, DateInput/DateTimeInput, Timestamp, and PowerSearch. This PR scopes to the shared plainDate/dateParser utilities and their direct consumers (DateInput, DateTimeInput, DateRangeInput, Calendar, and the exported useCalendarNavigation hook). Timestamp's relative-time and absolute-date formatting, and PowerSearch, need their own investigation and will follow as separate PRs. (Follows #5117, which already covered Calendar's weekday header names.)

Evidence

plainDateFormat (packages/core/src/utils/plainDate.ts), which backs formatSharedDate and is used directly by DateRangeInput and Calendar:

export function plainDateFormat(
  pd: PlainDate,
  options: Intl.DateTimeFormatOptions,
): string {
  return new Intl.DateTimeFormat(undefined, options).format(
    plainDateToDate(pd),
  );
}

undefined resolves to the host/browser locale. formatSharedDate is the shared entry point DateInput's display path uses (per its own doc comment, it's also the single source of truth Timestamp's formatTimestamp switch maps onto).

Separately, dateParser.ts's isLocaleDayFirst (used to disambiguate genuinely ambiguous numeric input like "3/4/2026" as day-first or month-first) had the same problem:

export function isLocaleDayFirst(): boolean {
  const parts = new Intl.DateTimeFormat().formatToParts(new Date(2000, 0, 15));
  ...
}

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?: Locale parameter to plainDateFormat, formatSharedDate, isLocaleDayFirst, and parseDateInput (threaded down to the internal parseNumericDate helper). Optional and additive, so no signature changes for any other caller of these exported utilities.

Threaded the locale through every consumer by reading InternationalizationContext.locale at each component/hook (DateInput, DateTimeInput, DateRangeInput, Calendar's three functions, and useCalendarNavigation), matching the exact pattern useDirection already uses for direction.

getTimeZoneParts (also in plainDate.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 for en-US and day-first for es-ES.
  • plainDate.test.ts: formatSharedDate with locale="es-ES" produces "25 de enero de 2026" for date_long.
  • DateInput.test.tsx: a component-level test rendering inside InternationalizationProvider 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 run on DateInput, DateTimeInput, DateRangeInput, Calendar, dateParser.test.ts, plainDate.test.ts: 453/453 passing
  • Verified new tests fail without the fix, pass with it
  • eslint clean on touched files (two pre-existing, unrelated borderVars unused-var warnings confirmed present before this change)
  • tsc --noEmit: no new errors on touched files
  • Changeset added

@vercel

vercel Bot commented Aug 16, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview Aug 21, 2026 4:20am

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 16, 2026
@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Aug 16, 2026
@github-actions

github-actions Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

Modified Components

Calendar (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 1439 -
Complexity N/A Very High (139) -
DateInput (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 531 -
Complexity N/A Very High (85) -
DateRangeInput (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 537 -
Complexity N/A Very High (66) -
DateTimeInput (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 852 -
Complexity N/A Very High (157) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.8KB 1.2KB

Accessibility Audit

Status: 1 accessibility violation(s) found — 1 critical.

DateRangeInput - 1 issue(s)
  • 🔴 critical: Ensure an element's role supports its ARIA attributes
    • Rule: aria-allowed-attr · Affects 1/20 stories · Learn more
    • WCAG: 4.1.2 (Level A)

Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@HelloOjasMutreja
HelloOjasMutreja marked this pull request as ready for review August 17, 2026 01:55
@nynexman4464
nynexman4464 force-pushed the fix/plaindate-locale-formatting branch from 98f90f0 to 88b71d6 Compare August 18, 2026 20:52
@nynexman4464
nynexman4464 changed the base branch from main to nynexman4464/fix/provider-locale-migrations August 18, 2026 20:54
github-actions Bot added a commit that referenced this pull request Aug 18, 2026
@nynexman4464
nynexman4464 force-pushed the fix/plaindate-locale-formatting branch from 88b71d6 to 98f90f0 Compare August 18, 2026 22:01
@nynexman4464
nynexman4464 changed the base branch from nynexman4464/fix/provider-locale-migrations to main August 18, 2026 22:01
@nynexman4464

Copy link
Copy Markdown
Contributor

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, main base, and description. We’ll provide review feedback first and keep any maintainer follow-up on a separate branch.

@nynexman4464 nynexman4464 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.

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:

  1. Gregorian calendar pinning in plainDateFormat and isLocaleDayFirst, because Astryx PlainDate is Gregorian.
  2. Provider-change rerender coverage rather than only initial-provider coverage.
  3. 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.
  4. 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));

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.

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)', () => {

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.

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.

github-actions Bot added a commit that referenced this pull request Aug 18, 2026
…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.

ghost 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.

Approved to land the provider-locale migration; the remaining Gregorian, deterministic-default, and coverage refinements will follow in a maintainer PR.

@github-actions github-actions Bot removed the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Aug 21, 2026
@nynexman4464
nynexman4464 merged commit 7646e92 into meta:main Aug 21, 2026

This branch was successfully deployed

1 active deployment
Preview — 2e8b6392 Deployed Aug 21, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants