@@ -69,9 +69,7 @@ const castToDate = (dateOrStrValue, dateFormat) => {
6969 return DateUtils . parse ( dateOrStrValue , dateFormat ) ;
7070} ;
7171
72- const isDateInRange = ( value , minValue , maxValue , dateFormat ) => {
73- const minDate = castToDate ( minValue , dateFormat ) ;
74- const maxDate = castToDate ( maxValue , dateFormat ) ;
72+ const isDateInRange = ( value , minDate , maxDate , dateFormat ) => {
7573 const format = DateUtils . format ;
7674 if ( value == null ) return null ;
7775 if ( dateFormat == null ) return forgeConfigError ( "Missing option dateFormat, can't perform date validation." ) ;
@@ -97,8 +95,11 @@ const isValid = (dataStr, type, options, canBeEmpty = false) => {
9795 if ( ! options ?. dateFormat ) return forgeConfigError ( "Missing option dateFormat, can't perform date validation." ) ;
9896
9997 const valueAsDate = DateUtils . parse ( dataStr , options ?. dateFormat ) ;
100- if ( isNaN ( valueAsDate . getTime ( ) ) ) return forgeTypeError ( dataStr , type , options ) ;
101- return isDateInRange ( valueAsDate , options ?. minValue , options ?. maxValue , options ?. dateFormat ) ;
98+ if ( isNaN ( valueAsDate . getTime ( ) ) ) return forgeTypeError ( dataStr , type , options ) ; // Invalid date
99+
100+ const minDate = options ?. minDate ?? castToDate ( options ?. minValue , options ?. dateFormat ) ;
101+ const maxDate = options ?. maxDate ?? castToDate ( options ?. maxValue , options ?. dateFormat ) ;
102+ return isDateInRange ( valueAsDate , minDate , maxDate , options ?. dateFormat ) ;
102103 }
103104 case 'enum' :
104105 if ( ! options . enumValues ) return forgeConfigError ( "Missing option enumValues, can't perform enum validation." ) ;
0 commit comments