Skip to content

Commit 1f725d0

Browse files
Noel Kim (김민혁)Noel Kim (김민혁)
andauthored
fix(locale): dateFns generator for korean (#603)
* fix(locale): dateFns generator for korean * feat: add tests * fix: locale --------- Co-authored-by: Noel Kim (김민혁) <[email protected]>
1 parent 5db4fbe commit 1f725d0

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/generate/dateFns.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ import {
2727
import * as Locale from 'date-fns/locale';
2828
import type { GenerateConfig } from '.';
2929

30+
const localeMap: Record<string, string> = {
31+
ko_KR: 'ko'
32+
};
33+
3034
const dealLocal = (str: string) => {
31-
return str.replace(/_/g, '');
35+
return localeMap[str] || str.replace(/_/g, '');
3236
};
3337

3438
const localeParse = (format: string) => {

tests/generate.spec.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import momentGenerateConfig from '../src/generate/moment';
66
import { getMoment } from './util/commonUtil';
77

88
import 'dayjs/locale/zh-cn';
9+
import 'dayjs/locale/ko';
910
import type { GenerateConfig } from '../src/generate';
1011

1112
describe('Picker.Generate', () => {
@@ -91,6 +92,13 @@ describe('Picker.Generate', () => {
9192
'2000-01-02',
9293
);
9394
});
95+
['2000-01-02', '02/01/2000'].forEach((str) => {
96+
const date = generateConfig.locale.parse('ko_KR', str, ['YYYY-MM-DD', 'DD/MM/YYYY']);
97+
98+
expect(generateConfig.locale.format('ko_KR', date!, 'YYYY-MM-DD')).toEqual(
99+
'2000-01-02',
100+
);
101+
});
94102
});
95103

96104
it('week', () => {
@@ -188,6 +196,15 @@ describe('Picker.Generate', () => {
188196
});
189197

190198
it('getShortWeekDays', () => {
199+
expect(generateConfig.locale.getShortWeekDays!('ko_KR')).toEqual([
200+
'일',
201+
'월',
202+
'화',
203+
'수',
204+
'목',
205+
'금',
206+
'토',
207+
]);
191208
expect(generateConfig.locale.getShortWeekDays!('zh_CN')).toEqual([
192209
'日',
193210
'一',

0 commit comments

Comments
 (0)