fix(date-time): use browser regional locale for default date format (#8023)

When no explicit dateTimeLocale override is set, the date adapter locale
followed the UI translation language (currentLang), which is region-agnostic
('en' resolves to US MM/DD/YYYY). This mis-formatted dates for en-GB/en-AU
users who never picked a date locale, and turned master red: 5 recurring
start-date E2E tests fail because the suite pins navigator.language=en-GB
and types DD/MM/YYYY.

Fall back to the browser regional locale (getBrowserCultureLang, e.g.
'en-GB') instead, with currentLang/defaultLang/DEFAULT_LOCALE as further
fallbacks. Regression introduced in #8000.
This commit is contained in:
Johannes Millan 2026-06-05 12:28:58 +02:00 committed by GitHub
parent 315c900391
commit 97cfb2829d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -61,11 +61,17 @@ export class DateTimeFormatService {
if (cfgValue) {
this.setDateAdapterLocale(cfgValue);
} else {
const uiLang =
// No explicit date/time override: follow the browser's regional locale
// (e.g. 'en-GB' → DD/MM/YYYY) rather than the UI translation language.
// The UI language is region-agnostic — 'en' resolves to US MM/DD/YYYY,
// which would mis-format dates for en-GB/en-AU/etc. users who never
// picked a date locale. Fall back to UI language, then the default.
const fallbackLocale =
this._translateService.getBrowserCultureLang?.()?.toLowerCase() ||
this._translateService.currentLang ||
this._translateService.defaultLang ||
DEFAULT_LOCALE;
this.setDateAdapterLocale(uiLang as DateTimeLocale);
this.setDateAdapterLocale(fallbackLocale as DateTimeLocale);
}
});
}