fix: Non lanciare un errore quando si prova a convertire una data quando non è valida
Ad esempio quando è `undefined`
This commit is contained in:
parent
3c811c4c62
commit
4464214904
|
@ -70,6 +70,15 @@ export default abstract class Model<A extends ModelAttributes, R extends ModelRe
|
||||||
return super.getAttributes() as ModelAttributes;
|
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>) {
|
setAttribute<AN extends keyof A = keyof A>(attributeName: AN, value: ValueOf<A, AN>) {
|
||||||
const date = dayjs(value as string | Date | undefined);
|
const date = dayjs(value as string | Date | undefined);
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
|
|
Loading…
Reference in New Issue