Skip to content

[6.x] Fix date formats#14256

Merged
jasonvarga merged 2 commits into6.xfrom
fix-date-locale
Mar 16, 2026
Merged

[6.x] Fix date formats#14256
jasonvarga merged 2 commits into6.xfrom
fix-date-locale

Conversation

@jasonvarga
Copy link
Member

@jasonvarga jasonvarga commented Mar 15, 2026

What & Why

DateFormatter was using navigator.language as the default locale, which often returns a regionless tag like en. When passed to Intl.DateTimeFormat, this resolves to US formatting (MM/DD/YYYY) — affecting users in the UK, Australia, Europe, etc. who have their browser set to English without a region.

The fix uses Intl.DateTimeFormat().resolvedOptions().locale as the fallback instead, which returns a fully resolved locale from the system/OS regional settings (e.g. en-GB rather than en).

A static DateFormatter.defaultLocale property is also introduced, which takes priority when set. This is used in tests to keep assertions deterministic without mocking navigator.language, and could serve as a hook for overriding via a preference if necessary.

Changes

  • Removed #locale = navigator.language field initializer
  • locale getter now returns DateFormatter.defaultLocale ?? Intl.DateTimeFormat().resolvedOptions().locale
  • Tests swap setNavigatorLanguage() for DateFormatter.defaultLocale in beforeEach

Fixes #14074
This PR intentionally does not introduce a preference. I'd like to see if this resolves the issue before introducing another thing.

Instead of using navigator.language (which often returns a regionless tag
like "en", defaulting to US formatting), fall back to
Intl.DateTimeFormat().resolvedOptions().locale which returns a fully
resolved locale from the system/OS regional settings.

Adds DateFormatter.defaultLocale as a static override for testing and
future per-user preference support.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jasonvarga jasonvarga changed the title Improve default locale detection in DateFormatter [6.x] Improve default locale detection in DateFormatter Mar 16, 2026
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jasonvarga jasonvarga marked this pull request as ready for review March 16, 2026 17:55
@jasonvarga jasonvarga changed the title [6.x] Improve default locale detection in DateFormatter [6.x] Fix date formats Mar 16, 2026
@jasonvarga jasonvarga merged commit 14bbfd0 into 6.x Mar 16, 2026
22 checks passed
@jasonvarga jasonvarga deleted the fix-date-locale branch March 16, 2026 18:00
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.

Cant change the date format in control panel

1 participant