Skip to content

Commit bfcdf46

Browse files
authored
fix: missing week days and months when using dateFns generate config (#115)
1 parent 8c3d943 commit bfcdf46

File tree

2 files changed

+60
-52
lines changed

2 files changed

+60
-52
lines changed

β€Žsrc/generate/dateFns.tsβ€Ž

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ const generateConfig: GenerateConfig<Date> = {
7171
getWeek: (locale, date) => {
7272
return getWeek(date, { locale: Locale[dealLocal(locale)] });
7373
},
74+
getShortWeekDays: locale => {
75+
const clone = Locale[dealLocal(locale)];
76+
return Array.from({ length: 7 }).map((_, i) => clone.localize.day(i, { width: 'short' }));
77+
},
78+
getShortMonths: locale => {
79+
const clone = Locale[dealLocal(locale)];
80+
return Array.from({ length: 12 }).map((_, i) =>
81+
clone.localize.month(i, { width: 'abbreviated' }),
82+
);
83+
},
7484
format: (locale, date, format) => {
7585
if (!isValid(date)) {
7686
return null;

β€Žtests/generate.spec.tsxβ€Ž

Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -144,59 +144,57 @@ describe('Picker.Generate', () => {
144144
).toEqual(null);
145145
});
146146

147-
if (name !== 'date-fns') {
148-
it('getShortWeekDays', () => {
149-
expect(generateConfig.locale.getShortWeekDays!('zh_CN')).toEqual([
150-
'ζ—₯',
151-
'δΈ€',
152-
'二',
153-
'δΈ‰',
154-
'ε››',
155-
'δΊ”',
156-
'ε…­',
157-
]);
158-
expect(generateConfig.locale.getShortWeekDays!('en_US')).toEqual([
159-
'Su',
160-
'Mo',
161-
'Tu',
162-
'We',
163-
'Th',
164-
'Fr',
165-
'Sa',
166-
]);
167-
});
147+
it('getShortWeekDays', () => {
148+
expect(generateConfig.locale.getShortWeekDays!('zh_CN')).toEqual([
149+
'ζ—₯',
150+
'δΈ€',
151+
'二',
152+
'δΈ‰',
153+
'ε››',
154+
'δΊ”',
155+
'ε…­',
156+
]);
157+
expect(generateConfig.locale.getShortWeekDays!('en_US')).toEqual([
158+
'Su',
159+
'Mo',
160+
'Tu',
161+
'We',
162+
'Th',
163+
'Fr',
164+
'Sa',
165+
]);
166+
});
168167

169-
it('getShortMonths', () => {
170-
expect(generateConfig.locale.getShortMonths!('zh_CN')).toEqual([
171-
'1月',
172-
'2月',
173-
'3月',
174-
'4月',
175-
'5月',
176-
'6月',
177-
'7月',
178-
'8月',
179-
'9月',
180-
'10月',
181-
'11月',
182-
'12月',
183-
]);
184-
expect(generateConfig.locale.getShortMonths!('en_US')).toEqual([
185-
'Jan',
186-
'Feb',
187-
'Mar',
188-
'Apr',
189-
'May',
190-
'Jun',
191-
'Jul',
192-
'Aug',
193-
'Sep',
194-
'Oct',
195-
'Nov',
196-
'Dec',
197-
]);
198-
});
199-
}
168+
it('getShortMonths', () => {
169+
expect(generateConfig.locale.getShortMonths!('zh_CN')).toEqual([
170+
'1月',
171+
'2月',
172+
'3月',
173+
'4月',
174+
'5月',
175+
'6月',
176+
'7月',
177+
'8月',
178+
'9月',
179+
'10月',
180+
'11月',
181+
'12月',
182+
]);
183+
expect(generateConfig.locale.getShortMonths!('en_US')).toEqual([
184+
'Jan',
185+
'Feb',
186+
'Mar',
187+
'Apr',
188+
'May',
189+
'Jun',
190+
'Jul',
191+
'Aug',
192+
'Sep',
193+
'Oct',
194+
'Nov',
195+
'Dec',
196+
]);
197+
});
200198

201199
it('getWeek', () => {
202200
const formatStr = name === 'date-fns' ? 'yyyy-MM-dd' : 'YYYY-MM-DD';

0 commit comments

Comments
Β (0)