export type ShiftKey = 'manha' | 'tarde' | 'noite'; export const SHIFTS: Record = { manha: { startHour: 6, endHour: 14 }, tarde: { startHour: 14, endHour: 22 }, noite: { startHour: 22, endHour: 6 }, }; /** Given a shift and a day (Date at local midnight), returns [from, to). */ export function shiftWindow(shift: ShiftKey, day: Date): { from: Date; to: Date } { const s = SHIFTS[shift]; const from = new Date(day); from.setHours(s.startHour, 0, 0, 0); const to = new Date(day); if (s.endHour <= s.startHour) to.setDate(to.getDate() + 1); // noite crosses midnight to.setHours(s.endHour, 0, 0, 0); return { from, to }; } /** "Hoje" = start of local day up to now. `now` injected for testability. */ export function todayWindow(now: Date): { from: Date; to: Date } { const from = new Date(now); from.setHours(0, 0, 0, 0); return { from, to: now }; }