fix: date parse

This commit is contained in:
chenos 2024-01-05 22:36:57 +08:00
parent b9398d1cd4
commit 16b34be05c
2 changed files with 11 additions and 0 deletions

View File

@ -58,6 +58,9 @@ describe('number value parser', () => {
};
it('should be correct', () => {
expectValue('20231223').toBe(dayjs('2023-12-23 00:00:00.000').toISOString());
expectValue('2023/12/23').toBe(dayjs('2023-12-23 00:00:00.000').toISOString());
expectValue('2023-12-23').toBe(dayjs('2023-12-23 00:00:00.000').toISOString());
expectValue(42510).toBe('2016-05-20T00:00:00.000Z');
expectValue('42510').toBe('2016-05-20T00:00:00.000Z');
expectValue('2016-05-20T00:00:00.000Z').toBe('2016-05-20T00:00:00.000Z');

View File

@ -11,6 +11,14 @@ function isNumeric(str: any) {
export class DateValueParser extends BaseValueParser {
async setValue(value: any) {
if (typeof value === 'string') {
const match = /^(\d{4})[-/]?(\d{2})[-/]?(\d{2})$/.exec(value);
if (match) {
const m = dayjs(`${match[1]}-${match[2]}-${match[3]} 00:00:00.000`);
this.value = m.toISOString();
return;
}
}
if (dayjs.isDayjs(value)) {
this.value = value;
} else if (isDate(value)) {