Skip to content

Commit fe24ff0

Browse files
huangkairanhuangkairan
andauthored
fix(generate): dayjs default strict mode (#534)
* fix(generate): `dayjs.parse` default strict mode * test(generate): add `parse` test case Co-authored-by: huangkairan <[email protected]>
1 parent 66b486d commit fe24ff0

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/generate/dayjs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ const generateConfig: GenerateConfig<Dayjs> = {
162162
parseNoMatchNotice();
163163
return null;
164164
}
165-
const date = dayjs(formatText, format).locale(localeStr);
165+
const date = dayjs(formatText, format, true).locale(localeStr);
166166
if (date.isValid()) {
167167
return date;
168168
}

tests/generate.spec.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,4 +255,13 @@ describe('Generate:dayjs', () => {
255255
expect(timea.isValid()).toBeTruthy();
256256
expect(timea.valueOf()).toEqual(timeb.valueOf());
257257
});
258+
259+
it('parse', () => {
260+
const timea = dayjsGenerateConfig.locale.parse('en_US', '2022-11-23 13:5' ,['YYYY-MM-DD HH:mm']);
261+
expect(timea).toEqual(null);
262+
263+
const timeb = dayjsGenerateConfig.locale.parse('en_US', '2022-11-23 13:05' ,['YYYY-MM-DD HH:mm']);
264+
const dateb = dayjsGenerateConfig.locale.format('en_US', timeb, 'YYYY-MM-DD HH:mm');
265+
expect(dateb).toEqual('2022-11-23 13:05');
266+
})
258267
});

0 commit comments

Comments
 (0)