diff --git a/src/generate/dayjs.ts b/src/generate/dayjs.ts index 55deb9e2b..d17aa3a42 100644 --- a/src/generate/dayjs.ts +++ b/src/generate/dayjs.ts @@ -162,7 +162,7 @@ const generateConfig: GenerateConfig = { parseNoMatchNotice(); return null; } - const date = dayjs(formatText, format).locale(localeStr); + const date = dayjs(formatText, format, true).locale(localeStr); if (date.isValid()) { return date; } diff --git a/tests/generate.spec.tsx b/tests/generate.spec.tsx index d4f420547..b36732d72 100644 --- a/tests/generate.spec.tsx +++ b/tests/generate.spec.tsx @@ -255,4 +255,13 @@ describe('Generate:dayjs', () => { expect(timea.isValid()).toBeTruthy(); expect(timea.valueOf()).toEqual(timeb.valueOf()); }); + + it('parse', () => { + const timea = dayjsGenerateConfig.locale.parse('en_US', '2022-11-23 13:5' ,['YYYY-MM-DD HH:mm']); + expect(timea).toEqual(null); + + const timeb = dayjsGenerateConfig.locale.parse('en_US', '2022-11-23 13:05' ,['YYYY-MM-DD HH:mm']); + const dateb = dayjsGenerateConfig.locale.format('en_US', timeb, 'YYYY-MM-DD HH:mm'); + expect(dateb).toEqual('2022-11-23 13:05'); + }) });