fix: handle date being invalid
This commit is contained in:
parent
24b4bf1a74
commit
fb1241c779
@ -8,7 +8,19 @@ export default class SchemaDate extends SchemaItem<Date> {
|
||||
switch (format) {
|
||||
case 'yy-mm-dd':
|
||||
case 'iso8601': {
|
||||
this.addPreProcess((it) => typeof it === 'string' ? new Date(it) : it)
|
||||
this.addPreProcess((it) => {
|
||||
if (typeof it !== 'string') {
|
||||
return it
|
||||
}
|
||||
|
||||
const date = new Date(it)
|
||||
|
||||
if (isNaN(date.getDate())) {
|
||||
return it
|
||||
}
|
||||
|
||||
return date
|
||||
})
|
||||
break
|
||||
}
|
||||
case 'jj/mm/yy': {
|
||||
@ -21,7 +33,12 @@ export default class SchemaDate extends SchemaItem<Date> {
|
||||
return input
|
||||
}
|
||||
|
||||
return new Date(splitted[2], splitted[1] - 1, splitted[0])
|
||||
const date = new Date(splitted[2], splitted[1] - 1, splitted[0])
|
||||
if (isNaN(date.getDate())) {
|
||||
return input
|
||||
}
|
||||
|
||||
return date
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user