fix: date parse
This commit is contained in:
parent
b9398d1cd4
commit
16b34be05c
@ -58,6 +58,9 @@ describe('number value parser', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
it('should be correct', () => {
|
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('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');
|
expectValue('2016-05-20T00:00:00.000Z').toBe('2016-05-20T00:00:00.000Z');
|
||||||
|
@ -11,6 +11,14 @@ function isNumeric(str: any) {
|
|||||||
|
|
||||||
export class DateValueParser extends BaseValueParser {
|
export class DateValueParser extends BaseValueParser {
|
||||||
async setValue(value: any) {
|
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)) {
|
if (dayjs.isDayjs(value)) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
} else if (isDate(value)) {
|
} else if (isDate(value)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user