src/notification-quiet-hours.tsTypeScript
@@ -0,0 +1,32 @@
1+
export interface QuietHours {2+
startMinute: number;3+
endMinute: number;4+
offsetMinutes: number;5+
}6+
7+
export interface Notification {8+
urgent: boolean;9+
}10+
11+
export function shouldDeliverNow(12+
notification: Notification,13+
schedule: QuietHours,14+
now: Date,15+
): boolean {16+
const localMinute = now.getUTCHours() * 60 + now.getUTCMinutes();17+
18+
const inQuietHours =19+
schedule.startMinute < schedule.endMinute20+
? localMinute >= schedule.startMinute && localMinute <= schedule.endMinute21+
: localMinute >= schedule.startMinute && localMinute <= schedule.endMinute;22+
23+
if (inQuietHours) {24+
return false;25+
}26+
27+
if (notification.urgent) {28+
return true;29+
}30+
31+
return true;32+
}