@ -11,24 +11,35 @@ export const pageSizeOptions = [
] ;
export const toDateAfterFromDateValidator : ValidatorFn = (
group : AbstractControl
control : AbstractControl
) : ValidationErrors | null = > {
const fromDate = group . get ( 'fromDate' ) ? . value ;
const toDate = group . get ( 'toDate' ) ? . value ;
const currentDate = new Date ( ) . toISOString ( ) ;
const from = control . get ( 'fromDate' ) ? . value ;
const to = control . get ( 'toDate' ) ? . value ;
if ( ! fromDate || ! toDate ) {
return null ;
if ( ! from || ! to ) return null ;
// Normalize to midnight to avoid timezone bugs
const fromDate = new Date ( from ) ;
const toDate = new Date ( to ) ;
fromDate . setHours ( 0 , 0 , 0 , 0 ) ;
toDate . setHours ( 0 , 0 , 0 , 0 ) ;
const today = new Date ( ) ;
today . setHours ( 0 , 0 , 0 , 0 ) ;
// Rule 1: fromDate must be < toDate
if ( fromDate >= toDate ) {
return { fromDateGreaterThanOrEqualToToDate : true } ;
}
if ( toDate < fromDate )
return { toDateInvalid : true }
else if ( toDate >= currentDate )
return { toDateGreaterThanToday : true }
else
return null
// Rule 2: no future dates
if ( fromDate > today || toDate > today ) {
return { futureDateNotAllowed : true } ;
}
return null ;
} ;
export const EXCEL_FILE_TYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8' ;