fix: handle date being invalid

This commit is contained in:
Florian Bouillon 2025-04-02 13:43:56 +02:00
parent 24b4bf1a74
commit fb1241c779
Signed by: Florian Bouillon
GPG Key ID: 7676FF78F3BC40EC

View File

@ -8,7 +8,19 @@ export default class SchemaDate extends SchemaItem<Date> {
switch (format) { switch (format) {
case 'yy-mm-dd': case 'yy-mm-dd':
case 'iso8601': { 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 break
} }
case 'jj/mm/yy': { case 'jj/mm/yy': {
@ -21,7 +33,12 @@ export default class SchemaDate extends SchemaItem<Date> {
return input 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
}) })
} }
} }