fix: Non lanciare un errore quando si prova a convertire una data quando non è valida

Ad esempio quando è `undefined`
This commit is contained in:
Maicol Battistini 2023-07-14 11:10:05 +02:00
parent 3c811c4c62
commit 4464214904
No known key found for this signature in database
1 changed files with 9 additions and 0 deletions

View File

@ -70,6 +70,15 @@ export default abstract class Model<A extends ModelAttributes, R extends ModelRe
return super.getAttributes() as ModelAttributes;
}
protected getAttributeAsDate(attributeName: string) {
// @ts-ignore
let attribute: string | Date = (this.attributes as Map<string, string | null>).get(attributeName);
if (attribute && dayjs(attribute).isValid()) {
attribute = super.getAttributeAsDate(attributeName) as Date;
}
return attribute;
}
setAttribute<AN extends keyof A = keyof A>(attributeName: AN, value: ValueOf<A, AN>) {
const date = dayjs(value as string | Date | undefined);
// @ts-expect-error