(
now: Date,
{ startHour, endHour }: PatchyHourWindow,
)
| 10 | // whose start is after its end wraps past midnight (23 to 3), so its early |
| 11 | // hours belong to the previous day. |
| 12 | const getWindowStartDay = ( |
| 13 | now: Date, |
| 14 | { startHour, endHour }: PatchyHourWindow, |
| 15 | ): Date | null => { |
| 16 | const hour = now.getHours(); |
| 17 | if (startHour < endHour) { |
| 18 | return hour >= startHour && hour < endHour ? now : null; |
| 19 | } |
| 20 | if (hour >= startHour) { |
| 21 | return now; |
| 22 | } |
| 23 | if (hour < endHour) { |
| 24 | const previousDay = new Date(now); |
| 25 | previousDay.setDate(now.getDate() - 1); |
| 26 | return previousDay; |
| 27 | } |
| 28 | return null; |
| 29 | }; |
| 30 | |
| 31 | export const isLateNight = (now: Date, window: PatchyHourWindow): boolean => |
| 32 | getWindowStartDay(now, window) !== null; |
no outgoing calls
no test coverage detected