shoc-frontend-new/src/domain/work-orders/utils/due-date-floor.ts
2026-09-16 13:32:44 -03:00

27 lines
955 B
TypeScript

/**
* SH-356: a Due Date can never be earlier than Schedule On.
*
* The floor is the concrete Schedule On day, the start of a date range, or — for a
* week-only schedule (SH-110) — the first day of the target week.
*/
export function resolveDueDateFloor(schedule: {
scheduledOn?: string | null;
targetWeek?: string | null;
}): string {
return schedule.scheduledOn?.trim() || schedule.targetWeek?.trim() || "";
}
export function isDueDateBeforeFloor(dueDate: string | null | undefined, floor: string): boolean {
return Boolean(dueDate && floor && dueDate < floor);
}
/**
* Patch fragment for a Schedule On change: clears an existing Due Date that the new
* schedule would leave in the past. Never bumps it to a guessed value.
*/
export function clearDueDateBeforeSchedule(
dueDate: string | null | undefined,
nextFloor: string,
): { dueDate?: string } {
return isDueDateBeforeFloor(dueDate, nextFloor) ? { dueDate: "" } : {};
}