Skip to content

Commit

Permalink
fix(locale): dateFns generator for korean (#603)
Browse files Browse the repository at this point in the history
* fix(locale): dateFns generator for korean

* feat: add tests

* fix: locale

---------

Co-authored-by: Noel Kim (김민혁) <noel@quotabook.com>
  • Loading branch information
Noel Kim (김민혁) and Noel Kim (김민혁) committed Feb 19, 2024
1 parent 5db4fbe commit 1f725d0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/generate/dateFns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ import {
import * as Locale from 'date-fns/locale';
import type { GenerateConfig } from '.';

const localeMap: Record<string, string> = {
ko_KR: 'ko'
};

const dealLocal = (str: string) => {
return str.replace(/_/g, '');
return localeMap[str] || str.replace(/_/g, '');
};

const localeParse = (format: string) => {
Expand Down
17 changes: 17 additions & 0 deletions tests/generate.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import momentGenerateConfig from '../src/generate/moment';
import { getMoment } from './util/commonUtil';

import 'dayjs/locale/zh-cn';
import 'dayjs/locale/ko';
import type { GenerateConfig } from '../src/generate';

describe('Picker.Generate', () => {
Expand Down Expand Up @@ -91,6 +92,13 @@ describe('Picker.Generate', () => {
'2000-01-02',
);
});
['2000-01-02', '02/01/2000'].forEach((str) => {
const date = generateConfig.locale.parse('ko_KR', str, ['YYYY-MM-DD', 'DD/MM/YYYY']);

expect(generateConfig.locale.format('ko_KR', date!, 'YYYY-MM-DD')).toEqual(
'2000-01-02',
);
});
});

it('week', () => {
Expand Down Expand Up @@ -188,6 +196,15 @@ describe('Picker.Generate', () => {
});

it('getShortWeekDays', () => {
expect(generateConfig.locale.getShortWeekDays!('ko_KR')).toEqual([
'일',
'월',
'화',
'수',
'목',
'금',
'토',
]);
expect(generateConfig.locale.getShortWeekDays!('zh_CN')).toEqual([
'日',
'一',
Expand Down

0 comments on commit 1f725d0

Please sign in to comment.