Skip to content

Commit 9c2b7b7

Browse files
elmehdimrhejscribner
authored andcommitted
fix(DateType.cast): preserve null/undefined values instead of casting to unix timestamp
1 parent e4a91a4 commit 9c2b7b7

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/schema/types/date-type.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,15 @@ export class DateType extends CoreType {
6767
}
6868

6969
cast(value: any, strategy = CAST_STRATEGY.DEFAULT_OR_DROP) {
70+
if(value === null || value === undefined) {
71+
return value;
72+
}
73+
7074
if (isDateValid(value)) {
7175
return new Date(value);
72-
} else {
73-
return checkCastStrategy(value, strategy, this);
74-
}
76+
}
77+
78+
return checkCastStrategy(value, strategy, this);
7579
}
7680

7781
validate(value: unknown, strategy) {

0 commit comments

Comments
 (0)