Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/generate/dateFns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, '')]
);
Expand Down
1 change: 1 addition & 0 deletions src/generate/dayjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const localeMap: IlocaleMapObject = {
// el_GR:
en_GB: 'en-gb',
en_US: 'en',
es_US: 'es-us',
Comment thread
coderabbitai[bot] marked this conversation as resolved.
// es_ES:
// et_EE:
// fa_IR:
Expand Down
22 changes: 22 additions & 0 deletions tests/generate.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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');
});
});