Skip to content

Commit

Permalink
fix(generate): dayjs default strict mode (#534)
Browse files Browse the repository at this point in the history
* fix(generate): `dayjs.parse` default strict mode

* test(generate): add `parse` test case

Co-authored-by: huangkairan <wb-hkr877030@alibaba-inc.com>
  • Loading branch information
huangkairan and huangkairan authored Nov 23, 2022
1 parent 66b486d commit fe24ff0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/generate/dayjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ const generateConfig: GenerateConfig<Dayjs> = {
parseNoMatchNotice();
return null;
}
const date = dayjs(formatText, format).locale(localeStr);
const date = dayjs(formatText, format, true).locale(localeStr);
if (date.isValid()) {
return date;
}
Expand Down
9 changes: 9 additions & 0 deletions tests/generate.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
})
});

0 comments on commit fe24ff0

Please sign in to comment.