Files
paypoint-frontend/src/app/models/validators/time-after-start-validator.ts
2025-03-12 23:44:29 +01:00

19 lines
660 B
TypeScript

import {AbstractControl, ValidationErrors, ValidatorFn} from '@angular/forms';
export function timeAfterStartValidator(startTimeField: string): ValidatorFn {
return (control: AbstractControl): ValidationErrors | null => {
const startTime = control.parent?.get(startTimeField)?.value;
const endTime = control.value;
if (!startTime || !endTime) {
return null; // Niet valideren als een van beide leeg is
}
// Omzetten naar Date-objecten voor vergelijking
const start = new Date(`1970-01-01T${startTime}:00`);
const end = new Date(`1970-01-01T${endTime}:00`);
return end > start ? null : {endTimeInvalid: true};
};
}