From 9f3d0cda54c902bf6e9d6749649fc565b5d73f6e Mon Sep 17 00:00:00 2001 From: PerryLink <255665900+PerryLink@users.noreply.github.com> Date: Tue, 20 Oct 2026 11:25:59 +0000 Subject: [PATCH] feat: map es_US in the dayjs and date-fns adapters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `es_US` picker locale means Spanish for the US: Spanish month and weekday names with Sunday as the first day of the week. Day.js has an `es-us` locale, but `localeMap` had no `es_US` entry, so `parseLocale('es_US')` fell back to `es` — Spanish, but Monday first. The picker's `lang.locale` stays in the underscore form because it is shared with the other adapters, so the mapping belongs here. The date-fns adapter had the same gap the other way round: it resolved `es_US` to `es`, which also starts the week on Monday, and date-fns ships no es-US locale. `es_US` now returns the Spanish locale with `weekStartsOn: 0`. Adds a test per adapter: Spanish month and weekday names, Sunday first. --- src/generate/dateFns.ts | 12 ++++++++++++ src/generate/dayjs.ts | 1 + tests/generate.spec.tsx | 22 ++++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/src/generate/dateFns.ts b/src/generate/dateFns.ts index c1c97d91c..6076f4160 100644 --- a/src/generate/dateFns.ts +++ b/src/generate/dateFns.ts @@ -31,7 +31,19 @@ import { import * as locales from 'date-fns/locale'; import type { GenerateConfig } from '.'; +// date-fns has no es-US locale and its `es` locale starts the week on Monday. +// The `es_US` picker locale means Spanish with the US week start, so keep the +// Spanish formatting and override the first day of the week. +const esUS: Locale = { + ...locales.es, + options: { ...locales.es.options, weekStartsOn: 0 }, +}; + const getLocale = (locale: string): Locale => { + if (locale === 'es_US') { + return esUS; + } + return ( locales[locale] || locales[locale.replace(/_/g, '')] || locales[locale.replace(/_.*$/g, '')] ); diff --git a/src/generate/dayjs.ts b/src/generate/dayjs.ts index a4fa37804..1fa2f8536 100644 --- a/src/generate/dayjs.ts +++ b/src/generate/dayjs.ts @@ -39,6 +39,7 @@ const localeMap: IlocaleMapObject = { // el_GR: en_GB: 'en-gb', en_US: 'en', + es_US: 'es-us', // es_ES: // et_EE: // fa_IR: diff --git a/tests/generate.spec.tsx b/tests/generate.spec.tsx index f0a7aed60..c555e7b15 100644 --- a/tests/generate.spec.tsx +++ b/tests/generate.spec.tsx @@ -9,6 +9,7 @@ import { getMoment } from './util/commonUtil'; import 'dayjs/locale/zh-cn'; import 'dayjs/locale/ko'; import 'dayjs/locale/fr'; +import 'dayjs/locale/es-us'; import type { GenerateConfig } from '../src/generate'; describe('Picker.Generate', () => { @@ -415,3 +416,24 @@ describe('Generate:date-fns', () => { expect(dateFnsGenerateConfig.getMinute(parsed)).toEqual(30); }); }); + + +describe('Generate: es_US', () => { + it('dayjs keeps the US week start and formats in Spanish', () => { + expect(dayjsGenerateConfig.locale.getWeekFirstDay('es_US')).toEqual(0); + + const date = dayjsGenerateConfig.locale.parse('es_US', '2018-01-15', ['YYYY-MM-DD'])!; + + expect(dayjsGenerateConfig.locale.format('es_US', date, 'MMMM')).toEqual('enero'); + expect(dayjsGenerateConfig.locale.format('es_US', date, 'dddd')).toEqual('lunes'); + }); + + it('date-fns keeps the US week start and formats in Spanish', () => { + expect(dateFnsGenerateConfig.locale.getWeekFirstDay('es_US')).toEqual(0); + + const date = new Date(2018, 0, 15); + + expect(dateFnsGenerateConfig.locale.format('es_US', date, 'MMMM')).toEqual('enero'); + expect(dateFnsGenerateConfig.locale.format('es_US', date, 'EEEE')).toEqual('lunes'); + }); +});