forked from fahrPool/fahrPool
22 lines
823 B
TypeScript
22 lines
823 B
TypeScript
export type KorrekturValidationResult =
|
|
| { valid: true; gehtUm: string }
|
|
| { valid: false; error: string };
|
|
|
|
export function validateSchichtKorrektur(input: {
|
|
gehtUm: FormDataEntryValue | null;
|
|
kommtUm: string;
|
|
}): KorrekturValidationResult {
|
|
if (typeof input.gehtUm !== "string" || input.gehtUm.trim() === "") {
|
|
return { valid: false, error: "Bitte eine Geht-Uhrzeit angeben." };
|
|
}
|
|
const gehtUmDatum = new Date(input.gehtUm);
|
|
if (Number.isNaN(gehtUmDatum.getTime())) {
|
|
return { valid: false, error: "Ungueltige Geht-Uhrzeit." };
|
|
}
|
|
const kommtUmDatum = new Date(input.kommtUm);
|
|
if (gehtUmDatum.getTime() <= kommtUmDatum.getTime()) {
|
|
return { valid: false, error: "Die Geht-Uhrzeit muss nach der Kommt-Uhrzeit liegen." };
|
|
}
|
|
return { valid: true, gehtUm: gehtUmDatum.toISOString() };
|
|
}
|