From 75b8f0cf02a7ad2958e5044d8ed6f5cae0fe84fc Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Sat, 23 Aug 2025 08:45:33 +0800 Subject: [PATCH] Prioritize Intl's locale instead of navigator.languages --- src/utils/date-time-format.js | 2 +- tests/date-time-format.spec.js | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/utils/date-time-format.js b/src/utils/date-time-format.js index 05610f72..20f524ea 100644 --- a/src/utils/date-time-format.js +++ b/src/utils/date-time-format.js @@ -6,7 +6,7 @@ function initLocales() { try { const dtfLocale = new Intl.DateTimeFormat().resolvedOptions().locale; if (!newLocales.includes(dtfLocale)) { - newLocales.push(dtfLocale); + newLocales.unshift(dtfLocale); } } catch {} return newLocales; diff --git a/tests/date-time-format.spec.js b/tests/date-time-format.spec.js index 81989381..fc5ce4f4 100644 --- a/tests/date-time-format.spec.js +++ b/tests/date-time-format.spec.js @@ -95,10 +95,11 @@ test.describe('DateTimeFormat locale combination behavior', () => { expect(navigator.language).toBe('en-GB'); expect(formatted).toBeTruthy(); - // Verify that the DateTimeFormat uses en-GB (British formatting) + // Verify the negotiation: + // Environment default may be prioritized by implementation, otherwise user region should be respected. const resolvedLocale = dtf.resolvedOptions().locale; - // Should resolve to en-GB since the locale combination logic works - expect(resolvedLocale).toBe('en-GB'); + const envDefault = new Intl.DateTimeFormat().resolvedOptions().locale; + expect([envDefault, 'en-GB', 'en']).toContain(resolvedLocale); }); test('should handle different formatting options', () => {